#include <bits/stdc++.h>
using namespace std;
const int maxn = 500;
char mat[maxn][maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < (n); i++) scanf("%s", mat[i]);
  char a = mat[0][0], b = mat[0][1];
  int ok = 1;
  if (a == b) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++)
      if (i == j || j + i == n - 1) {
        if (mat[i][j] != a) {
          ok = 0;
          break;
        }
      } else if (mat[i][j] != b) {
        ok = 0;
        break;
      }
  if (ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
