#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> v(n);
  for (auto &e : v) cin >> e;
  int a = 0;
  for (int i = 0; i < n; i++, a++) {
    for (int j = 0; j < n; j++) {
      if (j == a or j == n - 1 - a) {
        if (v[i][j] != v[0][0]) {
          cout << "NO";
          return 0;
        }
      } else {
        if (v[i][j] != v[0][1] or v[i][j] == v[0][0]) {
          cout << "NO";
          return 0;
        }
      }
    }
  }
  cout << "YES";
  return 0;
}
