#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n][n];
  char temp;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      cin >> temp;
      a[i][j] = (int)temp - 48;
    }
  int x1, y1, x2, y2;
  x1 = x2 = y1 = y2 = -1;
  for (int i = 0; i < n && x1 < 0; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] == 4) {
        x1 = i;
        y1 = j;
        while (j < n && a[i][j] == 4) j++;
        y2 = j - 1;
        j = y1;
        while (i < n && a[i][j] == 4) i++;
        x2 = i - 1;
        break;
      }
    }
  }
  if (x1 < 0)
    cout << "NO" << endl;
  else {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        if ((i == x1 - 1 || i == x2 + 1) && (j == y1 - 1 || j == y2 + 1)) {
          if (a[i][j] != 1) {
            cout << "NO" << endl;
            return 0;
          }
        } else if (i >= x1 && i <= x2 && j >= y1 && j <= y2) {
          if (a[i][j] != 4) {
            cout << "NO" << endl;
            return 0;
          }
        } else if (i >= x1 - 1 && i <= x2 + 1 && j >= y1 - 1 && j <= y2 + 1) {
          if (a[i][j] != 2) {
            cout << "NO" << endl;
            return 0;
          }
        } else {
          if (a[i][j] != 0) {
            cout << "NO" << endl;
            return 0;
          }
        }
      }
    cout << "YES" << endl;
  }
}
