Vanya plays a game of balloons on the field of size n × n, where each cell contains a balloon with one of the values 0, 1, 2 or 3. The goal is to destroy a cross, such that the product of all values of balloons in the cross is maximum possible. There are two types of crosses: normal and rotated. For example:
    
    
      
    **o**  
    **o**  
    ooooo  
    **o**  
    **o**  
    

or
    
    
      
    o***o  
    *o*o*  
    **o**  
    *o*o*  
    o***o  
    

Formally, the cross is given by three integers r, c and d, such that d ≤ r, c ≤ n - d + 1. The normal cross consists of balloons located in cells (x, y) (where x stay for the number of the row and y for the number of the column), such that |x - r|·|y - c| = 0 and |x - r| + |y - c| < d. Rotated cross consists of balloons located in cells (x, y), such that |x - r| = |y - c| and |x - r| < d.

Vanya wants to know the maximum possible product of the values of balls forming one cross. As this value can be large, output it modulo 109 + 7.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of rows and columns in the table with balloons.

The each of the following n lines contains n characters '0', '1', '2' or '3' — the description of the values in balloons.

Output

Print the maximum possible product modulo 109 + 7. Note, that you are not asked to maximize the remainder modulo 109 + 7, but to find the maximum value and print it this modulo.

Examples

Input

4
1233
0213
2020
0303


Output

108


Input

5
00300
00300
33333
00300
00300


Output

19683


Input

5
00003
02030
00300
03020
30000


Output

108


Input

5
21312
10003
10002
10003
23231


Output

3


Input

5
12131
12111
12112
21311
21212


Output

24

Note

In the first sample, the maximum product is achieved for a rotated cross with a center in the cell (3, 3) and radius 1: 2·2·3·3·3 = 108.
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int IT_MAX = 4096;
const long long MOD = 1000000007;
const int INF = 1034567890;
const long long LL_INF = 1234567890123456789ll;
const double PI = acos(-1);
const long double ERR = 1E-10;
char in[1050][1050];
int cnt1[4][1050][1050];
int cnt2[4][1050][1050];
int cnt3[4][1050][1050];
int cnt4[4][1050][1050];
long double lg1[1050][1050];
long double lg2[1050][1050];
long double lg3[1050][1050];
long double lg4[1050][1050];
long long po2[10050];
long long po3[10050];
int main() {
  int N, i, j, k;
  po2[0] = po3[0] = 1;
  for (i = 1; i <= 10000; i++) {
    po2[i] = (po2[i - 1] * 2) % MOD;
    po3[i] = (po3[i - 1] * 3) % MOD;
  }
  scanf("%d", &N);
  for (i = 1; i <= N; i++) scanf("%s", in[i] + 1);
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= N; j++) {
      for (k = 0; k < 4; k++)
        cnt1[k][i][j] = cnt1[k][i][j - 1] + (in[i][j] == '0' + k);
      lg1[i][j] = lg1[i][j - 1];
      if (in[i][j] >= '2') lg1[i][j] += log10(in[i][j] - '0');
    }
  }
  for (j = 1; j <= N; j++) {
    for (i = 1; i <= N; i++) {
      for (k = 0; k < 4; k++)
        cnt2[k][i][j] = cnt2[k][i - 1][j] + (in[i][j] == '0' + k);
      lg2[i][j] = lg2[i - 1][j];
      if (in[i][j] >= '2') lg2[i][j] += log10(in[i][j] - '0');
    }
  }
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= N; j++) {
      for (k = 0; k < 4; k++)
        cnt3[k][i][j] = cnt3[k][i - 1][j - 1] + (in[i][j] == '0' + k);
      lg3[i][j] = lg3[i - 1][j - 1];
      if (in[i][j] >= '2') lg3[i][j] += log10(in[i][j] - '0');
    }
  }
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= N; j++) {
      for (k = 0; k < 4; k++)
        cnt4[k][i][j] = cnt4[k][i - 1][j + 1] + (in[i][j] == '0' + k);
      lg4[i][j] = lg4[i - 1][j + 1];
      if (in[i][j] >= '2') lg4[i][j] += log10(in[i][j] - '0');
    }
  }
  long double mx = -1;
  long long ans = 0;
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= N; j++) {
      if (in[i][j] == '0') continue;
      int st = 1, en = min(min(i - 1, j - 1), min(N - i, N - j)), mi, rv = 0;
      while (st <= en) {
        mi = (st + en) / 2;
        int c0 = 0;
        c0 += cnt1[0][i][j + mi] - cnt1[0][i][j - mi - 1];
        c0 += cnt2[0][i + mi][j] - cnt2[0][i - mi - 1][j];
        if (c0 == 0) {
          rv = mi;
          st = mi + 1;
        } else
          en = mi - 1;
      }
      int c2 = 0, c3 = 0;
      long double s = 0;
      c2 += cnt1[2][i][j + rv] - cnt1[2][i][j - rv - 1];
      c2 += cnt2[2][i + rv][j] - cnt2[2][i - rv - 1][j];
      if (in[i][j] == '2') c2--;
      c3 += cnt1[3][i][j + rv] - cnt1[3][i][j - rv - 1];
      c3 += cnt2[3][i + rv][j] - cnt2[3][i - rv - 1][j];
      if (in[i][j] == '3') c3--;
      s += lg1[i][j + rv] - lg1[i][j - rv - 1];
      s += lg2[i + rv][j] - lg2[i - rv - 1][j];
      s -= log10(in[i][j] - '0');
      if (s > mx) {
        mx = s;
        ans = (po2[c2] * po3[c3]) % MOD;
      }
    }
  }
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= N; j++) {
      if (in[i][j] == '0') continue;
      if (i == j && j == 3) {
        i = j;
      }
      int st = 1, en = min(min(i - 1, j - 1), min(N - i, N - j)), mi, rv = 0;
      while (st <= en) {
        mi = (st + en) / 2;
        int c0 = 0;
        c0 += cnt3[0][i + mi][j + mi] - cnt3[0][i - mi - 1][j - mi - 1];
        c0 += cnt4[0][i + mi][j - mi] - cnt4[0][i - mi - 1][j + mi + 1];
        if (c0 == 0) {
          rv = mi;
          st = mi + 1;
        } else
          en = mi - 1;
      }
      int c2 = 0, c3 = 0;
      long double s = 0;
      c2 += cnt3[2][i + rv][j + rv] - cnt3[2][i - rv - 1][j - rv - 1];
      c2 += cnt4[2][i + rv][j - rv] - cnt4[2][i - rv - 1][j + rv + 1];
      if (in[i][j] == '2') c2--;
      c3 += cnt3[3][i + rv][j + rv] - cnt3[3][i - rv - 1][j - rv - 1];
      c3 += cnt4[3][i + rv][j - rv] - cnt4[3][i - rv - 1][j + rv + 1];
      if (in[i][j] == '3') c3--;
      s += lg3[i + rv][j + rv] - lg3[i - rv - 1][j - rv - 1];
      s += lg4[i + rv][j - rv] - lg4[i - rv - 1][j + rv + 1];
      s -= log10(in[i][j] - '0');
      if (s > mx) {
        mx = s;
        ans = (po2[c2] * po3[c3]) % MOD;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
