#include <bits/stdc++.h>
int main() {
  char a[303], b, c;
  int n, m, i, j;
  scanf("%d %s", &n, &a[1]);
  b = a[1], c = a[2];
  if (b == c) return 0 * printf("NO");
  i = 1;
  goto h;
  for (; i <= n; i++) {
    scanf("%s", &a[1]);
  h:
    m = n - i + 1;
    for (j = 1; j <= n; j++) {
      if (j == i || j == m) {
        if (a[j] != b) return 0 * printf("NO");
      } else {
        if (a[j] != c) return 0 * printf("NO");
      }
    }
  }
  printf("YES");
}
