#include <bits/stdc++.h>
using namespace std;
int main() {
  char m[1000][1000];
  int s, f = 1;
  char a, b;
  cin >> s;
  for (int r = 0; r < s; r++) {
    for (int c = 0; c < s; c++) {
      cin >> m[r][c];
    }
  }
  a = m[0][0];
  b = m[0][1];
  if (a == b)
    f = 0;
  else {
    for (int r = 0; r < s && f != 0; r++) {
      for (int c = 0; c < s && f != 0; c++) {
        if (r == c || c == s - r - 1) {
          if (m[r][c] != a) f = 0;
        } else {
          if (m[r][c] != b) f = 0;
        }
      }
    }
  }
  if (f == 1)
    cout << "YES";
  else
    cout << "NO";
}
