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[1005][1005];
double lg[4][3005];
int l[1005][1005], r[1005][1005], t[1005][1005], d[1005][1005];
int tl[1005][1005], tr[1005][1005], dl[1005][1005], dr[1005][1005];
struct sum {
  int x, y, z;
  sum operator+(sum b) { return {x + b.x, y + b.y, z + b.z}; }
  sum operator+(int &b) {
    if (b == 1) return {x + 1, y, z};
    if (b == 2) return {x, y + 1, z};
    if (b == 3) return {x, y, z + 1};
  }
  sum operator-(sum b) { return {x - b.x, y - b.y, z - b.z}; }
  bool operator>(sum &b) {
    return lg[2][y] + lg[3][z] > lg[2][b.y] + lg[3][b.z];
  }
};
sum pre[1005][1005];
sum dia1[2005][2005], dia2[2005][2005];
sum getsum(int x1, int y1, int x2, int y2) {
  return pre[x2][y2] - pre[x1 - 1][y2] - pre[x2][y1 - 1] + pre[x1 - 1][y1 - 1];
}
sum getsum2(int x1, int y1, int x2, int y2) {
  assert(x1 - y1 == x2 - y2);
  int tmp = x1 - y1 + 1000;
  return dia1[tmp][y2] - dia1[tmp][y1 - 1];
}
sum getsum3(int x1, int y1, int x2, int y2) {
  assert(x1 + y1 == x2 + y2);
  int tmp = x1 + y1;
  return dia2[tmp][y1] - dia2[tmp][y2 + 1];
}
const long long mod = 1000000007;
sum ans = {0, 0, 0};
long long getans() {
  long long aa = 1;
  for (int i = 0; i < ans.y; i++) aa = aa * 2 % mod;
  for (int i = 0; i < ans.z; i++) aa = aa * 3 % mod;
  return aa;
}
signed main() {
  ios::sync_with_stdio(0), cin.tie(0);
  ;
  lg[2][1] = log(2);
  lg[3][1] = log(3);
  for (int i = 2; i <= 3000; i++) {
    lg[2][i] = lg[2][1] + lg[2][i - 1];
    lg[3][i] = lg[3][1] + lg[3][i - 1];
  }
  int n;
  cin >> n;
  bool all0 = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      char c;
      cin >> c;
      arr[i][j] = c - '0';
      if (arr[i][j]) all0 = 0;
      pre[i][j] = pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1];
      pre[i][j] = pre[i][j] + arr[i][j];
      dia1[i - j + 1000][j] = dia1[i - j + 1000][j - 1] + arr[i][j];
      dia2[i + j][j] = dia2[i + j][j + 1] + arr[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (arr[i][j] == 0) {
        t[i][j] = l[i][j] = tl[i][j] = tr[i][j] = 0;
      } else {
        t[i][j] = t[i - 1][j] + 1;
        l[i][j] = l[i][j - 1] + 1;
        tl[i][j] = tl[i - 1][j - 1] + 1;
        tr[i][j] = tr[i - 1][j + 1] + 1;
      }
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = n; j >= 1; j--) {
      if (!arr[i][j])
        d[i][j] = r[i][j] = dl[i][j] = dr[i][j] = 0;
      else {
        d[i][j] = d[i + 1][j] + 1, r[i][j] = r[i][j + 1] + 1;
        dl[i][j] = dl[i + 1][j - 1] + 1, dr[i][j] = dr[i + 1][j + 1] + 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int dis = min({t[i][j], d[i][j], l[i][j], r[i][j]});
      if (dis > 0) {
        sum tmp = getsum(i - dis + 1, j, i + dis - 1, j) +
                  getsum(i, j - dis + 1, i, j + dis - 1) - getsum(i, j, i, j);
        if (tmp > ans) ans = tmp;
      }
      dis = min({tl[i][j], tr[i][j], dl[i][j], dr[i][j]});
      if (dis > 0) {
        sum tmp2 = getsum2(i - dis + 1, j - dis + 1, i + dis - 1, j + dis - 1) +
                   getsum3(i + dis - 1, j - dis + 1, i - dis + 1, j + dis - 1) -
                   getsum(i, j, i, j);
        if (tmp2 > ans) ans = tmp2;
      }
    }
  }
  if (all0) {
    cout << 0 << '\n';
  } else {
    cout << getans() << '\n';
  }
}
