#include <bits/stdc++.h>
using namespace std;
int main() {
  int size;
  cin >> size;
  string* arr = new string[size];
  for (int x = 0; x < size; x++) {
    cin >> arr[x];
  }
  char check1 = arr[0][0], check2 = arr[0][1];
  bool one = false, two = false;
  for (int x = 0; x < size; x++) {
    for (int y = 0; y < size; y++) {
      if (x == y || y + x + 1 == size) {
        if (arr[x][y] != check1) one = true;
      } else {
        if (arr[x][y] != check2 || arr[x][y] == check1) two = true;
      }
    }
  }
  if (one == false && two == false)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
