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