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>
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);
}
