#include <bits/stdc++.h>
using namespace std;
char s[1000 + 5][1000 + 5];
int a[1000 + 5][1000 + 5];
int a2, a3;
bool mark;
int pre[4][1000 + 5][1000 + 5];
int cnt2[2][1000 + 5][1000 + 5], cnt3[2][1000 + 5][1000 + 5];
void solve(int n) {
  for (int i = 1; i <= n; i++) pre[0][i][0] = 0;
  for (int i = 1; i <= n; i++) pre[1][i][n + 1] = n + 1;
  for (int i = 1; i <= n; i++) pre[2][0][i] = 0;
  for (int i = 1; i <= n; i++) pre[3][n + 1][i] = n + 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      pre[0][i][j] = a[i][j] == 0 ? j : pre[0][i][j - 1];
  for (int i = 1; i <= n; i++)
    for (int j = n; j >= 1; j--)
      pre[1][i][j] = a[i][j] == 0 ? j : pre[1][i][j + 1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      pre[2][i][j] = a[i][j] == 0 ? i : pre[2][i - 1][j];
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= n; j++)
      pre[3][i][j] = a[i][j] == 0 ? i : pre[3][i + 1][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      cnt2[0][i][j] = cnt2[0][i][j - 1] + (a[i][j] == 2);
      cnt2[1][i][j] = cnt2[1][i - 1][j] + (a[i][j] == 2);
      cnt3[0][i][j] = cnt3[0][i][j - 1] + (a[i][j] == 3);
      cnt3[1][i][j] = cnt3[1][i - 1][j] + (a[i][j] == 3);
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (a[i][j]) {
        int len = 0x3f3f3f3f;
        len = min(len, j - pre[0][i][j]);
        len = min(len, pre[1][i][j] - j);
        len = min(len, i - pre[2][i][j]);
        len = min(len, pre[3][i][j] - i);
        int l = j - len + 1, r = j + len - 1, u = i - len + 1, d = i + len - 1;
        int c2 = cnt2[0][i][r] - cnt2[0][i][l - 1] + cnt2[1][d][j] -
                 cnt2[1][u - 1][j] - (a[i][j] == 2);
        int c3 = cnt3[0][i][r] - cnt3[0][i][l - 1] + cnt3[1][d][j] -
                 cnt3[1][u - 1][j] - (a[i][j] == 3);
        int d2 = c2 - a2, d3 = c3 - a3;
        if (d2 + log2(3) * d3 >= 0) a2 = c2, a3 = c3, mark = 1;
      }
}
long long qp(long long a, int k) {
  long long res = 1;
  while (k) {
    if (k & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    k >>= 1;
  }
  return res;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) a[i][j] = s[i][j] - '0';
  solve(n);
  int h = (n + 1) / 2;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) a[i][j] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if ((i + j) % 2 == 0) a[(i + j) / 2][h + (j - i) / 2] = s[i][j] - '0';
  solve(n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) a[i][j] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if ((i + j) % 2 == 1) a[(i + j) / 2][h + (j - i + 1) / 2] = s[i][j] - '0';
  solve(n);
  if (mark)
    printf("%I64d\n", qp(2, a2) * qp(3, a3) % 1000000007);
  else
    puts("0");
  return 0;
}
