#include <bits/stdc++.h>
using namespace std;
int n, i, j, k, p;
string s, c;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s;
    if (i <= n / 2)
      p = i;
    else
      p = n - i - 1;
    if (k == 0) {
      c[0] = s[0];
      c[1] = s[1];
      if (c[0] == c[1]) {
        cout << "NO";
        return 0;
      }
      k = 1;
    }
    if (s[i] != c[0] || s[n - i - 1] != c[0]) {
      cout << "NO";
      return 0;
    }
    for (j = 0; j < p; j++) {
      if (s[j] != c[1]) {
        cout << "NO";
        return 0;
      }
    }
    for (j = p + 1; j < n - p - 1; j++) {
      if (s[j] != c[1]) {
        cout << "NO";
        return 0;
      }
    }
    for (j = n - p; j < n; j++) {
      if (s[j] != c[1]) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
}
