#include <bits/stdc++.h>
using namespace std;
void no() {
  cout << "NO";
  exit(0);
}
int main() {
  int n;
  cin >> n;
  vector<vector<char> > v(n, vector<char>(n));
  for (auto& second : v) {
    for (auto& first : second) cin >> first;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j || (i + j) == n - 1) {
        if (v[i][j] != v[0][0]) no();
      } else if (v[i][j] != v[0][1])
        no();
    }
  }
  if (v[0][0] == v[0][1]) no();
  cout << "YES";
}
