#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e3, mod = 1e9 + 7;
int n, a[N + 7][N + 7];
pair<int, int> operator+(const pair<int, int> p, const int q) {
  if (q == 2) return make_pair(p.first + 1, p.second);
  if (q == 3) return make_pair(p.first, p.second + 1);
  return make_pair(p.first, p.second);
}
pair<int, int> operator-(const pair<int, int> p, const int q) {
  if (q == 2) return make_pair(p.first - 1, p.second);
  if (q == 3) return make_pair(p.first, p.second - 1);
  return make_pair(p.first, p.second);
}
pair<int, int> operator+(const pair<int, int> p, const pair<int, int> q) {
  return make_pair(p.first + q.first, p.second + q.second);
}
pair<int, int> operator-(const pair<int, int> p, const pair<int, int> q) {
  return make_pair(p.first - q.first, p.second - q.second);
}
int operator<(const pair<int, int> p, const pair<int, int> q) {
  if (p.first < q.first && p.second < q.second) return 1;
  if (p.first > q.first && p.second > q.second) return 0;
  return 1. * (p.first - q.first) < log2(3) * (q.second - p.second);
}
int Pow(int a, int first) {
  if (a == 0) return 0;
  int res = 1;
  for (; first; a = 1ll * a * a % mod, first >>= 1)
    if (first & 1) res = 1ll * res * a % mod;
  return res;
}
int get(const pair<int, int> p) {
  return 1ll * Pow(2, p.first) * Pow(3, p.second) % mod;
}
pair<int, int> sh[N + 7][N + 7], sl[N + 7][N + 7];
int ph[N + 7][N + 7], bh[N + 7][N + 7];
int pl[N + 7][N + 7], bl[N + 7][N + 7];
pair<int, int> sp[N + 7][N + 7], sn[N + 7][N + 7];
int pp[N + 7][N + 7], bp[N + 7][N + 7];
int pn[N + 7][N + 7], bn[N + 7][N + 7];
int main() {
  scanf("%d", &n);
  char c;
  int ok = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      while (!isdigit(c = getchar()))
        ;
      ok |= (a[i][j] = c - '0');
    }
  if (!ok) return puts("0"), 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) sh[i][j] = sh[i][j - 1] + a[i][j];
    for (int j = 0; j <= n; j++)
      if (a[i][j])
        ph[i][j] = ph[i][j - 1];
      else
        ph[i][j] = j;
    for (int j = n + 1; j >= 1; j--)
      if (a[i][j])
        bh[i][j] = bh[i][j + 1];
      else
        bh[i][j] = j;
  }
  for (int j = 1; j <= n; j++) {
    for (int i = 1; i <= n; i++) sl[i][j] = sl[i - 1][j] + a[i][j];
    for (int i = 0; i <= n; i++)
      if (a[i][j])
        pl[i][j] = pl[i - 1][j];
      else
        pl[i][j] = i;
    for (int i = n + 1; i >= 1; i--)
      if (a[i][j])
        bl[i][j] = bl[i + 1][j];
      else
        bl[i][j] = i;
  }
  for (int s = 2; s <= n * 2; s++) {
    for (int i = max(1, s - n); i <= min(n, s - 1); i++) {
      int j = s - i;
      sp[i][j] = sp[i - 1][j + 1] + a[i][j];
    }
    for (int i = max(1, s - n) - 1; i <= min(n, s - 1); i++) {
      int j = s - i;
      if (a[i][j])
        pp[i][j] = pp[i - 1][j + 1];
      else
        pp[i][j] = i;
    }
    for (int i = min(n, s - 1) + 1; i >= max(1, s - n); i--) {
      int j = s - i;
      if (a[i][j])
        bp[i][j] = bp[i + 1][j - 1];
      else
        bp[i][j] = i;
    }
  }
  for (int c = -n + 1; c <= n - 1; c++) {
    for (int i = max(1, c + 1); i <= min(n, c + n); i++) {
      int j = i - c;
      sn[i][j] = sn[i - 1][j - 1] + a[i][j];
    }
    for (int i = max(1, c + 1) - 1; i <= min(n, c + n); i++) {
      int j = i - c;
      if (a[i][j])
        pn[i][j] = pn[i - 1][j - 1];
      else
        pn[i][j] = i;
    }
    for (int i = min(n, c + n) + 1; i >= max(1, c + 1); i--) {
      int j = i - c;
      if (a[i][j])
        bn[i][j] = bn[i + 1][j + 1];
      else
        bn[i][j] = i;
    }
  }
  pair<int, int> ans(0, 0);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (a[i][j]) {
        pair<int, int> now(0, 0);
        int len = min(min(j - ph[i][j], bh[i][j] - j),
                      min(i - pl[i][j], bl[i][j] - i));
        now = now + sh[i][j + len - 1] - sh[i][j - len];
        now = now + sl[i + len - 1][j] - sl[i - len][j];
        now = now - a[i][j];
        if (ans < now) ans = now;
      }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (a[i][j]) {
        pair<int, int> now(0, 0);
        int len = min(min(i - pp[i][j], bp[i][j] - i),
                      min(i - pn[i][j], bn[i][j] - i));
        now = now + sp[i + len - 1][j - len + 1] - sp[i - len][j + len];
        now = now + sn[i + len - 1][j + len - 1] - sn[i - len][j - len];
        now = now - a[i][j];
        if (ans < now) ans = now;
      }
  printf("%d\n", get(ans));
  return 0;
}
