#include <bits/stdc++.h>
using namespace std;
char c[100];
int a[100][100];
int cx[] = {1, 1, -1, -1};
int cy[] = {-1, 1, 1, -1};
int main() {
  int n, flag = 1;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", c);
    for (int j = 0; j < n; j++) a[i][j] = c[j] - '0';
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] == 0) continue;
      int sum = 0;
      for (int k = 0; k < 4; k++) {
        int xx = i + cx[k], yy = j + cy[k];
        if (xx < 0 || yy < 0 || xx >= n || yy >= n) continue;
        if (a[xx][yy]) sum++;
      }
      if (sum != a[i][j]) flag = 0;
    }
  }
  if (flag)
    cout << "Yes" << '\n';
  else
    cout << "No" << '\n';
  return 0;
}
