#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<vector<char> > x(n, vector<char>(n));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> x[i][j];
  char tmp = x[0][0];
  char tmp1 = x[0][1];
  bool ok = true;
  if (tmp == tmp1) {
    cout << "NO";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j || i == n - j - 1) {
        if (x[i][j] != tmp) ok = false;
      } else if (x[i][j] != tmp1)
        ok = false;
    }
  }
  if (ok)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
