#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  char mat[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> mat[i][j];
    }
  }
  char a = mat[0][0];
  char b = mat[0][1];
  if (a == b) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if ((i == j || i == (n - j - 1)) && mat[i][j] != a) {
        cout << "NO" << endl;
        return 0;
      } else if ((!(i == j || i == (n - j - 1)) && mat[i][j] != b)) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
}
