#include <bits/stdc++.h>
using namespace std;
int main() {
  set<char> mySet;
  int n;
  cin >> n;
  char dig[n][n];
  char x;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> dig[i][j];
      if (i == 0 && j == 1) x = dig[i][j];
      if (j != i && j != (n - i - 1)) {
        if (dig[i][j] != x) {
          cout << "NO" << endl;
          return 0;
        }
      }
      mySet.insert(dig[i][j]);
    }
  }
  if (mySet.size() != 2) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 0; i < n - 1; i++) {
    if (dig[i][i] != dig[i + 1][i + 1]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  for (int i = 0, j = n - 1; i<n - 1, j> 0; i++, j--) {
    if (dig[i][j] != dig[i + 1][j - 1]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
