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 long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int n;
char board[1005][1005];
int pre[8][1005][1005], pre2[8][1005][1005], pre3[8][1005][1005];
int direction[8][2] = {{-1, 0},  {1, 0}, {0, -1}, {0, 1},
                       {-1, -1}, {1, 1}, {1, -1}, {-1, 1}};
bool bigger(int cnt21, int cnt31, int cnt22, int cnt32) {
  double d1 = cnt21 + cnt31 * log2(3), d2 = cnt22 + cnt32 * log2(3);
  return d1 > d2;
}
bool inRange(int x) { return x >= 0 && x < n; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  memset(board, 0, sizeof(board));
  memset(pre, 0, sizeof(pre));
  memset(pre2, 0, sizeof(pre2));
  memset(pre3, 0, sizeof(pre3));
  cin >> n;
  for (int i = 0; i < (int)n; i++)
    for (int j = 0; j < (int)n; j++) cin >> board[i][j];
  bool oneExist = 0;
  int maxCnt2 = 0, maxCnt3 = 0;
  for (int k = 0; k < (int)8; k++) {
    for (int i = 0; i < (int)n; i++) {
      for (int j = 0; j < (int)n; j++) {
        int x0 = i - direction[k][0], y0 = j - direction[k][1];
        if (!inRange(x0) || !inRange(y0)) {
          int cnt = 0, k0 = 0, k2 = 0, k3 = 0;
          bool next = 1;
          while (next) {
            cnt++;
            int x = x0 + direction[k][0] * cnt, y = y0 + direction[k][1] * cnt;
            if (!inRange(x) || !inRange(y)) {
              next = 0;
              break;
            }
            if (board[x][y] == '0') {
              k0 = k2 = k3 = 0;
            } else {
              if (board[x][y] == '2') k2++;
              if (board[x][y] == '3') k3++;
              k0++;
              pre[k][x][y] = k0;
              pre2[k][x][y] = k2;
              pre3[k][x][y] = k3;
            }
          }
        }
      }
    }
  }
  for (int i = 0; i < (int)n; i++) {
    for (int j = 0; j < (int)n; j++) {
      if (board[i][j] == '0') continue;
      for (int l = 0; l < (int)2; l++) {
        int t = l * 4;
        oneExist = 1;
        int cnt2 = 0, cnt3 = 0, cnt = 10000;
        if (board[i][j] == '2') cnt2++;
        if (board[i][j] == '3') cnt3++;
        for (int k = t; k < (int)t + 4; k++) cnt = min(cnt, pre[k][i][j] - 1);
        if (cnt) {
          for (int k = t; k < (int)t + 4; k++) {
            int x = i + direction[k][0] * cnt, y = j + direction[k][1] * cnt;
            cnt2 += abs(pre2[k][i][j] - pre2[k][x][y]);
            cnt3 += abs(pre3[k][i][j] - pre3[k][x][y]);
          }
        }
        if (bigger(cnt2, cnt3, maxCnt2, maxCnt3)) {
          maxCnt2 = cnt2;
          maxCnt3 = cnt3;
        }
      }
    }
  }
  if (!oneExist)
    cout << 0 << "\n";
  else {
    long long ans = 1;
    for (int i = 0; i < (int)maxCnt2; i++) {
      ans *= 2;
      ans %= mod;
    }
    for (int i = 0; i < (int)maxCnt3; i++) {
      ans *= 3;
      ans %= mod;
    }
    cout << ans << "\n";
  }
  return 0;
}
