#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  char arr[n][n];
  bool flag = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> arr[i][j];
    }
  }
  char first = arr[0][0];
  char second = arr[0][1];
  if (first == second) 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] != first) {
          flag = 1;
          break;
        }
      } else {
        if (arr[i][j] != second) {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 1) break;
  }
  if (flag == 1)
    cout << "NO";
  else
    cout << "YES";
}
