#include <bits/stdc++.h>
using namespace std;
int main() {
  bool ok = true;
  int n;
  cin >> n;
  char inp[n][n];
  set<char> t;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) {
      cin >> inp[i][j];
      t.insert(inp[i][j]);
    }
  if (t.size() != 2) ok = false;
  for (int i = 0; i < n; ++i)
    if (inp[i][i] != inp[0][0] or inp[i][n - i - 1] != inp[0][0]) ok = false;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (i != j and j != n - i - 1 and inp[i][j] == inp[0][0]) ok = false;
  if (ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
