#include <bits/stdc++.h>
using namespace std;
const double lg2 = log(2);
const double lg3 = log(3);
const int N = 2009, mod = 1e9 + 7;
int n, ansx, ansy;
int c2[N][N], r2[N][N];
int c3[N][N], r3[N][N];
vector<int> c0[N], r0[N];
char st[N][N], str[N][N];
bool mk[N][N];
void solve(int n) {
  for (int i = 1; i <= (n); i++) r0[i].clear(), c0[i].clear();
  memset(c2, 0, sizeof(c2));
  memset(r2, 0, sizeof(r2));
  memset(c3, 0, sizeof(c3));
  memset(r3, 0, sizeof(r3));
  for (int i = 1; i <= (n); i++) r0[i].push_back(0), c0[i].push_back(0);
  for (int i = 1; i <= (n); i++)
    for (int j = 1; j <= (n); j++) {
      if (st[i][j] == '0') r0[i].push_back(j), c0[j].push_back(i);
      r2[i][j] = r2[i][j - 1] + (st[i][j] == '2');
      r3[i][j] = r3[i][j - 1] + (st[i][j] == '3');
      c2[i][j] = c2[i - 1][j] + (st[i][j] == '2');
      c3[i][j] = c3[i - 1][j] + (st[i][j] == '3');
    }
  for (int i = 1; i <= (n); i++) r0[i].push_back(n + 1), c0[i].push_back(n + 1);
  int xx = 0, yy = 0;
  for (int i = 1; i <= (n); i++)
    for (int j = 1; j <= (n); j++) {
      if (mk[i][j]) continue;
      if (st[i][j] == '0') continue;
      vector<int>::iterator ll, rr, uu, dd;
      rr = upper_bound(r0[i].begin(), r0[i].end(), j);
      ll = rr;
      ll--;
      dd = upper_bound(c0[j].begin(), c0[j].end(), i);
      uu = dd;
      uu--;
      int ri = min(min(*rr - j, j - *ll), min(i - *uu, *dd - i));
      int cnt2 =
          r2[i][j + ri - 1] - r2[i][j - ri] + c2[i + ri - 1][j] - c2[i - ri][j];
      int cnt3 =
          r3[i][j + ri - 1] - r3[i][j - ri] + c3[i + ri - 1][j] - c3[i - ri][j];
      if (st[i][j] == '2') cnt2--;
      if (st[i][j] == '3') cnt3--;
      if (cnt2 * lg2 + cnt3 * lg3 > xx * lg2 + yy * lg3) xx = cnt2, yy = cnt3;
    }
  if (xx * lg2 + yy * lg3 > ansx * lg2 + ansy * lg3) ansx = xx, ansy = yy;
}
void rotate() {
  for (int i = 1; i <= (n); i++)
    for (int j = 1; j <= (n); j++) str[i][j] = st[i][j];
  for (int i = 1; i <= (2 * n - 1); i++)
    for (int j = 1; j <= (2 * n - 1); j++) st[i][j] = '0';
  for (double i = 1.5; i < n; i++)
    for (double j = 1.5; j < n; j++) {
      int x = i + j - 1, y = j - i + n;
      st[x][y] = '1';
      mk[x][y] = true;
    }
  for (int i = 1; i <= (n); i++)
    for (int j = 1; j <= (n); j++) st[i + j - 1][j - i + n] = str[i][j];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= (n); i++) scanf("%s", st[i] + 1);
  memset(mk, false, sizeof(mk));
  solve(n);
  rotate();
  solve(2 * n - 1);
  int ans = 0;
  for (int i = 1; i <= (n); i++)
    for (int j = 1; j <= (n); j++)
      if (str[i][j] != '0') ans = 1;
  for (int i = 1; i <= (ansx); i++) ans = ans * 2 % mod;
  for (int i = 1; i <= (ansy); i++) ans = (long long)ans * 3 % mod;
  printf("%d\n", ans);
  return 0;
}
