#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int j = 2;
  char x, c, z;
  cin >> x;
  cin >> z;
  bool yes = 1;
  int left = 0;
  int right = n - 1;
  for (int i = 0; i < n; i++) {
    for (; j < n; j++) {
      cin >> c;
      if (j == left) {
        if (c != x) yes = 0;
      } else if (j == right) {
        if (c != x) yes = 0;
      } else if (c != z || c == x) {
        yes = 0;
      }
    }
    left++;
    right--;
    j = 0;
  }
  if (yes) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  cin >> n;
}
