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 arr[1000][1000];
int cnt[4][4][1000][1000];
char str[1005];
int getmx(int m1, int m2) {
  double l1 = (m1 / 10000 * log(3)) + (m1 % 10000 * log(2));
  double l2 = (m2 / 10000 * log(3)) + (m2 % 10000 * log(2));
  return l1 < l2 ? m2 : m1;
}
long long modpow(long long b, int e) {
  if (e == 0) return 1;
  if (e == 1) return b;
  long long m = modpow(b, e / 2);
  m = (m * m) % 1000000007LL;
  if (e % 2 == 1) m = (m * b) % 1000000007LL;
  return m;
}
long long calc(int m) {
  return (modpow(2LL, m % 10000) * modpow(3LL, m / 10000)) % 1000000007LL;
}
int getnum(int c, int i, int j, int r) {
  int ret =
      cnt[c][0][i + r][j] - cnt[c][0][i - r][j] + (arr[i - r][j] == c ? 1 : 0);
  ret +=
      cnt[c][1][i][j + r] - cnt[c][1][i][j - r] + (arr[i][j - r] == c ? 1 : 0);
  if (arr[i][j] == c) ret--;
  return ret;
}
int getnum2(int c, int i, int j, int r) {
  int ret = cnt[c][2][i + r][j + r] - cnt[c][2][i - r][j - r] +
            (arr[i - r][j - r] == c ? 1 : 0);
  ret += cnt[c][3][i + r][j - r] - cnt[c][3][i - r][j + r] +
         (arr[i - r][j + r] == c ? 1 : 0);
  if (arr[i][j] == c) ret--;
  return ret;
}
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%s", str);
    for (int j = 0; j < N; j++) {
      arr[i][j] = str[j] - '0';
    }
  }
  for (int n = 0; n < 4; n++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        cnt[n][0][i][j] =
            (arr[i][j] == n ? 1 : 0) + (i != 0 ? cnt[n][0][i - 1][j] : 0);
        cnt[n][1][i][j] =
            (arr[i][j] == n ? 1 : 0) + (j != 0 ? cnt[n][1][i][j - 1] : 0);
        cnt[n][2][i][j] = (arr[i][j] == n ? 1 : 0) +
                          ((i != 0 && j != 0) ? cnt[n][2][i - 1][j - 1] : 0);
        cnt[n][3][i][j] =
            (arr[i][j] == n ? 1 : 0) +
            ((i != 0 && j != N - 1) ? cnt[n][3][i - 1][j + 1] : 0);
      }
    }
  }
  int mx = -1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (arr[i][j] == 0) continue;
      int L = 0;
      int R = min(min(i, j), min(N - i, N - j) - 1);
      while (R - L > 2) {
        int M = (L + R) / 2;
        if (getnum(0, i, j, M) == 0) {
          L = M;
        } else {
          R = M - 1;
        }
      }
      while (L < R) {
        if (getnum(0, i, j, L) == 0)
          L++;
        else
          break;
      }
      while (getnum(0, i, j, L) != 0) L--;
      mx = getmx(mx, getnum(3, i, j, L) * 10000 + getnum(2, i, j, L));
      L = 0;
      R = min(min(i, j), min(N - i, N - j) - 1);
      while (R - L > 2) {
        int M = (L + R) / 2;
        if (getnum2(0, i, j, M) == 0) {
          L = M;
        } else {
          R = M - 1;
        }
      }
      while (L < R) {
        if (getnum2(0, i, j, L) == 0)
          L++;
        else
          break;
      }
      if (getnum2(0, i, j, L) != 0) L--;
      mx = getmx(mx, getnum2(3, i, j, L) * 10000 + getnum2(2, i, j, L));
    }
  }
  if (mx == -1)
    printf("0\n");
  else
    printf("%I64d\n", calc(mx));
  return 0;
}
