#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  char paper[n][n];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> paper[i][j];
  char diag = paper[0][0];
  bool condition = true;
  for (int i = 0; i < n; i++)
    if (paper[i][i] != diag || paper[i][n - i - 1] != diag) {
      condition = false;
      break;
    }
  if (!condition) {
    cout << "NO";
    return 0;
  }
  char rest = paper[0][1];
  if (rest == diag) {
    cout << "NO";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j && i + j != n - 1) {
        if (paper[i][j] != rest) {
          condition = false;
        }
      }
    }
  }
  if (!condition)
    cout << "NO";
  else
    cout << "YES";
  return 0;
}
