#include <bits/stdc++.h>
using namespace std;
long long ar[100100], ar1[100010];
string s, ss;
char ch[305][305];
int main() {
  long long ar[105];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> ch[i][j];
    }
  }
  char c = ch[0][0];
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < n; j++) {
      if (i == j) {
        if (c != ch[i][j]) {
          cout << "NO" << endl;
          return 0;
        }
      }
    }
  }
  char cc;
  cc = ch[0][n - 1];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i + j == n - 1) {
        if (cc != ch[i][j]) {
          cout << "NO" << endl;
          return 0;
        }
      }
    }
  }
  char ccc;
  ccc = ch[0][1];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (ccc == ch[i][j] and ccc != c and ccc != cc) {
        cnt++;
      }
    }
  }
  if (n * n == (n + n - 1) + cnt)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
