#include <bits/stdc++.h>
using namespace std;
const int nmax = 2000 + 100;
const long long mod = 1e9 + 7;
int n;
int a[nmax + 1][nmax + 1], b[nmax + 1][nmax + 1];
int zl[nmax + 1][nmax + 1];
int zc[nmax + 1][nmax + 1];
double s[nmax + 1][nmax + 1];
void solve() {
  memset(zl, 0, sizeof(zl));
  memset(zc, 0, sizeof(zc));
  memset(s, 0, sizeof(s));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      double x;
      if (a[i][j] == 0) {
        x = 0;
        zl[i][j] = zc[i][j] = 1;
      } else {
        x = log(a[i][j]);
      }
      s[i][j] = x;
    }
  }
}
inline double suma(int x, int y, int z, int t) {
  return s[z][t] - s[x - 1][t] - s[z][y - 1] + s[x - 1][y - 1];
}
int main() {
  bool zero = 1;
  fscanf(stdin, "%d", &n);
  char c = fgetc(stdin);
  for (int i = 1; i <= n; ++i) {
    while (c < '0' || c > '3') {
      c = fgetc(stdin);
    }
    for (int j = 1; j <= n; ++j) {
      a[i][j] = c - '0';
      c = fgetc(stdin);
      if (a[i][j] != 0) zero = 0;
      b[i][j] = a[i][j];
    }
  }
  if (zero == 1) {
    fprintf(stdout, "0\n");
    return 0;
  }
  solve();
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      s[i][j] = s[i][j - 1] + s[i - 1][j] + s[i][j] - s[i - 1][j - 1];
      zl[i][j] += zl[i][j - 1];
      zc[i][j] += zc[i - 1][j];
    }
  }
  int n2;
  for (n2 = 1; (n2 << 1) <= n; n2 <<= 1) {
  }
  double expmax = -2;
  int ansx, ansy, lg;
  long long ansmod;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (a[i][j] == 0) continue;
      int ans = 0;
      for (int step = n2; step > 0; step >>= 1) {
        int x = ans + step;
        if (i + x <= n && i - x > 0 && j + x <= n && j - x > 0)
          if (zc[i + x][j] - zc[i - x - 1][j] == 0 &&
              zl[i][j + x] - zl[i][j - x - 1] == 0) {
            ans += step;
          }
      }
      double ee = suma(i - ans, j, i + ans, j) + suma(i, j - ans, i, j + ans) -
                  suma(i, j, i, j);
      if (ee > expmax) {
        expmax = ee;
        ansx = i, ansy = j;
        lg = ans;
      }
    }
  }
  long long poate = a[ansx][ansy];
  for (int i = 1; i <= lg; ++i) {
    if (ansy - i > 0) poate = (poate * a[ansx][ansy - i]) % mod;
    if (ansy + i <= n) poate = (poate * a[ansx][ansy + i]) % mod;
    if (ansx - i > 0) poate = (poate * a[ansx - i][ansy]) % mod;
    if (ansx + i <= n) poate = (poate * a[ansx + i][ansy]) % mod;
  }
  ansmod = poate;
  memset(a, 0, sizeof(a));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      a[i - j + n][i + j] = b[i][j];
    }
  }
  n = n * 2;
  solve();
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      s[i][j] = s[i][j - 1] + s[i - 1][j] + s[i][j] - s[i - 1][j - 1];
      zl[i][j] += zl[i][j - 1];
      zc[i][j] += zc[i - 1][j];
    }
  }
  for (n2 = 1; (n2 << 1) <= n; n2 <<= 1) {
  }
  bool gata = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (a[i][j] == 0) continue;
      int ans = 0;
      for (int step = n2; step > 0; step >>= 1) {
        int x = ans + step;
        if (i + x <= n && i - x > 0 && j + x <= n && j - x > 0)
          if (zc[i + x][j] - zc[i - x - 1][j] == x &&
              zl[i][j + x] - zl[i][j - x - 1] == x) {
            ans += step;
          }
      }
      double ee = suma(i - ans, j, i + ans, j) + suma(i, j - ans, i, j + ans) -
                  suma(i, j, i, j);
      if (ee > expmax) {
        expmax = ee;
        ansx = i, ansy = j;
        lg = ans;
        gata = 0;
      }
    }
  }
  if (gata == 0) {
    poate = a[ansx][ansy];
    for (int i = 2; i <= lg; i += 2) {
      if (ansy - i > 0) poate = (poate * a[ansx][ansy - i]) % mod;
      if (ansy + i <= n) poate = (poate * a[ansx][ansy + i]) % mod;
      if (ansx - i > 0) poate = (poate * a[ansx - i][ansy]) % mod;
      if (ansx + i <= n) poate = (poate * a[ansx + i][ansy]) % mod;
    }
    ansmod = poate;
  }
  fprintf(stdout, "%I64d\n", ansmod);
  return 0;
}
