#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j;
  int a[50 + 5][50 + 5];
  char s[100];
  while (scanf("%d", &n) != EOF) {
    for (i = 1; i <= n; i++) {
      scanf("%s", s + 1);
      for (j = 1; j <= n; j++) a[i][j] = s[j] - '0';
    }
    int flag = 1;
    int x, y;
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= n; j++) {
        int ans = 0;
        if (a[i][j] == 0) continue;
        if (i - 1 > 0 && j - 1 > 0) ans += a[i - 1][j - 1] == 0 ? 0 : 1;
        if (i - 1 > 0 && j + 1 <= n) ans += a[i - 1][j + 1] == 0 ? 0 : 1;
        if (i + 1 <= n && j - 1 > 0) ans += a[i + 1][j - 1] == 0 ? 0 : 1;
        if (i + 1 <= n && j + 1 <= n) ans += a[i + 1][j + 1] == 0 ? 0 : 1;
        if (ans != a[i][j]) {
          flag = 0;
          break;
        }
      }
    }
    if (flag)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
