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;
int N;
int A[1010][1010];
int SH[4][1010][1010];
int SV[4][1010][1010];
int Ssl[4][1010][1010];
int Srev[4][1010][1010];
int L[1010][1010];
int R[1010][1010];
int U[1010][1010];
int D[1010][1010];
int UL[1010][1010];
int UR[1010][1010];
int DL[1010][1010];
int DR[1010][1010];
signed long long mo = 1000000007;
string S;
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N;
  for (y = 0; y < (N); y++) {
    cin >> S;
    for (x = 0; x < (N); x++) A[y][x] = S[x] - '0';
  }
  for (i = 0; i < (4); i++) {
    for (y = 0; y < (N); y++)
      for (x = 0; x < (N); x++) {
        SH[i][y + 1][x + 1] = SH[i][y + 1][x] + (A[y][x] == i);
        SV[i][y + 1][x + 1] = SV[i][y][x + 1] + (A[y][x] == i);
        Ssl[i][y + 1][x + 1] = Ssl[i][y][x + 2] + (A[y][x] == i);
        Srev[i][y + 1][x + 1] = Srev[i][y][x] + (A[y][x] == i);
      }
  }
  for (y = 0; y < (N); y++)
    for (x = 0; x < (N); x++) {
      L[y + 1][x + 1] = (A[y][x] == 0) ? 0 : (1 + L[y + 1][x]);
      UL[y + 1][x + 1] = (A[y][x] == 0) ? 0 : (1 + UL[y][x]);
      UR[y + 1][x + 1] = (A[y][x] == 0) ? 0 : (1 + UR[y][x + 2]);
    }
  for (y = 0; y < (N); y++)
    for (x = N - 1; x >= 0; x--)
      R[y + 1][x + 1] = (A[y][x] == 0) ? 0 : (1 + R[y + 1][x + 2]);
  for (x = 0; x < (N); x++)
    for (y = 0; y < (N); y++)
      U[y + 1][x + 1] = (A[y][x] == 0) ? 0 : (1 + U[y][x + 1]);
  for (x = 0; x < (N); x++)
    for (y = N - 1; y >= 0; y--)
      D[y + 1][x + 1] = (A[y][x] == 0) ? 0 : (1 + D[y + 2][x + 1]);
  for (y = N - 1; y >= 0; y--)
    for (x = 0; x < (N); x++) {
      DL[y + 1][x + 1] = (A[y][x] == 0) ? 0 : (1 + DL[y + 2][x]);
      DR[y + 1][x + 1] = (A[y][x] == 0) ? 0 : (1 + DR[y + 2][x + 2]);
    }
  double ma = -3;
  int p2 = 0, p3 = 0;
  for (y = 0; y < (N); y++)
    for (x = 0; x < (N); x++)
      if (A[y][x] != 0) {
        int mc = min(min(L[y + 1][x + 1], R[y + 1][x + 1]),
                     min(U[y + 1][x + 1], D[y + 1][x + 1]));
        int t[4] = {};
        for (i = 2; i <= 3; i++)
          t[i] = SH[i][y + 1][x + 1 + mc - 1] - SH[i][y + 1][x + 1 - mc] +
                 SV[i][y + 1 + mc - 1][x + 1] - SV[i][y + 1 - mc][x + 1] -
                 (A[y][x] == i);
        double dt = t[2] * log(2) + t[3] * log(3);
        if (dt > ma) ma = dt, p2 = t[2], p3 = t[3];
        mc = min(min(UL[y + 1][x + 1], UR[y + 1][x + 1]),
                 min(DL[y + 1][x + 1], DR[y + 1][x + 1]));
        for (i = 2; i <= 3; i++)
          t[i] = Srev[i][y + 1 + mc - 1][x + 1 + mc - 1] -
                 Srev[i][y + 1 - mc][x + 1 - mc] +
                 Ssl[i][y + 1 + mc - 1][x + 1 - (mc - 1)] -
                 Ssl[i][y + 1 - mc][x + 1 + mc] - (A[y][x] == i);
        dt = t[2] * log(2) + t[3] * log(3);
        if (dt > ma) ma = dt, p2 = t[2], p3 = t[3];
      }
  if (ma < -2)
    cout << 0 << endl;
  else {
    signed long long ret = 1;
    for (i = 0; i < (p2); i++) ret = ret * 2 % mo;
    for (i = 0; i < (p3); i++) ret = ret * 3 % mo;
    cout << ret << endl;
  }
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  solve();
  return 0;
}
