#include <bits/stdc++.h>
using namespace std;
char m[60][60];
int cnt[10];
bool judge(int n) {
  int i, j;
  if (cnt[4] == 0) {
    bool z = 1;
    for (i = 0; i < 10; i++)
      if (cnt[i] != 0) z = 0;
    if (z == 1)
      return true;
    else
      return false;
  } else {
    vector<int> x;
    vector<int> y;
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
        if (m[i][j] == '4') {
          x.push_back(i);
          y.push_back(j);
        }
      }
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    int x1 = x[0], x2 = x.back();
    int y1 = y[0], y2 = y.back();
    if (cnt[4] != (x2 - x1 + 1) * (y2 - y1 + 1)) return false;
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
        if (i <= x2 && i >= x1 && j <= y2 && j >= y1) {
          if (m[i][j] != '4') return false;
        } else if (i <= x2 && i >= x1 && j - y1 == -1) {
          if (m[i][j] != '2') return false;
        } else if (i <= x2 && i >= x1 && j - y2 == 1) {
          if (m[i][j] != '2') return false;
        } else if (j <= y2 && j >= y1 && i - x1 == -1) {
          if (m[i][j] != '2') return false;
        } else if (j <= y2 && j >= y1 && i - x2 == 1) {
          if (m[i][j] != '2') return false;
        } else if (i == x1 - 1 && j == y1 - 1) {
          if (m[i][j] != '1') return false;
        } else if (i == x1 - 1 && j == y2 + 1) {
          if (m[i][j] != '1') return false;
        } else if (i == x2 + 1 && j == y1 - 1) {
          if (m[i][j] != '1') return false;
        } else if (i == x2 + 1 && j == y2 + 1) {
          if (m[i][j] != '1') return false;
        } else if (m[i][j] != '0')
          return false;
      }
    }
    return true;
  }
  return false;
}
int main() {
  int n;
  scanf("%d", &n);
  int i, j;
  for (i = 0; i < n; i++) {
    scanf("%s", m[i]);
  }
  memset(cnt, 0, sizeof(cnt));
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      cnt[m[i][j] - '0']++;
    }
  }
  bool ans = judge(n);
  if (ans)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
