#include <bits/stdc++.h>
using namespace std;
int a[1000][1000];
int main() {
  int n;
  cin >> n;
  char c;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> c;
      a[i][j] = c - 'a';
    }
  }
  int x = a[1][1];
  for (int i = 1; i <= n; i++) {
    if (a[i][i] != x) {
      printf("NO");
      return 0;
    } else
      a[i][i] = -1;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i][n - i + 1] != x && a[i][n - i + 1] != -1) {
      printf("NO");
      return 0;
    } else
      a[i][n - i + 1] = -1;
  }
  if (a[1][2] == x) {
    printf("NO");
    return 0;
  } else
    x = a[1][2];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] != x && a[i][j] != -1) {
        printf("NO");
        return 0;
      } else
        a[i][j] = -1;
    }
  }
  printf("YES");
  return 0;
}
