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 double PI = acos(0) * 2;
const double EPS = 1e-8;
const long long MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcounll(s);
}
long long ch[1010][1010][4], cc[1010][1010][4], dc1[1010][1010][4],
    dc2[1010][1010][4];
int n, a[1010][1010];
double ret;
long long ans;
long long power_mod(long long n, long long m, long long mod) {
  if (m == 0) return 1;
  long long r = power_mod(n, m / 2, mod);
  if (m % 2 == 0)
    return r * r % mod;
  else
    return r * r % mod * n % mod;
}
int main() {
  double l3 = log2(3);
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      char x;
      cin >> x;
      a[i][j] = x - '0';
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = 0; k < 4; k++) {
        ch[j][i][k] = ch[j][i - 1][k];
        cc[i][j][k] = cc[i][j - 1][k];
        dc1[i][j][k] = dc1[i - 1][j - 1][k];
        dc2[i][j][k] = dc2[i - 1][j + 1][k];
      }
      ch[j][i][a[i][j]] = ch[j][i - 1][a[i][j]] + 1;
      cc[i][j][a[i][j]] = cc[i][j - 1][a[i][j]] + 1;
      dc1[i][j][a[i][j]] = dc1[i - 1][j - 1][a[i][j]] + 1;
      dc2[i][j][a[i][j]] = dc2[i - 1][j + 1][a[i][j]] + 1;
    }
  }
  long long c0, c1, c2, c3;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (a[i][j] != 0) {
        int l = 0, r = n;
        while (l < r) {
          int mid = (l + r + 1) >> 1;
          if (i + mid > n || i - mid < 1 || j + mid > n || j - mid < 1) {
            r = mid - 1;
            continue;
          }
          int dd = i - mid;
          int dt = i + mid;
          int bt = j - mid;
          int bp = j + mid;
          long long lc0 =
              ch[j][dt][0] - ch[j][dd - 1][0] + cc[i][bp][0] - cc[i][bt - 1][0];
          long long lc1 =
              ch[j][dt][1] - ch[j][dd - 1][1] + cc[i][bp][1] - cc[i][bt - 1][1];
          long long lc2 =
              ch[j][dt][2] - ch[j][dd - 1][2] + cc[i][bp][2] - cc[i][bt - 1][2];
          long long lc3 =
              ch[j][dt][3] - ch[j][dd - 1][3] + cc[i][bp][3] - cc[i][bt - 1][3];
          if (lc0 != 0)
            r = mid - 1;
          else {
            l = mid;
            c0 = lc0;
            c1 = lc1;
            c2 = lc2;
            c3 = lc3;
          }
        }
        if (l == 0) {
          c0 = 0;
          c2 = 0;
          c3 = 0;
          if (a[i][j] == 3) c3 = 2;
          if (a[i][j] == 2) c2 = 2;
        }
        if (c3 == 0 && c2 == 0 && c1 != 0 && ans == 0) ans = 1;
        if (c0 == 0) {
          if (a[i][j] == 3) c3 -= 1;
          if (a[i][j] == 2) c2 -= 1;
          if (l3 * c3 + c2 > ret) {
            ret = l3 * c3 + c2;
            ans = 1LL;
            if (c3 != 0) ans *= power_mod(3LL, c3, MOD);
            if (c2 != 0) ans *= power_mod(2LL, c2, MOD);
            ans %= MOD;
          }
        }
        l = 0;
        r = n;
        while (l < r) {
          int mid = (l + r + 1) >> 1;
          if (i + mid > n || i - mid < 1 || j + mid > n || j - mid < 1) {
            r = mid - 1;
            continue;
          }
          int dd = i - mid;
          int dt = i + mid;
          int bt = j - mid;
          int bp = j + mid;
          long long lc0 = dc1[dt][bp][0] - dc1[dd - 1][bt - 1][0] +
                          dc2[dt][bt][0] - dc2[dd - 1][bp + 1][0];
          long long lc1 = dc1[dt][bp][1] - dc1[dd - 1][bt - 1][1] +
                          dc2[dt][bt][1] - dc2[dd - 1][bp + 1][1];
          long long lc2 = dc1[dt][bp][2] - dc1[dd - 1][bt - 1][2] +
                          dc2[dt][bt][2] - dc2[dd - 1][bp + 1][2];
          long long lc3 = dc1[dt][bp][3] - dc1[dd - 1][bt - 1][3] +
                          dc2[dt][bt][3] - dc2[dd - 1][bp + 1][3];
          if (lc0 != 0)
            r = mid - 1;
          else {
            l = mid;
            c0 = lc0;
            c1 = lc1;
            c2 = lc2;
            c3 = lc3;
          }
        }
        if (l == 0) {
          c0 = 0;
          c2 = 0;
          c3 = 0;
          if (a[i][j] == 3) c3 = 2;
          if (a[i][j] == 2) c2 = 2;
        }
        if (c3 == 0 && c2 == 0 && c1 != 0 && ans == 0) ans = 1;
        if (c0 == 0) {
          if (a[i][j] == 3) c3 -= 1;
          if (a[i][j] == 2) c2 -= 1;
          if (l3 * c3 + c2 > ret) {
            ret = l3 * c3 + c2;
            ans = 1LL;
            if (c3 != 0) ans *= power_mod(3LL, c3, MOD);
            if (c2 != 0) ans *= power_mod(2LL, c2, MOD);
            ans %= MOD;
          }
        }
      }
  }
  cout << ans;
  return 0;
}
