#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  char a[n][n];
  for (long long int i = 0; i < n; i++)
    for (long long int j = 0; j < n; j++) cin >> a[i][j];
  long long int f = 0, p = n - 1;
  char c = a[0][0];
  char t = a[0][1];
  if (t != c) {
    for (long long int i = 1; i < n; i++)
      if (a[i][i] != c) f = 1;
    for (long long int i = 0; i < n; i++) {
      if (a[i][abs(p - i)] != c) f = 1;
    }
    if (f == 0) {
      for (long long int i = 0; i < n; i++) {
        for (long long int j = 0; j < n; j++) {
          if (i == j || (j == abs(p - i)))
            continue;
          else {
            if (a[i][j] != t) f = 1;
          }
        }
      }
      cout << ((f == 0) ? "YES" : "NO");
    } else
      cout << "NO";
  } else
    cout << "NO";
}
