#include <bits/stdc++.h>
using namespace std;
const int rx[] = {0, -1, 0, 1, -1, 1, 1, -1};
const int cy[] = {1, 0, -1, 0, 1, 1, -1, -1};
int main() {
  int n;
  vector<string> m;
  string s;
  scanf("%d", &n);
  vector<vector<int> > c(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++) {
    cin >> s;
    m.push_back(s);
  }
  char x, nx;
  x = m[0][0];
  for (int i = 0, j = 0; i < n; i++, j++) {
    if (m[i][j] != x) {
      cout << "NO" << endl;
      return 0;
    }
    c[i][j] = 1;
  }
  for (int i = 0, j = n - 1; i < n; i++, j--) {
    if (m[i][j] != x) {
      cout << "NO" << endl;
      return 0;
    }
    c[i][j] = 1;
  }
  nx = m[0][1];
  if (x == nx) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (!c[i][j] && m[i][j] != nx) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
