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;
struct chengji {
  int ge[5];
  bool friend operator<(chengji x, chengji y) {
    if ((x.ge[2] < y.ge[2]) && (x.ge[3] < y.ge[3])) return 1;
    if ((x.ge[2] == y.ge[2]) && (x.ge[3] < y.ge[3])) return 1;
    if ((x.ge[2] < y.ge[2]) && (x.ge[3] == y.ge[3])) return 1;
    if ((x.ge[2] > y.ge[2]) && (x.ge[3] < y.ge[3])) {
      if ((x.ge[2] - y.ge[2]) * log(2.0) < (y.ge[3] - x.ge[3]) * log(3.0))
        return 1;
    }
    if ((x.ge[2] < y.ge[2]) && (x.ge[3] > y.ge[3])) {
      if ((x.ge[3] - y.ge[3]) * log(3.0) < (y.ge[2] - x.ge[2]) * log(2.0))
        return 1;
    }
    return 0;
  }
  chengji friend operator-(chengji x, chengji y) {
    for (int i = 1; i <= 3; i++) x.ge[i] -= y.ge[i];
    return x;
  }
  chengji friend operator+(chengji x, chengji y) {
    for (int i = 1; i <= 3; i++) x.ge[i] += y.ge[i];
    return x;
  }
} l[1100][1100], r[1100][1100], u[1100][1100], d[1100][1100], lu[1100][1100],
    ru[1100][1100], ld[1100][1100], rd[1100][1100], temp;
chengji maxx;
int lenl[1100][1100], lenr[1100][1100], lenu[1100][1100], lend[1100][1100],
    lenlu[1100][1100], lenru[1100][1100], lenld[1100][1100], lenrd[1100][1100];
int n;
char s[1100];
int a[1100][1100];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf(" %s", s + 1);
    for (int j = 1; j <= n; j++) a[i][j] = s[j] - '0';
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] == 0) {
        lenl[i][j] = 0;
      } else {
        lenl[i][j] = lenl[i][j - 1] + 1;
        l[i][j] = l[i][j - 1];
        l[i][j].ge[a[i][j]]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = n; j >= 1; j--) {
      if (a[i][j] == 0) {
        lenr[i][j] = 0;
      } else {
        lenr[i][j] = lenr[i][j + 1] + 1;
        r[i][j] = r[i][j + 1];
        r[i][j].ge[a[i][j]]++;
      }
    }
  }
  for (int j = 1; j <= n; j++) {
    for (int i = 1; i <= n; i++) {
      if (a[i][j] == 0) {
        lenu[i][j] = 0;
      } else {
        lenu[i][j] = lenu[i - 1][j] + 1;
        u[i][j] = u[i - 1][j];
        u[i][j].ge[a[i][j]]++;
      }
    }
  }
  for (int j = 1; j <= n; j++) {
    for (int i = n; i >= 1; i--) {
      if (a[i][j] == 0) {
        lend[i][j] = 0;
      } else {
        lend[i][j] = lend[i + 1][j] + 1;
        d[i][j] = d[i + 1][j];
        d[i][j].ge[a[i][j]]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] == 0) {
        lenlu[i][j] = 0;
      } else {
        lenlu[i][j] = lenlu[i - 1][j - 1] + 1;
        lu[i][j] = lu[i - 1][j - 1];
        lu[i][j].ge[a[i][j]]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = n; j >= 1; j--) {
      if (a[i][j] == 0) {
        lenru[i][j] = 0;
      } else {
        lenru[i][j] = lenru[i - 1][j + 1] + 1;
        ru[i][j] = ru[i - 1][j + 1];
        ru[i][j].ge[a[i][j]]++;
      }
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] == 0) {
        lenld[i][j] = 0;
      } else {
        lenld[i][j] = lenld[i + 1][j - 1] + 1;
        ld[i][j] = ld[i + 1][j - 1];
        ld[i][j].ge[a[i][j]]++;
      }
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = n; j >= 1; j--) {
      if (a[i][j] == 0) {
        lenrd[i][j] = 0;
      } else {
        lenrd[i][j] = lenrd[i + 1][j + 1] + 1;
        rd[i][j] = rd[i + 1][j + 1];
        rd[i][j].ge[a[i][j]]++;
      }
    }
  }
  int v = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] != 0) {
        int m = min(min(lenu[i][j], lend[i][j]), min(lenl[i][j], lenr[i][j]));
        chengji q = u[i][j] - u[i - m][j];
        q = q + (d[i][j] - d[i + m][j]);
        q = q + (l[i][j] - l[i][j - m]);
        q = q + (r[i][j] - r[i][j + m]);
        q.ge[a[i][j]] -= 3;
        maxx = max(maxx, q);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] != 0) {
        v = 1;
        int m =
            min(min(lenlu[i][j], lenld[i][j]), min(lenru[i][j], lenrd[i][j]));
        chengji q = lu[i][j] - lu[i - m][j - m];
        q = q + (ld[i][j] - ld[i + m][j - m]);
        q = q + (ru[i][j] - ru[i - m][j + m]);
        q = q + (rd[i][j] - rd[i + m][j + m]);
        q.ge[a[i][j]] -= 3;
        maxx = max(maxx, q);
      }
    }
  }
  if (!v) {
    printf("0\n");
    return 0;
  }
  long long anss = 1;
  long long modd = 1000000000 + 7;
  for (int i = 1; i <= maxx.ge[2]; i++) {
    anss *= 2;
    anss %= modd;
  }
  for (int i = 1; i <= maxx.ge[3]; i++) {
    anss *= 3;
    anss %= modd;
  }
  cout << anss << endl;
  return 0;
}
