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