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