import java.util.Scanner;

public class Solution {

	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String s = in.nextLine();

		char[][] chars = new char[n][];

		for(int i = 0; i < n; i++)
			chars[i] = in.nextLine().toCharArray();
        boolean x = isX(chars);

        if(x)
        	System.out.println("YES");
        else
        	System.out.println("NO");
	}

	public static boolean isX(char[][] chars)
	{
		int i, j, k;
		char key1 = chars[0][0];
		for(i = 0, j = chars.length - 1; i < chars.length; i++, j--)
		{
			if(chars[i][i] != key1 || chars[i][j] != key1)
				return false;
		}

		char key2 = chars[0][1];
		if(key1 == key2)
			return false;
		for(i = 0, k = chars.length - 1; i < chars.length; i++, k--)
			for(j = 0; j < chars.length; j++)
			{
				if(i - j == 0 || k - j == 0)
					continue;
				else if(chars[i][j] != key2 || chars[i][j] == key1)
					return false;
			}
		return true;
	}

}


import java.util.Scanner;

public class Solution {

	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String s = in.nextLine();

		char[][] chars = new char[n][];

		for(int i = 0; i < n; i++)
			chars[i] = in.nextLine().toCharArray();
        boolean x = isX(chars);

        if(x)
        	System.out.println("YES");
        else
        	System.out.println("NO");
	}

	public static boolean isX(char[][] chars)
	{
		int i, j;
		char key1 = chars[0][0];
		for(i = 0, j = chars.length - 1; i < chars.length; i++, j--)
		{
			if(chars[i][i] != key1 || chars[i][j] != key1)
				return false;
		}

		char key2 = chars[0][1];
		if(key1 == key2)
			return false;
		for(i = 0; i < chars.length; i++)
			for(j = 0; j < chars.length; j++)
				if(chars[i][j] != key1)
					if(chars[i][j] != key2)
						return false;
		return true;
	}

}


import java.util.Scanner;

public class Solution {

	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String s = in.nextLine();

		char[][] chars = new char[n][];

		for(int i = 0; i < n; i++)
			chars[i] = in.nextLine().toCharArray();
		for(int i = 0; i < n; i++)
			System.out.println(chars[i]);
        in.close();

        boolean x = isX(chars);

        if(x)
        	System.out.println("YES");
        else
        	System.out.println("NO");
	}

	public static boolean isX(char[][] chars)
	{
		int i, j;
		char key1 = chars[0][0];
		for(i = 0, j = chars.length - 1; i < chars.length; i++, j--)
		{
			if(chars[i][i] != key1 || chars[i][j] != key1)
				return false;
		}

		char key2 = chars[0][1];

		for(i = 0; i < chars.length; i++)
			for(j = 0; j < chars.length; j++)
				if(chars[i][j] != key1)
					if(chars[i][j] != key2)
						return false;
		return true;
	}

}


import java.util.Scanner;

public class Solution {

	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String s = in.nextLine();

		char[][] chars = new char[n][];

		for(int i = 0; i < n; i++)
			chars[i] = in.nextLine().toCharArray();
        boolean x = isX(chars);

        if(x)
        	System.out.println("YES");
        else
        	System.out.println("NO");
	}

	public static boolean isX(char[][] chars)
	{
		int i, j;
		char key1 = chars[0][0];
		for(i = 0, j = chars.length - 1; i < chars.length; i++, j--)
		{
			if(chars[i][i] != key1 || chars[i][j] != key1)
				return false;
		}

		char key2 = chars[0][1];
		if(key1 == key2)
			return false;
		for(i = 0; i < chars.length; i++)
			for(j = 0; j < chars.length; j++)
			{
				if(chars[i][j] == key1)
					continue;
				else if(chars[i][j] != key2 || chars[i][j] == key1)
					return false;
			}
		return true;
	}

}


import java.util.Scanner;

public class Solution {

	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String s = in.nextLine();

		char[][] chars = new char[n][];

		for(int i = 0; i < n; i++)
			chars[i] = in.nextLine().toCharArray();
        boolean x = isX(chars);

        if(x)
        	System.out.println("YES");
        else
        	System.out.println("NO");
	}

	public static boolean isX(char[][] chars)
	{
		int i, j;
		char key1 = chars[0][0];
		for(i = 0, j = chars.length - 1; i < chars.length; i++, j--)
		{
			if(chars[i][i] != key1 || chars[i][j] != key1)
				return false;
		}

		char key2 = chars[0][1];
		if(key1 == key2)
			return false;
		for(i = 0; i < chars.length; i++)
			for(j = 0; j < chars.length; j++)
			{
				if(chars[i][j] == key1)
					continue;
				else if(chars[i][j] != key2)
					return false;
			}
		return true;
	}

}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class a {
  public static void main(String args[]) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] s = new String[n];
    for (int i = 0; i < n; ++i)
      s[i] = in.readLine();
    if (s[0].charAt(0) == s[0].charAt(1)) {
      System.out.println("NO");
    } else for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (j == i || j == n - 1 - i) {
          if (s[i].charAt(j) != s[0].charAt(0)) {
            System.out.println("NO");
            return;
          }
        } else {
          if (s[i].charAt(j) != s[0].charAt(1)) {
            System.out.println("NO");
            return;
          }
        }
      }
    }
    System.out.println("YES");
  }
}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class a {
  public static void main(String args[]) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    char[][] s = new char[n][n];
    for (int i = 0; i < n; ++i)
      s[i] = in.readLine().toCharArray();
    if (s[0][0] == s[0][1]) {
      System.out.println("NO");
      return;
    } else for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (j == i || j == n - 1 - i) {
          if (s[i][j] != s[0][0]) {
            System.out.println("NO");
            return;
          }
        } else {
          if (s[i][j] != s[0][1]) {
            System.out.println("NO");
            return;
          }
        }
      }
    }
    System.out.println("YES");
  }
}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class a {
  public static void main(String args[]) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] s = new String[n];
    for (int i = 0; i < n; ++i)
      s[i] = in.readLine();
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (j == i || j == n - 1 - i) {
          if (s[i].charAt(j) != s[0].charAt(0)) {
            System.out.println("NO");
            return;
          }
        } else {
          if (s[i].charAt(j) != s[0].charAt(1)) {
            System.out.println("NO");
            return;
          }
        }
      }
    }
    System.out.println("YES");
  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class a {
  public static void main(String args[]) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    int n = Integer.parseInt(in.readLine());
  }
}


import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class a {
  public static void main(String args[]) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] s = new String[n];
    for (int i = 0; i < n; ++i)
      s[i] = in.readLine();
    if (s[0].charAt(0) == s[0].charAt(1)) {
      System.out.println("NO");
      return;
    } else for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (j == i || j == n - 1 - i) {
          if (s[i].charAt(j) != s[0].charAt(0)) {
            System.out.println("NO");
            return;
          }
        } else {
          if (s[i].charAt(j) != s[0].charAt(1)) {
            System.out.println("NO");
            return;
          }
        }
      }
    }
    System.out.println("YES");
  }
}


// CF677-D2-A

import java.util.Scanner;

public class VanyaAndFence {

	static Scanner userinput = new Scanner(System.in);

	public static void main(String[] args) {
		String[] input_1 = userinput.nextLine().split(" ");
		String[] input_2 = userinput.nextLine().split(" ");

		int n = Integer.parseInt(input_1[0]);
		int m = Integer.parseInt(input_1[1]);
		int totalWidth = 0;

		for(int i=0;i<n;i++) {
			int userHeight = Integer.parseInt(input_2[i]);
			if( userHeight > m ) {
				totalWidth++;
			}
			totalWidth++;
		}

		System.out.println(totalWidth);

	}

}


import java.util.Scanner;

public class ValeraAndX {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		char main = 0, second = 0;
		boolean isTrue=true;
		for(int i=0;i<n;i++) {
			String l = input.next();
			if(i==0) {
				main=l.charAt(0);
				second = l.charAt(1);
				if(main == second) {
					System.out.println("NO");
					return;
				}
			}

			for(int j=0;j<l.length();j++) {
				if(j==i || l.length()-1-j == i) {
					if(l.charAt(l.length()-1-j) == main && l.charAt(0+j) == main) {
						isTrue=true;
					} else {
						isTrue=false;
						System.out.println("NO");
						return;
					}
				} else {
					if(l.charAt(j) == second) {
						isTrue=true;
					} else {
						System.out.println("NO");
						isTrue=false;
						return;
					}
				}
			}

		}

		if(isTrue==true) {
			System.out.println("YES");
		}

	}

}


import java.util.Scanner;

public class ValeraAndX {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		char main = 0, second = 0;
		boolean isTrue=true;
		for(int i=0;i<n;i++) {
			String l = input.next();
			if(i==0) {
				main=l.charAt(0);
				second = l.charAt(1);
				if(main == second) {
					System.out.println("NO");
					return;
				}
			}

			for(int j=0;j<l.length()-1;j++) {
				if(j==i || l.length()-1-j == i) {
					if(l.charAt(l.length()-1-j) == main && l.charAt(0+j) == main) {
						isTrue=true;
					} else {
						isTrue=false;
						System.out.println("NO");
						return;
					}
				} else {
					if(l.charAt(j) == second) {
						isTrue=true;
					} else {
						System.out.println("NO");
						isTrue=false;
						return;
					}
				}
			}

		}

		if(isTrue==true) {
			System.out.println("YES");
		}

	}

}


import java.util.Scanner;

public class ValeraAndX {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		char main = 0, second = 0;
		boolean isTrue=true;
		for(int i=0;i<n;i++) {
			String l = input.next();
			if(i==0) {
				main=l.charAt(0);
				second = l.charAt(1);
			}

			for(int j=0;j<l.length()-1;j++) {
				if(j==i || l.length()-1-j == i) {
					if(l.charAt(l.length()-1-j) == main && l.charAt(0+j) == main) {
						isTrue=true;
					} else {
						isTrue=false;
						System.out.println("NO");
						return;
					}
				} else {
					if(l.charAt(j) == second) {
						isTrue=true;
					} else {
						System.out.println("NO");
						isTrue=false;
						return;
					}
				}
			}

		}

		if(isTrue==true) {
			System.out.println("YES");
		}

	}

}


import java.util.Scanner;

public class Valera_and_X {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String[] str = new String[n];
		scan.nextLine();
		for (int i = 0; i < n; i++) {
			str[i] = scan.nextLine();
		}
		char c = str[0].charAt(0);
		for (int i = 0; i < n; i++) {
			if (str[i].charAt(i) != str[i].charAt(n - 1 - i) || str[i].charAt(i)!= c ) {
				System.out.print("NO");
				System.exit(0);
			}
		}
		char cc = str[0].charAt(1);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i != j && i != n - 1 - j) {
					if (str[i].charAt(j) != cc || str[i].charAt(j) == str[0].charAt(0)) {
						System.out.print("NO");
						System.exit(0);
					}
				}
			}
		}
		System.out.print("YES");
		scan.close();
	}

}


import java.util.Scanner;

public class Valera_and_X {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String[] str = new String[n];
		scan.nextLine();
		for (int i = 0; i < n; i++) {
			str[i] = scan.nextLine();
		}
		// char c = str[0].charAt(0);
		for (int i = 0; i < n; i++) {
			if (str[i].charAt(i) != str[i].charAt(n - 1 - i)) {
				System.out.print("No");
				System.exit(0);
			}
		}
		char cc = str[0].charAt(1);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i != j && i != n - 1 - j) {
					if (str[i].charAt(j) != cc) {
						System.out.print("No");
						System.exit(0);
					}
				}
			}
		}
		System.out.print("Yes");
		scan.close();
	}

}


import java.util.Scanner;

public class Valera_and_X {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String[] str = new String[n];
		scan.nextLine();
		for (int i = 0; i < n; i++) {
			str[i] = scan.nextLine();
		}
		// char c = str[0].charAt(0);
		for (int i = 0; i < n; i++) {
			if (str[i].charAt(i) != str[i].charAt(n - 1 - i)) {
				System.out.print("NO");
				System.exit(0);
			}
		}
		char cc = str[0].charAt(1);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i != j && i != n - 1 - j) {
					if (str[i].charAt(j) != cc) {
						System.out.print("NO");
						System.exit(0);
					}
				}
			}
		}
		System.out.print("YES");
		scan.close();
	}

}


import java.util.Scanner;

public class Valera_and_X {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String[] str = new String[n];
		scan.nextLine();
		for (int i = 0; i < n; i++) {
			str[i] = scan.nextLine();
		}
		// char c = str[0].charAt(0);
		for (int i = 0; i < n; i++) {
			if (str[i].charAt(i) != str[i].charAt(n - 1 - i)) {
				System.out.print("NO");
				System.exit(0);
			}
		}
		char cc = str[0].charAt(1);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i != j && i != n - 1 - j) {
					if (str[i].charAt(j) != cc || str[i].charAt(j) == str[0].charAt(0)) {
						System.out.print("NO");
						System.exit(0);
					}
				}
			}
		}
		System.out.print("YES");
		scan.close();
	}

}


import java.util.Scanner;

/**
 *
 * @author user
 */
public class NewMain11 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner s = new Scanner(System.in);

        int a = s.nextInt();

        String g[] = new String[a];
        String h = "";
        for (int i = 0; i < a; i++) {
            g[i] = s.next();
            h += g[i];
        }

        char q = ' ';
        char q1 = g[0].charAt(1);
        int c = 0;
        int d = a - 1;

        boolean found = false;
        for (int i = 0; i < (a / 2); i++) {
            if (g[i].charAt(c) == q && g[i].charAt(d) == q && g[(a - 1) - i].charAt(c) == q && g[(a - 1) - i].charAt(d) == q) {
                if (i == 0) {
                    q = g[i].charAt(c);
                }
                c++;
                d--;
            } else {
                found = true;
                q = ' ';
                break;
            }
        }
        int v = h.replaceAll("[" + q + q1 + "]", "").length();

        int v1 = h.replaceAll("[" + q1 + "]", "").length();
        int v2 = h.replaceAll("[" + q + "]", "").length();

        if (g[a / 2].charAt(a / 2) == q && !found && v == 0 && q1 != q
                && v1 == ((a * 2) - 1) && v2 == ((a * a) - ((a * 2) - 1))) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }

}


import java.util.Scanner;

public class NewMain11 {

    public static void main(String[] args) {
        // TODO code application logic here
        Scanner s = new Scanner(System.in);

        int a = s.nextInt();

        String g[] = new String[a];
        String h = "";
        for (int i = 0; i < a; i++) {
            g[i] = s.next();
            h += g[i];
        }

        char q = ' ';
        char q1 = g[0].charAt(1);
        int c = 0;
        int d = a - 1;

        boolean found = false;
        for (int i = 0; i < (a / 2); i++) {
            if (g[i].charAt(c) == g[i].charAt(d)) {
                q = g[i].charAt(c);
                c++;
                d--;
            } else {
                found = true;
                q = ' ';
                break;
            }
        }
        int v = h.replaceAll("[" + q + q1 + "]", "").length();
        if (g[a / 2].charAt(a / 2) == q && !found && v == 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

}


import java.util.Scanner;

/**
 *
 * @author user
 */
public class NewMain11 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner s = new Scanner(System.in);

        int a = s.nextInt();

        String g[] = new String[a];
        String h = "";
        for (int i = 0; i < a; i++) {
            g[i] = s.next();
            h += g[i];
        }

        char q = ' ';
        char q1 = g[0].charAt(1);
        int c = 0;
        int d = a - 1;

        boolean found = false;
        for (int i = 0; i < (a / 2); i++) {
            if (g[i].charAt(c) == g[i].charAt(d)) {
                q = g[i].charAt(c);
                c++;
                d--;
            } else {
                found = true;
                q = ' ';
                break;
            }
        }
        int v = h.replaceAll("[" + q + q1 + "]", "").length();

        int v1 = h.replaceAll("[" + q1 + "]", "").length();
        int v2 = h.replaceAll("[" + q + "]", "").length();

        if (g[a / 2].charAt(a / 2) == q && !found && v == 0 && q1 != q
                && v1 == ((a * 2) - 1) && v2 == ((a * a) - ((a * 2) - 1))) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }

}


import java.util.Scanner;

public class NewMain11 {

    public static void main(String[] args) {
        // TODO code application logic here
        Scanner s = new Scanner(System.in);

        int a = s.nextInt();

        String g[] = new String[a];
        String h = "";
        for (int i = 0; i < a; i++) {
            g[i] = s.next();
            h += g[i];
        }

        char q = ' ';
        char q1 = g[0].charAt(1);
        int c = 0;
        int d = a - 1;

        boolean found = false;
        for (int i = 0; i < (a / 2); i++) {
            if (g[i].charAt(c) == g[i].charAt(d)) {
                q = g[i].charAt(c);
                c++;
                d--;
            } else {
                found = true;
                q = ' ';
                break;
            }
        }
        int v = h.replaceAll("[" + q + q1 + "]", "").length();
        if (g[a / 2].charAt(a / 2) == q && !found && v == 0 && q1 != q) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

}


import java.util.Scanner;

/**
 *
 * @author user
 */
public class NewMain11 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner s = new Scanner(System.in);

        int n = s.nextInt();

        String g[] = new String[n];
        String h = "";
        for (int i = 0; i < n; i++) {
            g[i] = s.next();
            h += g[i] + "\n";
        }
        String h1 = h;

        int a = 0;
        int b = n - 1;

        String y = "", y1 = "";

        for (int i = 0; i < n / 2; i++) {
            y += g[i].charAt(a) + "" + g[i].charAt(b);
            String q = g[i].replaceFirst(String.valueOf(g[i].charAt(a)), "");
            y1 += q.replaceFirst(String.valueOf(g[i].charAt(b)), "");

            if (i == ((n / 2) - 1)) {
                y += g[n / 2].charAt(n / 2);
                y1 += g[n / 2].replaceFirst(String.valueOf(g[n / 2].charAt(n / 2)), "");
            }
            y += g[(n - 1) - i].charAt(a) + "" + g[(n - 1) - i].charAt(b);

            String q1 = g[(n - 1) - i].replaceFirst(String.valueOf(g[(n - 1) - i].charAt(a)), "");
            y1 += q1.replaceFirst(String.valueOf(g[(n - 1) - i].charAt(b)), "");

            a++;
            b--;
        }
        int t1 = y.replaceAll(String.valueOf(y.charAt(0)), "").length();
        int t2 = y1.replaceAll(String.valueOf(y1.charAt(0)), "").length();

        if (t1 == 0 && t2 == 0 && y.charAt(0) != y1.charAt(0)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }

}


import java.util.Scanner;

/**
 *
 * @author user
 */
public class NewMain11 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner s = new Scanner(System.in);

        int a = s.nextInt();

        String g[] = new String[a];
        String h = "";
        for (int i = 0; i < a; i++) {
            g[i] = s.next();
            h += g[i];
        }

        char q = ' ';
        char q1 = g[0].charAt(1);
        int c = 0;
        int d = a - 1;

        boolean found = false;
        for (int i = 0; i < (a / 2); i++) {
            if (g[i].charAt(c) == g[i].charAt(d) && g[(a - 1) - i].charAt(c) == g[(a - 1) - i].charAt(d)) {
                if (i == 0) {
                    q = g[i].charAt(c);
                }
                c++;
                d--;
            } else {
                found = true;
                q = ' ';
                break;
            }
        }
        int v = h.replaceAll("[" + q + q1 + "]", "").length();

        int v1 = h.replaceAll("[" + q1 + "]", "").length();
        int v2 = h.replaceAll("[" + q + "]", "").length();

        if (g[a / 2].charAt(a / 2) == q && !found && v == 0 && q1 != q
                && v1 == ((a * 2) - 1) && v2 == ((a * a) - ((a * 2) - 1))) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }

}


import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class A540 {
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt(),i,j;
        Boolean b = true;
        String a[]= new String[n];
        Set<Character> char_set = new HashSet<Character>();

        for (i=0; i<n; i++)
        {
            a[i]=sc.next();
            for (j=0; j<n; j++)
            {
                char_set.add(a[i].charAt(j));
            }
            if (a[i].charAt(i)!=a[i].charAt(n-i-1))
            {
                b=false;
            }

        }
        if (char_set.size()!=2)
            b=false;

        if (b)
            System.out.println("YES");
        else
            System.out.println("NO");

    }
}


import java.util.Scanner;

public class A404 {
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int i,j, n=sc.nextInt();
        String[] cross = new String[n];
        String result="YES";
        for(i=0; i<n; i++)
        {
            cross[i]=sc.next();
        }
        for(i=0; i<n-1; i++)
        {
            if(cross[i].charAt(i)!=cross[i].charAt(n-i-1))
            {
                result="NO";
                break;
            }
            else
            {
                for(j=0; j<n && j!=i && j!=n-i; j++)
                {
                    if(cross[i].charAt(j)!=cross[0].charAt(1))
                    {
                        System.out.println("i= "+i+" j= "+j);
                        result="NO";
                        break;
                    }
                }
            }
        }
        System.out.println(result);
    }

}


import java.util.Scanner;

public class A404 {
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int i,j, n=sc.nextInt();
        String[] cross = new String[n];
        String result="YES";
        for(i=0; i<n; i++)
        {
            cross[i]=sc.next();
        }
        for(i=0; i<n; i++)
        {
            if(cross[i].charAt(i)!=cross[i].charAt(n-i-1))
            {
                result="NO";
                break;
            }
            else
            {
                for(j=0; j<n && j!=i && j!=n-i; j++)
                {
                    if(cross[i].charAt(j)!=cross[0].charAt(1))
                    {
                        result="NO";
                        break;
                    }
                }
            }
        }
        System.out.println(result);
    }

}


import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class A540 {
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt(),i,j;
        Boolean b = true;
        String a[]= new String[n];
        Set<Character> char_set = new HashSet<Character>();
        Set<Character> temp_set = new HashSet<Character>();

        for (i=0; i<n; i++)
        {
            a[i]=sc.next();
            for (j=0; j<n && b; j++)
            {
                temp_set.add(a[i].charAt(j));
                char_set.add(a[i].charAt(j));
            }
            if (a[i].charAt(i)!=a[i].charAt(n-i-1) || temp_set.size()!=2)
            {
                b=false;
            }
            temp_set.clear();

        }
        if (char_set.size()!=2)
            b=false;

        if (b)
            System.out.println("YES");
        else
            System.out.println("NO");

    }
}


import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
//http://codeforces.com/problemset/problem/404/A

public class A540 {
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt(),i,j;
        Boolean b = true;
        String a[]= new String[n];
        String temp[]= new String[n];

        for (i=0; i<n; i++)
        {
            a[i]=sc.next();
            temp[i]="";
            for (j=0; j<n && b; j++)
            {
               /* System.out.println("i="+i+"\tj="+j+ "\tchar is=" +a[i].charAt(j));
            }*/
                if (j!=i && j!=n-i-1)
                    temp[i]+=a[0].charAt(1);
                else
                    temp[i]+=a[0].charAt(0);
            }

            if (!temp[i].equals(a[i]))
                b=false;

        }

        if (b)
            System.out.println("YES");
        else
            System.out.println("NO");

    }
}


import java.util.Scanner;

public class A404 {
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int i,j, n=sc.nextInt();
        String[] cross = new String[n];
        String result="YES";
        for(i=0; i<n; i++)
        {
            cross[i]=sc.next();
        }
        for(i=0; i<n-1; i++)
        {
            if(cross[i].charAt(i)!=cross[i].charAt(n-i-1))
            {
                result="NO";
                break;
            }
            else
            {
                for(j=0; j<n && j!=i && j!=n-i; j++)
                {
                    if(cross[i].charAt(j)!=cross[0].charAt(1))
                    {
                        result="NO";
                        break;
                    }
                }
            }
        }
        System.out.println(result);
    }

}


import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
//http://codeforces.com/problemset/problem/404/A

public class A540 {
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt(),i,j;
        Boolean b = true;
        String a[]= new String[n];
        String temp[]= new String[n];

        for (i=0; i<n; i++)
        {
            a[i]=sc.next();
            temp[i]="";
            for (j=0; j<n && b; j++)
            {
               /* System.out.println("i="+i+"\tj="+j+ "\tchar is=" +a[i].charAt(j));
            }*/
               if (a[0].charAt(0)==a[0].charAt(1))
                   b=false;
               else if (j!=i && j!=n-i-1)
                    temp[i]+=a[0].charAt(1);
                else
                    temp[i]+=a[0].charAt(0);
            }

            if (!temp[i].equals(a[i]))
                b=false;

        }

        if (b)
            System.out.println("YES");
        else
            System.out.println("NO");

    }
}


import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
//http://codeforces.com/problemset/problem/404/A

public class A540 {
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt(),i,j;
        Boolean b = true;
        String a[]= new String[n];
        String temp[]= new String[n];

        for (i=0; i<n; i++)
        {
            a[i]=sc.next();
            temp[i]="";
            for (j=0; j<n && b; j++)
            {
               /* System.out.println("i="+i+"\tj="+j+ "\tchar is=" +a[i].charAt(j));
            }*/
                if (j!=i)
                    temp[i]+=a[0].charAt(1);
                else
                    temp[i]+=a[0].charAt(0);
            }
            if (!temp[i].equals(a[i]))
                b=false;

        }

        if (b)
            System.out.println("YES");
        else
            System.out.println("NO");

    }
}


import java.util.Scanner;

/**
 * @author AY GaMaL
 *
 */
public class CODEFORCES {

	public static void main(String[] args)  {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		char charOne;
		char charTwo;
		boolean flag=true;
		String x=scan.next();
		charOne=x.charAt(0);
		charTwo=x.charAt(1);
		for(int i=1;i<n;i++) {
			x=scan.next();
			if(x.charAt(i)!=charOne||x.charAt(n-1-i)!=charOne) {
				flag=false;

			}
			for(int j=0;j<x.length();j++) {
				if(j==i||j==n-1-i)continue;
				if(x.charAt(j)!=charTwo)flag=false;

			}

		}
		if(charOne!=charTwo) {
			if(flag)System.out.println("YES");
			else System.out.println("NO");}
		else
			System.out.println("NO");

}
}


import java.util.Scanner;

/**
 * @author AY GaMaL
 *
 */
public class CODEFORCES {

	public static void main(String[] args)  {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		char charOne;
		char charTwo;
		boolean flag=true;
		String x=scan.next();
		charOne=x.charAt(0);
		char charLast=x.charAt(x.length()-1);
		if(charOne!=charLast)flag=false;
		charTwo=x.charAt(1);

		for(int j=0;j<x.length();j++) {
			if(j==0||j==n-1)continue;
			if(x.charAt(j)!=charTwo)flag=false;

		}

		for(int i=1;i<n;i++) {
			x=scan.next();
			if(x.charAt(i)!=charOne||x.charAt(n-1-i)!=charOne||x.charAt(i)!=x.charAt(n-1-i)) {
				flag=false;

			}
			for(int j=0;j<x.length();j++) {
				if(j==i||j==n-1-i)continue;
				if(x.charAt(j)!=charTwo)flag=false;

			}

		}
		if(charOne!=charTwo) {
			if(flag)System.out.println("YES");
			else System.out.println("NO");}
		else
			System.out.println("NO");

}
}


import java.util.Scanner;

/**
 * @author AY GaMaL
 *
 */
public class CODEFORCES {

	public static void main(String[] args)  {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		char charOne;
		char charTwo;
		boolean flag=true;
		String x=scan.next();
		charOne=x.charAt(0);
		charTwo=x.charAt(1);
		for(int i=1;i<n;i++) {
			x=scan.next();
			if(x.charAt(i)!=charOne||x.charAt(n-1-i)!=charOne) {
				flag=false;

			}
			for(int j=0;j<x.length();j++) {
				if(j==i||j==n-1-i)continue;
				if(x.charAt(j)!=charTwo)flag=false;

			}

		}
		if(flag)System.out.println("YES");
		else System.out.println("NO");

}
}


import java.util.Scanner;

/**
 * @author AY GaMaL
 *
 */
public class CODEFORCES {

	public static void main(String[] args)  {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		char charOne;
		char charTwo;
		boolean flag=true;
		String x=scan.next();
		charOne=x.charAt(0);
		char charLast=x.charAt(x.length()-1);
		if(charOne!=charLast)flag=false;
		charTwo=x.charAt(1);
		for(int i=1;i<n;i++) {
			x=scan.next();
			if(x.charAt(i)!=charOne||x.charAt(n-1-i)!=charOne||x.charAt(i)!=x.charAt(n-1-i)) {
				flag=false;

			}
			for(int j=0;j<x.length();j++) {
				if(j==i||j==n-1-i)continue;
				if(x.charAt(j)!=charTwo)flag=false;

			}

		}
		if(charOne!=charTwo) {
			if(flag)System.out.println("YES");
			else System.out.println("NO");}
		else
			System.out.println("NO");

}
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Solution {

	public static void main(String args[]) throws Exception {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		String[] arr = new String[n];
		HashMap<Character,Integer> set = new HashMap<Character,Integer>();
		boolean flag = true;
		for(int i=0;i<n;i++){
			arr[i] = sc.nextToken();
			for(int j=0;j<n;j++){
				if(!set.containsKey(arr[i].charAt(j)))
					set.put(arr[i].charAt(j),1);
				else
					set.put(arr[i].charAt(j), set.get(arr[i].charAt(j))+1);
			}
		}

		for(int i=0;i<n/2;i++){
			if(arr[i].charAt(i)!=arr[i].charAt(n-i-1) || arr[i].charAt(i)!=arr[0].charAt(0)){
				flag = false;
				break;
			}
		}
		if(flag){
			for(int i=n/2+1;i<n;i++){
				if(arr[i].charAt(i)!=arr[i].charAt(n-i-1) || arr[i].charAt(i)!=arr[0].charAt(0)){
					flag = false;
					break;
				}
			}
		}

		if(flag && set.size()==2 && set.get(arr[0].charAt(0))==((n-1)*2+1))
			System.out.println("YES");
		else
			System.out.println("NO");
	}

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Solution {

	public static void main(String args[]) throws Exception {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		String[] arr = new String[n];
		TreeSet<Character> set = new TreeSet<Character>();
		boolean flag = true;
		for(int i=0;i<n;i++){
			arr[i] = sc.nextToken();
			for(int j=0;j<n;j++){
				set.add(arr[i].charAt(j));
			}
		}

		for(int i=0;i<n/2;i++){
			if(arr[i].charAt(i)!=arr[i].charAt(n-i-1)){
				flag = false;
				break;
			}
		}
		if(flag){
			for(int i=n/2+1;i<n;i++){
				if(arr[i].charAt(i)!=arr[i].charAt(n-i-1)){
					flag = false;
					break;
				}
			}
		}

		if(flag&set.size()==2)
			System.out.println("YES");
		else
			System.out.println("NO");
	}

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Solution {

	public static void main(String args[]) throws Exception {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		String[] arr = new String[n];
		HashMap<Character,Integer> set = new HashMap<Character,Integer>();
		boolean flag = true;
		for(int i=0;i<n;i++){
			arr[i] = sc.nextToken();
			for(int j=0;j<n;j++){
				if(!set.containsKey(arr[i].charAt(j)))
					set.put(arr[i].charAt(j),1);
				else
					set.put(arr[i].charAt(j), set.get(arr[i].charAt(j))+1);
			}
		}

		for(int i=0;i<n/2;i++){
			if(arr[i].charAt(i)!=arr[i].charAt(n-i-1) || arr[i].charAt(i)!=arr[0].charAt(0)){
				flag = false;
				break;
			}
		}
		if(flag){
			for(int i=n/2;i<n;i++){
				if(arr[i].charAt(i)!=arr[i].charAt(n-i-1) || arr[i].charAt(i)!=arr[0].charAt(0)){
					flag = false;
					break;
				}
			}
		}

		if(flag && set.size()==2 && set.get(arr[0].charAt(0))==((n-1)*2+1))
			System.out.println("YES");
		else
			System.out.println("NO");
	}

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Solution {

	public static void main(String args[]) throws Exception {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		String[] arr = new String[n];
		HashMap<Character,Integer> set = new HashMap<Character,Integer>();
		boolean flag = true;
		for(int i=0;i<n;i++){
			arr[i] = sc.nextToken();
			for(int j=0;j<n;j++){
				if(!set.containsKey(arr[i].charAt(j)))
					set.put(arr[i].charAt(j),1);
				else
					set.put(arr[i].charAt(j), set.get(arr[i].charAt(j))+1);
			}
		}

		for(int i=0;i<n/2;i++){
			if(arr[i].charAt(i)!=arr[i].charAt(n-i-1)){
				flag = false;
				break;
			}
		}
		if(flag){
			for(int i=n/2+1;i<n;i++){
				if(arr[i].charAt(i)!=arr[i].charAt(n-i-1)){
					flag = false;
					break;
				}
			}
		}

		if(flag && set.size()==2 && set.get(arr[0].charAt(0))==((n-1)*2+1))
			System.out.println("YES");
		else
			System.out.println("NO");
	}

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

}


import java.util.*;
public class Homework{
    public static void main(String args[]){
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        char[][] a = new char[n][n];
        boolean flag = false;
        String str = "";
        for(int i=0;i<n;i++){
            str = s.next();
            a[i] = str.toCharArray();
        }
        for(int m=0;m<n;m++){
            for(int l = 0; l<n; l++){
                if((((m==l)||(m==n-1-l)) && (a[m][l] == a[0][0])) || (a[m][l] == a[0][1])){
                    flag = true;
                }
                else{
                    flag = false;
                    System.out.println("NO");
                    break;
                }
            }
            if(flag == false){
                break;
            }
            else
                continue;
        }
        if(flag == true){
            System.out.println("YES");
        }
    }
}


import java.util.*;
public class Homework{
    public static void main(String args[]){
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        char[][] a = new char[n][n];
        boolean flag = false;
        String str = "";
        for(int i=0;i<n;i++){
            str = s.next();
            a[i] = str.toCharArray();
        }
        for(int m=0;m<n;m++){
            for(int l = 0; l<n; l++){
                if((((m==l)||(m==n-1-l)) && (a[m][l] == a[0][0])) || (a[m][l] == a[0][1])){
                    flag = true;
                }
                else{
                    flag = false;
                    System.out.println("No");
                    break;
                }
            }
            if(flag == false){
                break;
            }
            else
                continue;
        }
        if(flag == true){
            System.out.println("Yes");
        }
    }
}


import java.util.*;
public class Homework{
    public static void main(String args[]){
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        char[][] a = new char[n][n];
        boolean flag = false;
        String str = "";
        for(int i=0;i<n;i++){
            str = s.next();
            a[i] = str.toCharArray();
        }
        for(int m=0;m<n;m++){
            for(int l = 0; l<n; l++){
                if((((m==l)||(m==n-1-l)) && (a[m][l] == a[0][0])) || ((a[m][l] == a[0][1]) && a[m][l] != a[0][0] )){
                    flag = true;
                }
                else{
                    flag = false;
                    System.out.println("NO");
                    break;
                }
            }
            if(flag == false){
                break;
            }
            else
                continue;
        }
        if(flag == true){
            System.out.println("YES");
        }
    }
}


import java.util.*;
public class Homework{
    public static void main(String args[]){
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        char[][] a = new char[n][n];
        boolean flag = false;
        String str = "";
        for(int i=0;i<n;i++){
            str = s.next();
            a[i] = str.toCharArray();
        }
        if (a[0][0] == a[0][1]) {
            System.out.println("NO");
            return;
        }
        for(int m=0;m<n;m++){
            for(int l = 0; l<n; l++){
                if  ((m == l) || (m == n - 1 - l)) {
                    if (a[m][l] == a[0][0]) {
                        flag = true;
                    } else {
                        flag = false;
                        System.out.println("NO");
                        break;
                    }
                } else {
                    if (a[m][l] == a[0][1]) {
                        flag = true;
                    } else {
                        flag = false;
                        System.out.println("NO");
                        break;
                    }
                }
            }
            if(flag == false){
                break;
            }
        }
        if(flag == true){
            System.out.println("YES");
        }
    }
}


import java.util.*;
public class Homework{
    public static void main(String args[]){
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        char[][] a = new char[n][n];
        boolean flag = false;
        for(int i=0;i<n;i++){
            for(int j = 0; j<n; j++){
                a[i][j] = s.next().charAt(0);
            }
        }
        for(int m=0;m<n;m++){
            for(int l = 0; l<n; l++){
                if((((m==l)||(m==n-1-l)) && (a[m][l] == a[0][0])) || (a[m][l] == a[0][1])){
                    flag = true;
                }
                else{
                    flag = false;
                    System.out.println("No");
                    break;
                }
            }
            if(flag == false){
                break;
            }
            else
                continue;
        }
        if(flag == true){
            System.out.println("Yes");
        }
    }
}


import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main{

    public static void main(String[] args)
    {
			Scanner in=new Scanner(System.in);
			int n=in.nextInt();
			in.nextLine();
			int pivot=n/2;
			int count=0;
			char c='`';
			int k=0;
			Set<Character> setDiagonal=new HashSet<Character>();
			Set<Character> setOther=new HashSet<Character>();

			String arr[]=new String[n];

			for(int i=0;i<n;i++)
			arr[i]=in.nextLine();

			for(int i=0;i<n;i++)
			{
				for(int j=0;j<n;j++)
				{
					if(i==j || (i+j)==(n-1))setDiagonal.add(arr[i].charAt(j));
					else
					{
						setOther.add(arr[i].charAt(j));
					}
				}
			}

			// for (char s : setDiagonal) {
			// 	System.out.print(s+" ");
			// }
			// System.out.println();
			// for (char s : setOther) {
			// 	System.out.print(s+" ");
			// }
			if(setDiagonal.size()==setOther.size() && setDiagonal.size()==1)
			{
				setDiagonal.removeAll(setOther);
				if(!setDiagonal.isEmpty())
				{
					System.out.println("YES");
				}
				else System.out.println("NO");
			}
			else System.out.println("NO");

	}

}


import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main{

    public static void main(String[] args)
    {
			Scanner in=new Scanner(System.in);
			int n=in.nextInt();
			in.nextLine();
			int pivot=n/2;
			int count=0;
			char c='`';
			int k=0;
			// String s="";
			String arr[]=new String[n];

			for(int i=0;i<n;i++)
			arr[i]=in.nextLine();
			// s=in.nextLine();
			// if(arr[].charAt(0)==s.charAt(n-1)){count++;c=s.charAt(0);}

			char y=arr[0].charAt(1);

			for( k=0;k<pivot;k++)
			{
				//  s=in.nextLine();

					if(arr[k].charAt(k)==arr[k].charAt(n-1-k)){count++;c=arr[k].charAt(k);}
			}
			// System.out.println(c);
			if(arr[k].charAt(k)==c){count++;k++;}
			// System.out.println(k);
			for( k=k;k<n;k++)
			{
				//  s=in.nextLine();
				if(arr[k].charAt(k)==arr[k].charAt(n-k-1)){count++;}
			}

			boolean flag=false;
			// System.out.println(c+" "+y);
			for(int i=0;i<n && flag==false;i++)
			{
				for(int j=0;j<n;j++)
				{
					if(arr[i].charAt(j)!=c && arr[i].charAt(j)!=y){flag=true;break;}
				}
			}
			if(!flag && count==n)System.out.println("YES");
			else System.out.println("NO");

	}

}


import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main{

    public static void main(String[] args)
    {
			Scanner in=new Scanner(System.in);
			int n=in.nextInt();
			in.nextLine();
			int pivot=n/2;
			int count=0;
			char c='`';
			int k=0;
			// String s="";
			String arr[]=new String[n];

			for(int i=0;i<n;i++)
			arr[i]=in.nextLine();
			// s=in.nextLine();
			// if(arr[].charAt(0)==s.charAt(n-1)){count++;c=s.charAt(0);}

			char y=arr[0].charAt(1);

			for( k=0;k<pivot;k++)
			{
				//  s=in.nextLine();

					if(arr[k].charAt(k)==arr[k].charAt(n-1-k)){count++;c=arr[k].charAt(k);}
			}
			// System.out.println(count);

			if(arr[k].charAt(k)==c){count++;k++;}
			else k++;
			// System.out.println(k);
			for( k=k;k<n;k++)
			{
				//  s=in.nextLine();
				if(arr[k].charAt(k)==arr[k].charAt(n-k-1)){count++;}
			}
			// System.out.println(count);
			boolean flag=false;
			if(c==y)flag=true;
			// System.out.println(c+" "+y);
			for(int i=0;i<n && flag==false;i++)
			{
				for(int j=0;j<n;j++)
				{
					if(arr[i].charAt(j)!=c && arr[i].charAt(j)!=y){flag=true;break;}
				}
			}
			// System.out.println(count);
			if(!flag && count==n)System.out.println("YES");
			else System.out.println("NO");

	}

}


import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main{

    public static void main(String[] args)
    {
			Scanner in=new Scanner(System.in);
			int n=in.nextInt();
			in.nextLine();
			int pivot=n/2;
			int count=0;
			char c='`';
			int k=0;
			// String s="";
			String arr[]=new String[n];

			for(int i=0;i<n;i++)
			arr[i]=in.nextLine();
			// s=in.nextLine();
			// if(arr[].charAt(0)==s.charAt(n-1)){count++;c=s.charAt(0);}

			char y=arr[0].charAt(1);

			for( k=0;k<pivot;k++)
			{
				//  s=in.nextLine();

					if(arr[k].charAt(k)==arr[k].charAt(n-1-k)){count++;c=arr[k].charAt(k);}
			}
			// System.out.println(c);
			if(arr[k].charAt(k)==c){count++;k++;}
			System.out.println(k);
			for( k=k;k<n;k++)
			{
				//  s=in.nextLine();
				if(arr[k].charAt(k)==arr[k].charAt(n-k-1)){count++;}
			}

			boolean flag=false;
			// System.out.println(c+" "+y);
			for(int i=0;i<n && flag==false;i++)
			{
				for(int j=0;j<n;j++)
				{
					if(arr[i].charAt(j)!=c && arr[i].charAt(j)!=y){flag=true;break;}
				}
			}
			if(!flag && count==n)System.out.println("YES");
			else System.out.println("NO");

	}

}


import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main{

    public static void main(String[] args)
    {
			Scanner in=new Scanner(System.in);
			int n=in.nextInt();
			in.nextLine();
			int pivot=n/2;
			int count=0;
			char c='`';
			int k=0;
			Set<Character> setDiagonal=new HashSet<Character>();
			Set<Character> setOther=new HashSet<Character>();

			String arr[]=new String[n];

			for(int i=0;i<n;i++)
			arr[i]=in.nextLine();

			for(int i=0;i<n;i++)
			{
				for(int j=0;j<n;j++)
				{
					if(i==j || (i+j)==(n-1))setDiagonal.add(arr[i].charAt(j));
					else
					{
						setOther.add(arr[i].charAt(j));
					}
				}
			}

			// for (char s : setDiagonal) {
			// 	System.out.println(s);
			// }
			if(setDiagonal.size()==setOther.size())
			{
				setDiagonal.removeAll(setOther);
				if(!setDiagonal.isEmpty())
				{
					System.out.println("YES");
				}
			}
			else System.out.println("NO");

	}

}


import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main{

    public static void main(String[] args)
    {
			Scanner in=new Scanner(System.in);
			int n=in.nextInt();
			in.nextLine();
			int pivot=n/2;
			int count=0;
			char c='`';
			int k=0;
			// String s="";
			String arr[]=new String[n];

			for(int i=0;i<n;i++)
			arr[i]=in.nextLine();
			// s=in.nextLine();
			// if(arr[].charAt(0)==s.charAt(n-1)){count++;c=s.charAt(0);}

			char y=arr[0].charAt(1);

			for( k=0;k<pivot;k++)
			{
				//  s=in.nextLine();

					if(arr[k].charAt(k)==arr[k].charAt(n-1-k)){count++;c=arr[k].charAt(k);}
			}
			// System.out.println(c);
			if(arr[k].charAt(k)==c){count++;k++;}
			// System.out.println(k);
			for( k=k;k<n;k++)
			{
				//  s=in.nextLine();
				if(arr[k].charAt(k)==arr[k].charAt(n-k-1)){count++;}
			}

			boolean flag=false;
			if(c==y)flag=true;
			// System.out.println(c+" "+y);
			for(int i=0;i<n && flag==false;i++)
			{
				for(int j=0;j<n;j++)
				{
					if(arr[i].charAt(j)!=c && arr[i].charAt(j)!=y){flag=true;break;}
				}
			}
			if(!flag && count==n)System.out.println("YES");
			else System.out.println("NO");

	}

}


import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main{

    public static void main(String[] args)
    {
			Scanner in=new Scanner(System.in);
			int n=in.nextInt();
			in.nextLine();
			int pivot=n/2;
			int count=0;
			char c='`';
			int k=0;
			Set<Character> setDiagonal=new HashSet<Character>();
			Set<Character> setOther=new HashSet<Character>();

			String arr[]=new String[n];

			for(int i=0;i<n;i++)
			arr[i]=in.nextLine();

			for(int i=0;i<n;i++)
			{
				for(int j=0;j<n;j++)
				{
					if(i==j || (i+j)==(n-1))setDiagonal.add(arr[i].charAt(j));
					else
					{
						setOther.add(arr[i].charAt(j));
					}
				}
			}

			// for (char s : setOther) {
			// 	System.out.println(s);
			// }
			if(setDiagonal.size()==setOther.size())
			{
				setDiagonal.removeAll(setOther);
				if(!setDiagonal.isEmpty())
				{
					System.out.println("YES");
				}
				else System.out.println("NO");
			}
			else System.out.println("NO");

	}

}


import java.util.Arrays;
import java.util.Scanner;

public class Somm {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t=in.nextInt();
       char a[][]=new char[t][t];
        boolean f=false;
       char first,second;
        for(int i=0;i<t;i++)
        {
            String s=in.next();
            for(int j=0;j<t;j++)
            {  a[i][j]=s.charAt(j);
                first=a[0][0];
                second=a[0][1];

                if(i==j)
                {
                    if(first!=a[i][j])
                    {
                        f=true;

                      //break;
                    }

                }
                else if(i==(t-1-j))
                {
                   if(first!=a[i][j])
                    {
                        f=true;

                      //break;
                    }

                }
                else
                {

                    if(first==a[i][j]||second!=a[i][j])
                    {
                        f=true;
                       //break;
                    }

                }

            }
            if(f)
                break;
        }

    if(f)
            System.out.println("NO");
        else
            System.out.println("YES");

}
   }


import java.util.Arrays;
import java.util.Scanner;

public class Somm {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t=in.nextInt();
       char a[][]=new char[t][t];
        boolean f=false;
       char first,second;
        for(int i=0;i<t;i++)
        {
            String s=in.next();
            for(int j=0;j<t;j++)
            {  a[i][j]=s.charAt(j);
                first=a[0][0];
                second=a[0][1];

                if(i==j)
                {
                    if(first!=a[i][j])
                    {
                        f=true;

                      //break;
                    }

                }
                else if(i==(t-1-j))
                {
                   if(first!=a[i][j])
                    {
                        f=true;

                      //break;
                    }

                }
                else
                {

                    if(first==a[i][j]||second!=a[i][j])
                    {
                        f=true;
                       //break;
                    }

                }

            }
        }

    if(f)
            System.out.println("NO");
        else
            System.out.println("YES");

}
   }


import java.util.Scanner;

public class Diaa {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t=in.nextInt();
        char c[][]=new char[t][t];
        char first,sec;
        boolean f=false;
        for(int i=0;i<t;i++)
        {
            String s=in.next();
            for(int j=0;j<t;j++)
            {
               c[i][j]=s.charAt(j);
               first=c[0][0];
               sec=c[0][1];
               if(i==j)
               {
                 if(first!=c[i][j])
                 {
                    f=true;
                 }
               }
               else if(i==t-1-j)
               {
                  if(first!=c[i][j])
                  {
                      f=true;
                  }
               }
               else
               {
                   if(sec!=c[i][j]||first==c[i][j])
                   {
                       f=true;
                   }
               }
               if(f)
               {
                   break;
               }

            }

        }
          if(f)
              System.out.println("NO");
          else
              System.out.println("YES");
    }

}


import java.util.Scanner;

public class Diaa {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t=in.nextInt();
        char c[][]=new char[t][t];
        char first,sec;
        boolean f=false;
        for(int i=0;i<t;i++)
        {
            String s=in.next();
            for(int j=0;j<t;j++)
            {
               c[i][j]=s.charAt(j);
               first=c[0][0];
               sec=c[0][1];
               if(i==j)
               {
                 if(first!=c[i][j])
                 {
                    f=true;
                 }
               }
               else if(i==t-1-j)
               {
                  if(first!=c[i][j])
                  {
                      f=true;
                  }
               }
               else
               {
                   if(sec!=c[i][j]||first==c[i][j])
                   {
                       f=true;
                   }
               }

            }
             if(f)
               {
                   break;
               }

        }
          if(f)
              System.out.println("NO");
          else
              System.out.println("YES");
    }

}


import java.util.Scanner;

public class Diaa {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t=in.nextInt();
        char c[][]=new char[t][t];
        boolean f=false;
        char first,sec;
        for(int i=0;i<t;i++)
        {
            String s=in.next();
            for(int j=0;j<t;j++)
            {
                c[i][j]=s.charAt(j);
                first=c[0][0];
                sec=c[0][1];
                if(i==j)
                {
                    if(first!=c[i][j])
                    {
                        f=true;
                    }
                }
                else if(i==t-1-j)
                {
                  if(first!=c[i][j])
                  {
                      f=true;
                  }

                }
                else
                {
                   if(sec!=c[i][j]||first==c[i][j])
                   {
                       f=true;
                   }
                }

            }
           if(f)
               break;
        }
       if(f)
            System.out.println("NO");
       else
            System.out.println("YES");
    }

}


import java.util.Arrays;
import java.util.Scanner;

public class Somm {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t=in.nextInt();
       char a[][]=new char[t][t];
       char first,second;
        for(int i=0;i<t;i++)
        {
            String s=in.next();
            for(int j=0;j<t;j++)
                a[i][j]=s.charAt(j);

        }
        first=a[0][0];
        second=a[0][1];
        boolean f=false;

        for(int r=0;r<t;r++)
            for(int q=0;q<t;q++)
            {

                if(r==q)
                {
                    if(first!=a[r][q])
                    {
                        f=true;

                      break;
                    }

                }
                else if(r==(t-1-q))
                {
                   if(first!=a[r][q])
                    {
                        f=true;

                      break;
                    }

                }
                else
                {

                    if(first==a[r][q]||second!=a[r][q])
                    {
                        f=true;

                       break;
                    }

                }

            }
        if(f)
            System.out.println("NO");
        else
            System.out.println("YES");

    }

}


import java.util.Arrays;
import java.util.Scanner;

public class Somm {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t=in.nextInt();
       char a[][]=new char[t][t];
        boolean f=false;
       char first,second;
        for(int i=0;i<t;i++)
        {
            String s=in.next();
            for(int j=0;j<t;j++)
            {  a[i][j]=s.charAt(j);
                first=a[0][0];
                second=a[0][1];

                if(i==j)
                {
                    if(first!=a[i][j])
                    {
                        f=true;

                      break;
                    }

                }
                else if(i==(t-1-j))
                {
                   if(first!=a[i][j])
                    {
                        f=true;

                      break;
                    }

                }
                else
                {

                    if(first==a[i][j]||second!=a[i][j])
                    {
                        f=true;
                       break;
                    }

                }

            }
        }

    if(f)
            System.out.println("NO");
        else
            System.out.println("YES");

}
   }


import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		ArrayList<String> input = new ArrayList<>();
		int size;
		boolean diagonal = true;
		size = in.nextInt();
		in.nextLine();
		char letterDiagonal, otherLetter;
		for (int i = 0; i < size; i++) {
			String line = in.nextLine();
			input.add(line);
		}

		letterDiagonal = input.get(0).charAt(0);
		otherLetter = input.get(0).charAt(1);

		for (int i = 0; i < size; i++) {
			for (int j = 0; j < size; j++) {
				if (i + j == size - 1 && input.get(i).charAt(j) != letterDiagonal) {
					diagonal = false;
					break;
				} else if (i == j && input.get(i).charAt(j) != letterDiagonal) {
					diagonal = false;
					break;
				} else if (input.get(i).charAt(j) != letterDiagonal
						&& input.get(i).charAt(j) != otherLetter) {
					diagonal = false;
					break;
				} else if (letterDiagonal == otherLetter){
					diagonal = false;
					break;
				}

			}
		}

		if(diagonal) System.out.println("YES");
		else System.out.println("NO");
	}

}


import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        ArrayList<String> input = new ArrayList<>();
        int size;
        int numOfDiagonalLetter = 0;
        boolean diagonal = true;
        char letterDiagonal, otherLetter;

        size = in.nextInt();
        in.nextLine();

        for (int i = 0; i < size; i++) {
            String line = in.nextLine();
            input.add(line);
        }

        //default values
        letterDiagonal = input.get(0).charAt(0);
        otherLetter = input.get(0).charAt(1);

        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                if (i + j == size - 1 && input.get(i).charAt(j) != letterDiagonal) {
                    diagonal = false;
                    break;
                } else if (i == j && input.get(i).charAt(j) != letterDiagonal) {
                    diagonal = false;
                    break;
                } else if (input.get(i).charAt(j) != letterDiagonal
                        && input.get(i).charAt(j) != otherLetter) {
                    diagonal = false;
                    break;
                } else if (letterDiagonal == otherLetter){
                    diagonal = false;
                    break;
                } else if(j > i && input.get(i).charAt(j) == letterDiagonal && i + j!= size-1){
                    diagonal = false;
                    break;
                }
                if(input.get(i).charAt(j) == letterDiagonal) numOfDiagonalLetter++;
            }
        }

        if(numOfDiagonalLetter > (size * 2) - 1){
            diagonal = false;
        }

        if(diagonal) System.out.println("YES");
        else System.out.println("NO");
    }

}


import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		ArrayList<String> input = new ArrayList<>();
		int size;
		boolean diagonal = true;
		size = in.nextInt();
		in.nextLine();
		char letterDiagonal, otherLetter;
		for (int i = 0; i < size; i++) {
			String line = in.nextLine();
			input.add(line);
		}

		letterDiagonal = input.get(0).charAt(0);
		otherLetter = input.get(0).charAt(1);

		for (int i = 0; i < size; i++) {
			for (int j = 0; j < size; j++) {
				if (i + j == size - 1 && input.get(i).charAt(j) != letterDiagonal) {
					diagonal = false;
					break;
				} else if (i == j && input.get(i).charAt(j) != letterDiagonal) {
					diagonal = false;
					break;
				} else if (input.get(i).charAt(j) != letterDiagonal
						&& input.get(i).charAt(j) != otherLetter) {
					diagonal = false;
					break;
				} else if (letterDiagonal == otherLetter){
					diagonal = false;
					break;
				} else if(j > i && input.get(i).charAt(j) == letterDiagonal && i + j!= size-1){
					diagonal = false;
					break;
				}

			}
		}

		if(diagonal) System.out.println("YES");
		else System.out.println("NO");
	}

}


import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		ArrayList<String> input = new ArrayList<>();
		int size;
		boolean diagonal = true;
		size = in.nextInt();
		in.nextLine();
		char letterDiagonal, otherLetter;
		for (int i = 0; i < size; i++) {
			String line = in.nextLine();
			input.add(line);
		}

		letterDiagonal = input.get(0).charAt(0);
		otherLetter = input.get(0).charAt(1);

		for (int i = 0; i < size; i++) {
			for (int j = 0; j < size; j++) {
				if (i + j == size - 1 && input.get(i).charAt(j) != letterDiagonal) {
					diagonal = false;
					break;
				} else if (i == j && input.get(i).charAt(j) != letterDiagonal) {
					diagonal = false;
					break;
				} else if (input.get(i).charAt(j) != letterDiagonal
						&& input.get(i).charAt(j) != otherLetter) {
					diagonal = false;
					break;
				}

			}
		}

		if(diagonal) System.out.println("YES");
		else System.out.println("NO");
	}

}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author islam
 */
public class Valera_and_X {

public static void main (String args[]){

Scanner in = new Scanner (System.in);
int size = in.nextInt();

char[][] problem = new char[size][size];
String line= "";
for (int i = 0 ; i<size ; i++){
line = in.next();

for (int  j=0; j<size;j++){

problem[i][j] = line.charAt(j);
}

//    System.out.println("");
}

//    for (int i = 0; i < size; i++) {
//        for (int j = 0; j <size ; j++) {
//            System.out.print(problem[i][j]);
//        }
//        System.out.println();
//    }
char x = problem[0][0];
char y = problem[0][1];
int countdia = 0;
int countrest=0;
int totalCount = (2*size)-1;
for (int i =0; i< size ; i++){

for (int j=0; j< size ; j++){
if (i ==j  || i+j == size-1 ){
if (problem[i][j]==x)
   countdia ++;
}

else if(problem[i][j]== y){
countrest++;

}

}

}

//    System.out.println(countdia );
//    System.out.println(countrest );
//    System.out.println(totalCount );
if (countdia == totalCount && countrest == ((size*size )- totalCount) && y != x){
    System.out.println("YES");
}
    else {
    System.out.println("NO");
            }
}

}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author islam
 */
public class Valera_and_X {

public static void main (String args[]){

Scanner in = new Scanner (System.in);
int size = in.nextInt();

char[][] problem = new char[size][size];
String line= "";
for (int i = 0 ; i<size ; i++){
line = in.next();

for (int  j=0; j<size;j++){

problem[i][j] = line.charAt(j);
}

//    System.out.println("");
}

//    for (int i = 0; i < size; i++) {
//        for (int j = 0; j <size ; j++) {
//            System.out.print(problem[i][j]);
//        }
//        System.out.println();
//    }
char x = problem[0][0];
char y = problem[0][1];
int countdia = 0;
int countrest=0;
int totalCount = (2*size)-1;
for (int i =0; i< size ; i++){

for (int j=0; j< size ; j++){
if (i ==j  || i+j == size-1 ){
if (problem[i][j]==x)
   countdia ++;
}

else if(problem[i][j]== y){
countrest++;

}

}

}

//    System.out.println(countdia );
//    System.out.println(countrest );
//    System.out.println(totalCount );
if (countdia == totalCount && countrest == ((size*size )- totalCount) ){
    System.out.println("YES");
}
    else {
    System.out.println("NO");
            }
}

}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author islam
 */
public class Valera_and_X {

public static void main (String args[]){

Scanner in = new Scanner (System.in);
int size = in.nextInt();

char[][] problem = new char[size][size];
String line= "";
for (int i = 0 ; i<size ; i++){
line = in.next();

for (int  j=0; j<size;j++){

problem[i][j] = line.charAt(j);
}

    System.out.println("");
}

//    for (int i = 0; i < size; i++) {
//        for (int j = 0; j <size ; j++) {
//            System.out.print(problem[i][j]);
//        }
//        System.out.println();
//    }
char x = problem[0][0];
char y = problem[0][1];
int countdia = 0;
int countrest=0;
int totalCount = (2*size)-1;
for (int i =0; i< size ; i++){

for (int j=0; j< size ; j++){
if (i ==j  || i+j == size-1 ){
if (problem[i][j]==x)
   countdia ++;
}

else if(problem[i][j]== y){
countrest++;

}

}

}

//    System.out.println(countdia );
//    System.out.println(countrest );
//    System.out.println(totalCount );
if (countdia == totalCount && countrest == ((size*size )- totalCount) ){
    System.out.println("YES");
}
    else {
    System.out.println("NO");
            }
}

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Problems {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        HashMap<Character, Integer> diagonals  = new HashMap<>();
        HashMap<Character, Integer> other_quares  = new HashMap<>();

        char arr[][] = new char[n][n];
        int index = 0;
        String s = "";
       /* char ch = ' ';
        char ch1 = ' ';
        int count1 = 0 , count2 = 0;
*/
        for (int i = 0; i < n; i++) {

            s = in.next();
            for (int j = 0; j < n; j++) {
                arr[i][j] = s.charAt(j);

            }
        }
        index = n - 1;
        for (int i = 0; i < n; i++) {

            for (int j = 0; j < n; j++) {
                if (i == j || j == index) {
                    diagonals.put(arr[i][j], 1);
                    /*
                    map.put(arr[i][j], 1);
                    ch = arr[i][j];
                    if (ch1 != arr[i][j]) {
                        map.put(arr[i][j], 1);
                    } else {
                        System.out.println("NO");
                        return;
                    }
                    if (!(map.size() <= 2)) {
                        System.out.println("NO");
                        return;
                    }
                     */
                } else {
                    other_quares.put(arr[i][j], 1);
                    /*
                    ch1 = arr[i][j];

                    if (ch != arr[i][j]) {
                        map.put(arr[i][j], 1);
                    }

                    if (!(map.size() == 2)) {
                        System.out.println("NO");
                        return;
                    }
                     */
                }

            }
            --index;

        }
        if (diagonals.size() == 1 && other_quares.size() == 1) {
             Character key = null ;

            for (Map.Entry<Character, Integer> entry : other_quares.entrySet()) {
                 key = entry.getKey();

            }
             Character key1 = null;

   for (Map.Entry<Character, Integer> entry : diagonals.entrySet()) {
                 key1 = entry.getKey();

            }

            if(key1 != key)
            {
               System.out.println("YES");
            }
            else
            {
                 System.out.println("NO");
            }

        } else {
            System.out.println("NO");
        }

    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Problems {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
         Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        HashMap <Character,Integer> map = new HashMap<>();
        char arr[][] = new char[n][n];
        int index = 0;
        String s = "";
        int count0 = 0 ,count1 = 0 ;

          for (int i = 0; i < n; i++)
        {

            s = in.next();
            for (int j = 0; j < n; j++)
            {
              arr[i][j] = s.charAt(j);
            }
        }

        for (int i = 0; i < n; i++)
        {
          index = n - 1;
            for (int j = 0; j < n; j++)
            {
               if(i == j || j == index)
               {
                   map.put(arr[i][j], ++count0);
                   if(!(map.size() <= 2))
                   {
                       System.out.println("NO");
                       return;
                   }

               }
               else
               {
                     map.put(arr[i][j], ++count1);
                      if(!(map.size() == 2))
                   {
                       System.out.println("NO");
                       return;
                   }
               }

            }
            --index;

        }
            if(map.size() == 2 )
            {

              System.out.println("YES");
            }
            else
            {
                System.out.println("NO");
            }

    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Problems {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
         Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        HashMap <Character,Integer> map = new HashMap<>();

        char arr[][] = new char[n][n];
        int index = 0;
        String s = "";
        char ch = ' ';
         char ch1 = ' ';
        int count0 = 0 ,count1 = 0 ;

          for (int i = 0; i < n; i++)
        {

            s = in.next();
            for (int j = 0; j < n; j++)
            {
              arr[i][j] = s.charAt(j);
            }
        }
          index = n - 1;
        for (int i = 0; i < n; i++)
        {

            for (int j = 0; j < n; j++)
            {
               if(i == j || j == index)
               {
                   map.put(arr[i][j], 1);
                   ch = arr[i][j] ;
                     if(ch1 !=arr[i][j] )
                   map.put(arr[i][j], 1);
                     else
                     {
                      System.out.println("NO");
                       return;
                     }
                   if(!(map.size() <= 2))
                   {
                       System.out.println("NO");
                       return;
                   }

               }
               else
               {
                  ch1 = arr[i][j];

                    if(ch !=arr[i][j] )
                   map.put(arr[i][j], 1);

                      if(!(map.size() == 2))
                   {
                       System.out.println("NO");
                       return;
                   }
             }

            }
            --index;

        }
            if(map.size() == 2 )
            {

              System.out.println("YES");
            }
            else
            {
                System.out.println("NO");
            }

    }

}


import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Problems {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
         Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        HashMap <Character,Integer> map = new HashMap<>();
        char arr[][] = new char[n][n];
        int index = 0;
        String s = "";
          for (int i = 0; i < n; i++)
        {

            s = in.next();
            for (int j = 0; j < n; j++)
            {
              arr[i][j] = s.charAt(j);
            }
        }

        for (int i = 0; i < n; i++)
        {
          index = n - 1;
            for (int j = 0; j < n; j++)
            {
               if(i == j || j == index)
               {
                   map.put(arr[i][j], 1);
                   if(!(map.size() <= 2))
                   {
                       System.out.println("No");
                       return;
                   }

               }
               else
               {
                     map.put(arr[i][j], 1);
                      if(!(map.size() <= 2))
                   {
                       System.out.println("No");
                       return;
                   }
               }

            }
            --index;

        }
            if(map.size() == 2)
            {
              System.out.println("Yes");
            }
            else
            {
                System.out.println("No");
            }

    }

}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Problems {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
         Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        HashMap <Character,Integer> map = new HashMap<>();
        char arr[][] = new char[n][n];
        int index = 0;
        String s = "";
        int count0 = 0 ,count1 = 0 ;

          for (int i = 0; i < n; i++)
        {

            s = in.next();
            for (int j = 0; j < n; j++)
            {
              arr[i][j] = s.charAt(j);
            }
        }

        for (int i = 0; i < n; i++)
        {
          index = n - 1;
            for (int j = 0; j < n; j++)
            {
               if(i == j || j == index)
               {
                   map.put(arr[i][j], ++count0);
                   if(!(map.size() <= 2))
                   {
                       System.out.println("NO");
                       return;
                   }

               }
               else
               {
                     map.put(arr[i][j], ++count1);
                      if(!(map.size() <= 2))
                   {
                       System.out.println("NO");
                       return;
                   }
               }

            }
            --index;

        }
            if(map.size() == 2 )
            {
                for (Map.Entry<Character, Integer> entry : map.entrySet()) {
            Character key = entry.getKey();
            Integer value = entry.getValue();
           if(!(value == n * 2))
           {
           System.out.println("NO");
           return;
           }

        }
              System.out.println("YES");
            }
            else
            {
                System.out.println("NO");
            }

    }

}


import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Problems {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
         Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        HashMap <Character,Integer> map = new HashMap<>();
        char arr[][] = new char[n][n];
        int index = 0;

          for (int i = 0; i < n; i++)
        {

            for (int j = 0; j < n; j++)
            {
              arr[i][j] = in.next().charAt(0);
            }
        }

        for (int i = 0; i < n; i++)
        {
          index = n - 1;
            for (int j = 0; j < n; j++)
            {
               if(i == j || j == index)
               {
                   map.put(arr[i][j], 1);
                   if(!(map.size() <= 2))
                   {
                       System.out.println("No");
                       return;
                   }

               }
               else
               {
                     map.put(arr[i][j], 1);
                      if(!(map.size() <= 2))
                   {
                       System.out.println("No");
                       return;
                   }
               }

            }
            --index;

        }
            if(map.size() == 2)
            {
              System.out.println("Yes");
            }
            else
            {
                System.out.println("No");
            }

    }

}


import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Problems {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
         Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        HashMap <Character,Integer> map = new HashMap<>();
        char arr[][] = new char[n][n];
        int index = 0;
        String s = "";
          for (int i = 0; i < n; i++)
        {

            s = in.next();
            for (int j = 0; j < n; j++)
            {
              arr[i][j] = s.charAt(j);
            }
        }

        for (int i = 0; i < n; i++)
        {
          index = n - 1;
            for (int j = 0; j < n; j++)
            {
               if(i == j || j == index)
               {
                   map.put(arr[i][j], 1);
                   if(!(map.size() <= 2))
                   {
                       System.out.println("NO");
                       return;
                   }

               }
               else
               {
                     map.put(arr[i][j], 1);
                      if(!(map.size() <= 2))
                   {
                       System.out.println("NO");
                       return;
                   }
               }

            }
            --index;

        }
            if(map.size() == 2)
            {
              System.out.println("YES");
            }
            else
            {
                System.out.println("NO");
            }

    }

}


import java.util.Scanner;

public class MyClass {
    public static void main(String[] args)throws java.lang.Exception{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean symetric = false;
        String[] arr = new String[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.next();
        }
        for (int i = 0; i <= n/2; i++) {
            if(i==n/2){
                if(arr[i].charAt(i) == arr[0].charAt(0)){

                    symetric = true;
                }
                else{
                    symetric = false;
                    break;
                }
            }
            else{
                if(arr[i].equals(arr[n-1-i])){
                    symetric = true;
                }
                else{
                    symetric = false;
                    break;
                }
            }
        }
        String s ="";
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(!s.contains(String.valueOf(arr[i].charAt(j)))){
                    s+=arr[i].charAt(j);
                }
            }
            if(s.length() != 2){
                symetric = false;
                break;
            }
        }
         if(symetric == true){
             System.out.println("YES");
         }
         else{
             System.out.println("NO");
         }
    }
}


import java.util.Scanner;

public class MyClass {
    public static void main(String[] args)throws java.lang.Exception{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean symetric = false;
        String[] arr = new String[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.next();
        }
        for (int i = 0; i <= n/2; i++) {
            if(i==n/2){
                for (int j = 0; j <= n/2; j++) {
                    if(i==j){
                        if(arr[i].charAt(j) == arr[0].charAt(0)){
                            symetric = true;
                        }
                         else{
                             symetric = false;
                             break;
                        }
                    }
                    else{
                        if(arr[i].charAt(j) == arr[i].charAt(n-j-1)){
                            symetric = true;
                        }
                        else{
                             symetric = false;
                             break;
                        }
                    }
                }
            }
            else{
                if(arr[i].equals(arr[n-1-i])){
                    symetric = true;
                }
                else{
                    symetric = false;
                    break;
                }
            }
        }
        String s ="";
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(!s.contains(String.valueOf(arr[i].charAt(j)))){
                    s+=arr[i].charAt(j);
                }
            }
            if(s.length() != 2){
                symetric = false;
                break;
            }
        }
         if(symetric == true){
             System.out.println("YES");
         }
         else{
             System.out.println("NO");
         }
    }
}


import java.util.Scanner;

public class MyClass {
    public static void main(String[] args)throws java.lang.Exception{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean symetric = false;
        String[] arr = new String[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.next();
        }
        for (int i = 0; i <= n/2; i++) {
            if(i==n/2){
                if(arr[i].charAt(i) == arr[0].charAt(0)){

                    symetric = true;
                }
                else{
                    symetric = false;
                    break;
                }
            }
            else{
                if(arr[i].equals(arr[n-1-i])){
                    symetric = true;
                }
                else{
                    symetric = false;
                    break;
                }
            }
        }
        String s ="";
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(!s.contains(String.valueOf(arr[i].charAt(j)))){
                    s+=arr[i].charAt(j);
                }
            }
        }
        if(s.length()>2 || s.length()==1){
        symetric = false;
        }
         if(symetric == true){
             System.out.println("YES");
         }
         else{
             System.out.println("NO");
         }
    }
}


import java.util.Scanner;

public class MyClass {
    public static void main(String[] args)throws java.lang.Exception{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean symetric = false;
        String[] arr = new String[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.next();
        }
        for (int i = 0; i <= n/2; i++) {
            if(i==n/2){
                for (int j = 0; j <= n/2; j++) {
                    if(i==j){
                        if(arr[i].charAt(j) == arr[0].charAt(0)){
                            symetric = true;
                        }
                         else{
                             symetric = false;
                             break;
                        }
                    }
                    else{
                        if(arr[i].charAt(j) == arr[i].charAt(n-j-1)){
                            symetric = true;
                        }
                        else{
                             symetric = false;
                             break;
                        }
                    }
                }
            }
            else{
                if(arr[i].equals(arr[n-1-i])){
                    symetric = true;
                }
                else{
                    symetric = false;
                    break;
                }
            }
        }
        String s ="";
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(!s.contains(String.valueOf(arr[i].charAt(j)))){
                    s+=arr[i].charAt(j);
                }
            }
        }
         if(symetric == true && s.length() == 2){
             System.out.println("YES");
         }
         else{
             System.out.println("NO");
         }
    }
}


import java.util.Scanner;

public class MyClass {
    public static void main(String[] args)throws java.lang.Exception{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean symetric = false;
        String[] arr = new String[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.next();
        }
        for (int i = 0; i <= n/2; i++) {
            if(i==n/2){
                if(arr[i].charAt(i) == arr[0].charAt(0)){

                    symetric = true;
                }
                else{
                    symetric = false;
                    break;
                }
            }
            else{
                if(arr[i].equals(arr[n-1-i])){
                    symetric = true;
                }
                else{
                    symetric = false;
                    break;
                }
            }
        }
        String s ="";
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(!s.contains(String.valueOf(arr[i].charAt(j)))){
                    s+=arr[i].charAt(j);
                }
            }
        }
        if(s.length()>2){
        symetric = false;
        }
         if(symetric == true){
             System.out.println("YES");
         }
         else{
             System.out.println("NO");
         }
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class JavaApplication1 {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        String [] arr = new String [n];

        input.nextLine();
        for(int i =0; i<n; i++)
            arr[i] = input.nextLine();

        String dig= "" ,nLine="";
        StringBuilder l=new StringBuilder();
        for(int i=0 , j=n-1; i<n && j>=0; i++ , j--){
               dig+= arr[i].charAt(i) +""+ arr[i].charAt(j);
               l= new StringBuilder(arr[i]+"");
               try{
                    l= l.deleteCharAt(i);
                    if(i < j)
                        l= l.deleteCharAt(j-1);
                    else if(i != j)
                        l= l.deleteCharAt(j);
               } catch(Exception e){}
               nLine+=l;
        }

        char [] a = dig.toCharArray();
        Arrays.sort(a);

        boolean flag = false;
        if(!dig.equals(String.valueOf(a)))
            flag=true;

        if(!flag){

                String diffDig = nLine , tt="";
                flag = false;

                tt = diffDig.substring(diffDig.length()/2, diffDig.length());
                tt += diffDig.substring(0, diffDig.length()/2);

                if(!diffDig.equals(tt) ||  diffDig.charAt(0) == dig.charAt(0) )
                     flag=true;

                if(!flag)
                    System.out.println("YES");
                else
                    System.out.println("NO");
            }
            else
                 System.out.println("NO");
        }

    }


import java.util.Scanner;

public class JavaApplication1 {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        String [] arr = new String [n];

        input.nextLine();
        for(int i =0; i<n; i++)
            arr[i] = input.nextLine();

        String dig="";
        for(int i=0 , j=n-1; i<n && j>=0; i++ , j--)
            dig+=arr[i].charAt(i) + arr[i].charAt(j);

        char cTest = dig.charAt(0);
        boolean flag = false;
        for(int i=0 ; i<n ; i++)
             if(dig.charAt(i) != cTest){
                 flag =true;
                 break;
             }

        if(!flag){

            String diffDig ="";
            for(int i=0 ; i<n ; i++)
                for(int y=0 ; y<arr[i].length() ; y++)
                     if(arr[i].charAt(y) != dig.charAt(0))
                        diffDig+= arr[i].charAt(y);

            if(diffDig.length() != 0){
                cTest = diffDig.charAt(0);
                flag = false;
                for(int i=0 ; i<diffDig.length() ; i++)
                     if(diffDig.charAt(i) != cTest){
                         flag =true;
                         break;
                     }

                if(!flag)
                    System.out.println("YES");
                else
                    System.out.println("NO");
            }
            else
                 System.out.println("NO");
        }
        else
             System.out.println("NO");

    }

}


import java.util.Arrays;
import java.util.Scanner;

public class JavaApplication1 {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        String [] arr = new String [n];

        input.nextLine();
        for(int i =0; i<n; i++)
            arr[i] = input.nextLine();

        String dig= "" ,nLine="";
        StringBuilder l=new StringBuilder();
        for(int i=0 , j=n-1; i<n && j>=0; i++ , j--){
               dig+= arr[i].charAt(i) +""+ arr[i].charAt(j);
               l= new StringBuilder(arr[i]+"");
               try{
                    l= l.deleteCharAt(i);
                    if(i < j)
                        l= l.deleteCharAt(j-1);
                    else if(i != j)
                        l= l.deleteCharAt(j);
               } catch(Exception e){}
               nLine+=l;
        }

        char [] a = dig.toCharArray();
        Arrays.sort(a);

        boolean flag = false;
        if(!dig.equals(String.valueOf(a)))
            flag=true;

        if(!flag){

                String diffDig = nLine , tt="";
                flag = false;
                a = diffDig.toCharArray();

                for(int i =a.length-1; i>=0; i--){
                    tt+=a[i];
                }

                if(!diffDig.equals(tt) ||  diffDig.charAt(0) == dig.charAt(0) )
                     flag=true;

                if(!flag)
                    System.out.println("YES");
                else
                    System.out.println("NO");
            }
            else
                 System.out.println("NO");
        }

    }


import java.util.Scanner;

public class JavaApplication1 {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        String [] arr = new String [n];

        input.nextLine();
        for(int i =0; i<n; i++)
            arr[i] = input.nextLine();

        String dig="";
        for(int i=0 , j=0; i<n && j< n; i++ , j++)
            dig+=arr[i].charAt(j);

        for(int i=0 , j=n-1; i<n && j>=0; i++ , j--)
            dig+=arr[i].charAt(j);

        char cTest = dig.charAt(0);
        boolean flag = false;
        for(int i=0 ; i<n ; i++)
             if(dig.charAt(i) != cTest)
                 flag =true;

        if(!flag){

            String diffDig ="";
            for(int i=0 ; i<n ; i++)
                for(int y=0 ; y<arr[i].length() ; y++)
                     if(arr[i].charAt(y) != dig.charAt(0))
                        diffDig+= arr[i].charAt(y);

            cTest = diffDig.charAt(0);
            flag = false;
            for(int i=0 ; i<diffDig.length() ; i++)
                 if(diffDig.charAt(i) != cTest)
                     flag =true;

            if(!flag)
                System.out.println("YES");
            else
                System.out.println("NO");
        }
        else
             System.out.println("NO");

    }

}