#include <bits/stdc++.h>
using namespace std;
const int N = 100007, M = 5007;
int i, j, k, l, n, m, p;
char a[M][M];
bool f[M][M];
int main() {
  cin >> n;
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  char tar = a[0][0];
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) {
      if (abs(i) == abs(j) || abs(n - j - 1) == abs(i) ||
          abs(n - i - 1) == abs(j)) {
        if (a[i][j] != tar) {
          cout << "NO" << endl;
          return 0;
        }
        f[i][j] = true;
      }
    }
  if (tar == a[1][0]) {
    cout << "NO" << endl;
    return 0;
  }
  tar = a[1][0];
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (!f[i][j]) {
        if (a[i][j] != tar) {
          cout << "NO" << endl;
          return 0;
        }
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
