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 int MOD = 1e9 + 7;
const int maxn = 1000 + 10;
struct Node {
  int n1, n2, n3, l;
  inline Node() { n1 = n2 = n3 = l = 0; }
  inline Node(char c) {
    n1 = n2 = n3 = l = 0;
    if (c == '1')
      n1 = l = 1;
    else if (c == '2')
      n2 = l = 1;
    else if (c == '3')
      n3 = l = 1;
  }
  inline Node operator+(Node &a) const {
    Node t;
    t.n1 = n1 + a.n1;
    t.n2 = n2 + a.n2;
    t.n3 = n3 + a.n3;
    return t;
  }
  inline Node operator-(Node &a) const {
    Node t;
    t.n1 = n1 - a.n1;
    t.n2 = n2 - a.n2;
    t.n3 = n3 - a.n3;
    return t;
  }
};
char w[maxn][maxn];
Node dp[8][maxn][maxn], ans;
int dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int n;
inline long long quick_(long long x, int n) {
  if (x == 0) return 0;
  long long ans = 1;
  for (; n;) {
    if (n & 1) ans = ans * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return ans;
}
inline void prin(Node no) {
  cout << "n1:" << no.n1 << " n2:" << no.n2 << " n3:" << no.n3 << endl;
}
inline void init() {
  memset(w, '0', sizeof(w));
  int i, j, z, x, y;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) scanf("%s", w[i] + 1);
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= n; ++j)
      for (z = 0; z < 8; ++z) dp[z][i][j] = Node(w[i][j]);
  for (z = 0; z < 4; ++z)
    for (i = 1; i <= n; ++i)
      for (j = 1; j <= n; ++j) {
        x = i + dx[z];
        y = j + dy[z];
        if (w[i][j] != '0') {
          dp[z][i][j] = dp[z][i][j] + dp[z][x][y];
          dp[z][i][j].l += dp[z][x][y].l + 1;
        }
      }
  for (z = 4; z < 6; ++z)
    for (i = n; i >= 1; --i)
      for (j = n; j >= 1; --j) {
        x = i + dx[z];
        y = j + dy[z];
        if (w[i][j] != '0') {
          dp[z][i][j] = dp[z][i][j] + dp[z][x][y];
          dp[z][i][j].l += dp[z][x][y].l + 1;
        }
      }
  for (z = 6; z < 8; ++z)
    for (i = n; i >= 1; --i)
      for (j = 1; j <= n; ++j) {
        x = i + dx[z];
        y = j + dy[z];
        if (w[i][j] != '0') {
          dp[z][i][j] = dp[z][i][j] + dp[z][x][y];
          dp[z][i][j].l += dp[z][x][y].l + 1;
        }
      }
}
int main() {
  double tan1, tan2, tan = 0;
  int i, j, z, lnor, lrot, x, y;
  init();
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= n; ++j) {
      Node no, ro;
      lrot = lnor = maxn;
      for (z = 0; z < 8; z += 2)
        lnor = min(lnor, dp[z][i][j].l), no = no + dp[z][i][j];
      for (z = 0; z < 8; z += 2) {
        if (dp[z][i][j].l > lnor) {
          x = i + dx[z] * (lnor);
          y = j + dy[z] * (lnor);
          no = no - dp[z][x][y];
        }
      }
      for (z = 1; z < 8; z += 2)
        lrot = min(lrot, dp[z][i][j].l), ro = ro + dp[z][i][j];
      for (z = 1; z < 8; z += 2) {
        if (dp[z][i][j].l > lrot) {
          x = i + dx[z] * (lrot);
          y = j + dy[z] * (lrot);
          ro = ro - dp[z][x][y];
        }
      }
      if (w[i][j] == '1')
        ro.n1 -= 3, no.n1 -= 3;
      else if (w[i][j] == '2')
        ro.n2 -= 3, no.n2 -= 3;
      else if (w[i][j] == '3')
        ro.n3 -= 3, no.n3 -= 3;
      Node t;
      tan1 = no.n2 * log(2) + no.n3 * log(3);
      tan2 = ro.n2 * log(2) + ro.n3 * log(3);
      if (tan1 > tan) ans = no, tan = tan1;
      if (tan2 > tan) ans = ro, tan = tan2;
      if (fabs(tan - 0) < 1e-9) {
        if (ans.n1 == 0 && no.n1 != 0)
          ans = no;
        else if (ans.n1 == 0 && ro.n1 != 0)
          ans = ro;
      }
    }
  long long res = quick_(2, ans.n2) * quick_(3, ans.n3) % MOD;
  if (ans.n2 == 0 && ans.n3 == 0 && ans.n1 == 0) res = 0;
  cout << res << endl;
}
