#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  vector<string> a(n);
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  unordered_set<char> diagonal, non_diagonal;
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < n; ++j) {
      if (i == j) {
        diagonal.insert(a[i][j]);
      } else if (j == n - i - 1) {
        diagonal.insert(a[i][j]);
      } else {
        non_diagonal.insert(a[i][j]);
      }
    }
  }
  if (diagonal.size() == 1 && non_diagonal.size() == 1) {
    for (char a : diagonal) {
      for (char b : non_diagonal) {
        if (a != b) {
          cout << "YES";
        } else {
          cout << "NO";
        }
      }
    }
  } else {
    cout << "NO";
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
}
