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 N = 2001;
const long long P = 1000000007;
int i, j, n, k, x, y, L, R, mid, ans2, ans3;
int a[N][N], sump[4][N][N], sumv[4][N][N], sumL[4][N][N], sumR[4][N][N];
char s[N];
long long flag;
int check1() {
  if (sump[0][i][j + mid] - sump[0][i][j - mid - 1] > 0) return 1;
  if (sumv[0][i + mid][j] - sumv[0][i - mid - 1][j] > 0) return 1;
  x = sump[2][i][j + mid] - sump[2][i][j - mid - 1] + sumv[2][i + mid][j] -
      sumv[2][i - mid - 1][j];
  if (a[i][j] == 2) x--;
  y = sump[3][i][j + mid] - sump[3][i][j - mid - 1] + sumv[3][i + mid][j] -
      sumv[3][i - mid - 1][j];
  if (a[i][j] == 3) y--;
  return 0;
}
int check2() {
  if (sumL[0][i + mid][j + mid] - sumL[0][i - mid - 1][j - mid - 1] > 0)
    return 1;
  if (sumR[0][i + mid][j - mid] - sumR[0][i - mid - 1][j + mid + 1] > 0)
    return 1;
  x = sumL[2][i + mid][j + mid] - sumL[2][i - mid - 1][j - mid - 1] +
      sumR[2][i + mid][j - mid] - sumR[2][i - mid - 1][j + mid + 1];
  if (a[i][j] == 2) x--;
  y = sumL[3][i + mid][j + mid] - sumL[3][i - mid - 1][j - mid - 1] +
      sumR[3][i + mid][j - mid] - sumR[3][i - mid - 1][j + mid + 1];
  if (a[i][j] == 3) y--;
  return 0;
}
void update() {
  if (log(2) * x + log(3) * y > log(2) * ans2 + log(3) * ans3)
    ans2 = x, ans3 = y;
}
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s;
    for (j = 0; j < n; j++) a[i][j + 1] = s[j] - '0';
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      for (k = 0; k <= 3; k++)
        if (a[i][j] == k)
          sump[k][i][j] = sump[k][i][j - 1] + 1;
        else
          sump[k][i][j] = sump[k][i][j - 1];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      for (k = 0; k <= 3; k++)
        if (a[j][i] == k)
          sumv[k][j][i] = sumv[k][j - 1][i] + 1;
        else
          sumv[k][j][i] = sumv[k][j - 1][i];
  for (k = 0; k <= 3; k++) {
    for (x = 1; x <= n; x++)
      for (i = 1, j = x; i <= n && j <= n; i++, j++)
        if (a[i][j] == k)
          sumL[k][i][j] = sumL[k][i - 1][j - 1] + 1;
        else
          sumL[k][i][j] = sumL[k][i - 1][j - 1];
    for (x = 2; x <= n; x++)
      for (i = x, j = 1; i <= n && j <= n; i++, j++)
        if (a[i][j] == k)
          sumL[k][i][j] = sumL[k][i - 1][j - 1] + 1;
        else
          sumL[k][i][j] = sumL[k][i - 1][j - 1];
    for (x = 1; x <= n; x++)
      for (i = 1, j = x; i <= n && j > 0; i++, j--)
        if (a[i][j] == k)
          sumR[k][i][j] = sumR[k][i - 1][j + 1] + 1;
        else
          sumR[k][i][j] = sumR[k][i - 1][j + 1];
    for (x = 2; x <= n; x++)
      for (i = x, j = n; i <= n && j > 0; i++, j--)
        if (a[i][j] == k)
          sumR[k][i][j] = sumR[k][i - 1][j + 1] + 1;
        else
          sumR[k][i][j] = sumR[k][i - 1][j + 1];
  }
  ans2 = ans3 = 0;
  flag = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) {
      if (a[i][j] == 0) continue;
      flag = 1;
      L = 0;
      R = min(min(i - 1, j - 1), min(n - i, n - j));
      while (L <= R) {
        mid = (L + R) / 2;
        if (check1())
          R = mid - 1;
        else
          L = mid + 1;
      }
      update();
      L = 0;
      R = min(min(i - 1, j - 1), min(n - i, n - j));
      while (L <= R) {
        mid = (L + R) / 2;
        if (check2())
          R = mid - 1;
        else
          L = mid + 1;
      }
      update();
    }
  if (!flag)
    cout << 0;
  else {
    for (i = 1; i <= ans2; i++) flag = flag * 2LL % P;
    for (i = 1; i <= ans3; i++) flag = flag * 3LL % P;
    cout << flag;
  }
}
