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