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