#include <bits/stdc++.h>
using namespace std;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename U>
using umap = unordered_map<T, U>;
template <typename T>
using uset = unordered_set<T>;
bool works() {
  int n;
  cin >> n;
  int a[n][n];
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < n; j++) a[i][j] = s[j] - '0';
  }
  set<pair<int, int>> fours;
  int fi, fj;
  fi = fj = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] == 4) {
        if (fi == -1) {
          fi = i;
          fj = j;
        }
        fours.insert({i, j});
      }
    }
  }
  if (fi == -1) {
    return false;
  }
  int db;
  for (db = fi; db < n && a[db][fj] == 4; db++)
    ;
  db--;
  int rb;
  for (rb = fj; rb < n && a[fi][rb] == 4; rb++)
    ;
  rb--;
  for (int i = fi; i <= db; i++)
    for (int j = fj; j <= rb; j++)
      if (a[i][j] != 4) {
        return false;
      } else {
        fours.erase({i, j});
      }
  if (!fours.empty()) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int val = 0;
      for (int ci = max(0, i - 1); ci <= min(n - 1, i + 1); ci++)
        for (int cj = max(0, j - 1); cj <= min(n - 1, j + 1); cj++)
          if (a[ci][cj] == 4) val = max(val, 3 - (abs(ci - i) + abs(cj - j)));
      if (a[i][j] != 4 && a[i][j] != val) {
        return false;
      }
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cout << (works() ? "Yes" : "No") << endl;
  return 0;
}
