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