#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[1005][1005];
bool check(int i, int j) {
  if (i < 0 || i >= n || j < 0 || j >= n) return 1;
  if (a[i][j] == '1') {
    a[i][j] = '2';
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  bool ok = 0;
  int stx, sty;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n && !ok; j++) {
      if (a[i][j] == '4') {
        ok = 1;
        stx = i, sty = j;
      }
    }
  if (!ok) {
    cout << "NO\n";
    return 0;
  }
  int row = 1, col = 1;
  for (int i = sty + 1; i < n; i++) {
    if (a[stx][i] != '4') break;
    row++;
  }
  for (int i = stx + 1; i < n; i++) {
    if (a[i][sty] != '4') break;
    col++;
  }
  int tot = row * col;
  for (int i = stx; i < col + stx; i++) {
    for (int j = sty; j < row + sty; j++) {
      if (a[i][j] != '4') {
        cout << "NO\n";
        return 0;
      }
      a[i][j] = '2';
    }
  }
  if (!check(stx - 1, sty - 1) || !check(stx + col, sty - 1) ||
      !check(stx - 1, sty + row) || !check(stx + col, sty + row)) {
    cout << "NO\n";
    return 0;
  }
  if (stx - 1 >= 0) stx--, col++;
  if (sty - 1 >= 0) sty--, row++;
  col += 1, row += 1;
  for (int i = stx; i < stx + col && i < n; i++)
    for (int j = sty; j < sty + row && j < n; j++) {
      if (a[i][j] != '2') {
        cout << "NO\n";
        return 0;
      }
      a[i][j] = '0';
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      if (a[i][j] != '0') {
        cout << "NO\n";
        return 0;
      }
    }
  cout << "YES\n";
  return 0;
}
