#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  char a[310][310];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
    }
  }
  char s1, s2;
  s1 = a[1][1];
  s2 = a[1][2];
  int flag = 1;
  if (s1 == s2)
    flag = 0;
  else {
    for (int i = 1; i <= n; i++) {
      if (a[i][i] != s1 || s1 != a[i][n - i + 1]) flag = 0;
      a[i][i] = a[i][n - i + 1] = s2;
      for (int j = 1; j <= n; j++) {
        if (a[i][j] != s2) flag = 0;
      }
    }
  }
  if (flag)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
