#include <bits/stdc++.h>
using namespace std;
char line[600];
int n;
bool isdiag(int i, int j) { return (i == j || n - i - 1 == j); }
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  char diag, other;
  bool is = 1;
  for (int i = 0; i < n; i++) {
    cin >> line;
    if (i == 0) diag = line[0], other = line[1];
    if (diag == other) is = 0;
    for (int j = (i == 0) ? 2 : 0; j < n; j++) {
      bool id = isdiag(i, j);
      if (id && line[j] != diag)
        is = 0;
      else if (!id && line[j] != other)
        is = 0;
    }
  }
  if (is)
    cout << "YES\n";
  else
    cout << "NO\n";
}
