#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  char a[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  int j = 0;
  char c = a[0][1];
  char temp = a[0][0];
  if (c == temp) {
    cout << "NO";
    return 0;
  }
  for (int k = 0; k < n; k++) {
    if (a[k][j] == a[k][n - j - 1] && a[k][j] == temp) {
      a[k][j] = '0';
      a[k][n - 1 - j] = '0';
    } else {
      cout << "NO";
      return 0;
    }
    j++;
  }
  for (int i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (a[i][j] != c && a[i][j] != '0') {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
  return 0;
}
