#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, f = 0;
  cin >> n;
  char a[n][n], b;
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) cin >> a[i][j];
  for (i = 0; i < n; i++) {
    if (f == 1) break;
    for (j = 0; j < n; j++) {
      if (i == j) {
        if (i > 0) {
          if (a[i][j] != a[i - 1][j - 1]) {
            cout << "NO";
            f = 1;
            break;
          }
        }
        if (i == n / 2) {
          if (a[i][j] != a[i + 1][j - 1]) {
            cout << "NO";
            f = 1;
            break;
          }
        }
      } else if (i + j == n - 1) {
        if (i + 1 < n) {
          if (a[i][j] != a[i + 1][j - 1]) {
            cout << "NO";
            f = 1;
            break;
          }
        }
      } else {
        if (i == 0 && j == 1) {
          b = a[i][j];
          if (b == a[0][0]) {
            cout << "NO";
            f = 1;
            break;
          }
        } else {
          if (a[i][j] != b) {
            cout << "NO";
            f = 1;
            break;
          }
        }
      }
    }
  }
  if (f == 0) cout << "YES";
  return 0;
}
