#include <bits/stdc++.h>
using namespace std;
const int MO = 1e9 + 7;
double Max_sum = 0.0, lg2[4], pre[1010][1010][8];
int X, Y, D, WAY, Dis, n, g[1010][1010], near[1010][1010][8];
char s[1010];
int main() {
  bool flag = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= n; j++) {
      g[i][j] = s[j] - '0';
      if (g[i][j]) flag = 0;
    }
  }
  if (flag) {
    printf("0\n");
    return 0;
  }
  lg2[0] = -54321;
  for (int i = 1; i <= 3; i++) lg2[i] = log(i);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (!g[i][j]) {
        near[i][j][0] = near[i][j][5] = 0;
        near[i][j][1] = near[i][j][4] = 0;
      } else {
        near[i][j][4] = near[i - 1][j - 1][4] + 1;
        near[i][j][5] = near[i - 1][j + 1][5] + 1;
        near[i][j][0] = near[i - 1][j][0] + 1;
        near[i][j][1] = near[i][j - 1][1] + 1;
      }
      pre[i][j][4] = pre[i - 1][j - 1][4] + lg2[g[i][j]];
      pre[i][j][0] = pre[i - 1][j][0] + lg2[g[i][j]];
      pre[i][j][5] = pre[i - 1][j + 1][5] + lg2[g[i][j]];
      pre[i][j][1] = pre[i][j - 1][1] + lg2[g[i][j]];
    }
  for (int i = n; i >= 1; i--)
    for (int j = n; j >= 1; j--) {
      if (!g[i][j]) {
        near[i][j][7] = near[i][j][2] = 0;
        near[i][j][6] = near[i][j][3] = 0;
      } else {
        near[i][j][7] = near[i + 1][j + 1][7] + 1;
        near[i][j][6] = near[i + 1][j - 1][6] + 1;
        near[i][j][2] = near[i][j + 1][2] + 1;
        near[i][j][3] = near[i + 1][j][3] + 1;
      }
      pre[i][j][6] = pre[i + 1][j - 1][6] + lg2[g[i][j]];
      pre[i][j][2] = pre[i][j + 1][2] + lg2[g[i][j]];
      pre[i][j][7] = pre[i + 1][j + 1][7] + lg2[g[i][j]];
      pre[i][j][3] = pre[i + 1][j][3] + lg2[g[i][j]];
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      int D = 12345;
      for (int k = 0; k <= 3; k++) D = min(D, near[i][j][k]);
      if (D) {
        double sum = 0.0;
        sum += pre[i + D - 1][j][0] - pre[i - D][j][0];
        sum += pre[i][j + D - 1][1] - pre[i][j - D][1];
        sum -= lg2[g[i][j]];
        if (sum > Max_sum) Max_sum = sum, X = i, Y = j, Dis = D, WAY = 1;
      }
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      int D = 12345;
      for (int k = 4; k <= 7; k++) D = min(D, near[i][j][k]);
      if (D) {
        double sum = 0.0;
        sum += pre[i + D - 1][j + D - 1][4] - pre[i - D][j - D][4];
        sum += pre[i + D - 1][j - D + 1][5] - pre[i - D][j + D][5];
        sum -= lg2[g[i][j]];
        if (sum > Max_sum) Max_sum = sum, X = i, Y = j, Dis = D, WAY = 2;
      }
    }
  int CJ = 1;
  if (WAY == 1) {
    for (int i = X - Dis + 1; i <= X + Dis - 1; i++)
      if (i != X) CJ = (long long)CJ * g[i][Y] % MO;
    for (int j = Y - Dis + 1; j <= Y + Dis - 1; j++)
      CJ = (long long)CJ * g[X][j] % MO;
  } else {
    for (int i = -Dis + 1; i <= Dis - 1; i++)
      if (i) CJ = (long long)CJ * g[X + i][Y - i] % MO;
    for (int i = -Dis + 1; i <= Dis - 1; i++)
      CJ = (long long)CJ * g[X + i][Y + i] % MO;
  }
  printf("%d\n", CJ);
}
