#include <bits/stdc++.h>
using namespace std;
const int p = (1e9) + 7;
const int N = 1000 + 5;
struct Node {
  int x, y;
  Node operator+(Node t) { return (Node){x + t.x, y + t.y}; }
  Node operator-(Node t) { return (Node){x - t.x, y - t.y}; }
  Node operator/(Node t) { return (Node){x - t.x, y - t.y}; }
  Node operator*(int t) { return (Node){x * t, y * t}; }
  bool operator>=(Node t) {
    if (x >= t.x && y >= t.y) return true;
    if (x <= t.x && y <= t.y) return false;
    if (x > t.x) {
      int a = x - t.x, b = t.y - y;
      return log(2) * a > log(3) * b;
    } else {
      int a = y - t.y, b = t.x - x;
      return log(3) * a > log(2) * b;
    }
  }
  void print() { printf("%d %d\n", x, y); }
} sr[N][N], sc[N][N], sm[N][N], sa[N][N], a[N][N];
int l[N][N], r[N][N], u[N][N], d[N][N], lu[N][N], ld[N][N], ru[N][N], rd[N][N];
char s[N][N];
long long qmul(long long a, long long b) {
  long long ans = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1) ans = ans * a % p;
  return ans;
}
int n, m;
bool check() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (s[i][j] != '0') return true;
  return false;
}
int main() {
  scanf("%d", &n);
  m = n;
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  if (!check()) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      a[i][j].x += s[i][j] == '2';
      a[i][j].y += s[i][j] == '3';
      if (s[i][j] != '0')
        l[i][j] = l[i][j - 1] + 1, u[i][j] = u[i - 1][j] + 1,
        lu[i][j] = lu[i - 1][j - 1] + 1, ru[i][j] = ru[i - 1][j + 1] + 1;
      sr[i][j] = sr[i][j - 1] + a[i][j];
      sc[i][j] = sc[i - 1][j] + a[i][j];
      sm[i][j] = sm[i - 1][j - 1] + a[i][j];
      sa[i][j] = sa[i - 1][j + 1] + a[i][j];
    }
    for (int j = m; j >= 1; j--)
      if (s[i][j] != '0') r[i][j] = r[i][j + 1] + 1;
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= m; j++)
      if (s[i][j] != '0')
        d[i][j] = d[i + 1][j] + 1, ld[i][j] = ld[i + 1][j - 1] + 1,
        rd[i][j] = rd[i + 1][j + 1] + 1;
  }
  Node ans = (Node){0, 0};
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (s[i][j] != '0') {
        int t;
        Node tmp;
        t = min(min(l[i][j], r[i][j]), min(u[i][j], d[i][j]));
        tmp = sr[i][j + t - 1] - sr[i][j - t] + sc[i + t - 1][j] -
              sc[i - t][j] - a[i][j];
        if (tmp >= ans) ans = tmp;
        t = min(min(lu[i][j], ld[i][j]), min(ru[i][j], rd[i][j]));
        tmp = sm[i + t - 1][j + t - 1] - sm[i - t][j - t] +
              sa[i + t - 1][j - t + 1] - sa[i - t][j + t] - a[i][j];
        if (tmp >= ans) ans = tmp;
      }
  printf("%I64d\n", qmul(2, ans.x) * qmul(3, ans.y) % p);
  return 0;
}
