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 MAXN = 2005;
const int INF = 1000000000;
const int MOD = INF + 7;
pair<int, int> operator-(pair<int, int> i1, pair<int, int> i2) {
  return pair<int, int>(i1.first - i2.first, i1.second - i2.second);
}
pair<int, int> operator+(pair<int, int> i1, pair<int, int> i2) {
  return pair<int, int>(i1.first + i2.first, i1.second + i2.second);
}
pair<int, int> maior(pair<int, int> i1, pair<int, int> i2) {
  pair<int, int> c1 = i1, c2 = i2;
  int dm = min(i1.first, i2.first), tm = min(i1.second, i2.second);
  i1.first -= dm, i2.first -= dm;
  i1.second -= tm, i2.second -= tm;
  if (i1.first == 0 && i1.second == 0) return c2;
  if (i2.first == 0 && i2.second == 0) return c1;
  if (i1.first == 0) swap(i1, i2), swap(c1, c2);
  int dois = i1.first - i2.first, tres = i2.second - i1.second;
  if (tres >= (log(2.) / log(3.)) * dois) return c2;
  return c1;
}
pair<int, int> linha[MAXN][MAXN];
pair<int, int> coluna[MAXN][MAXN];
int CE[MAXN][MAXN], CD[MAXN][MAXN];
int CC[MAXN][MAXN], CB[MAXN][MAXN];
int mat[MAXN][MAXN];
int allright[MAXN][MAXN];
pair<int, int> solve(int n) {
  memset(CE, 0, sizeof CE);
  memset(CD, 0, sizeof CD);
  memset(CB, 0, sizeof CB);
  memset(CC, 0, sizeof CC);
  for (int i = 0; i < n + 1; i++)
    for (int j = 0; j < n + 1; j++)
      linha[i][j] = coluna[i][j] = pair<int, int>(0, 0);
  for (int i = 0; i < n + 1; i++)
    linha[i][0] = pair<int, int>(0, 0), CE[i][0] = CD[i][n + 1] = 0;
  for (int i = 0; i < n + 1; i++)
    coluna[0][i] = pair<int, int>(0, 0), CC[0][i] = CB[n + 1][i] = 0;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < n + 1; j++) {
      int c = mat[i - 1][j - 1];
      CC[i][j] = CC[i - 1][j] + 1;
      if (c == 0) CC[i][j] = 0;
    }
  }
  for (int i = n; i >= 0; i--) {
    for (int j = 1; j < n + 1; j++) {
      int c = mat[i - 1][j - 1];
      CB[i][j] = CB[i + 1][j] + 1;
      if (c == 0) CB[i][j] = 0;
    }
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < n + 1; j++) {
      int c = mat[i - 1][j - 1];
      CE[i][j] = CE[i][j - 1] + 1;
      if (c == 0) CE[i][j] = 0;
    }
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = n; j >= 0; j--) {
      int c = mat[i - 1][j - 1];
      CD[i][j] = CD[i][j + 1] + 1;
      if (c == 0) CD[i][j] = 0;
    }
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < n + 1; j++) {
      int c = mat[i - 1][j - 1];
      linha[i][j] = linha[i][j - 1];
      coluna[i][j] = coluna[i - 1][j];
      if (c == 2) {
        linha[i][j].first++;
        coluna[i][j].first++;
      } else if (c == 3) {
        linha[i][j].second++;
        coluna[i][j].second++;
      }
    }
  }
  pair<int, int> max1;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < n + 1; j++) {
      int mm = min(min(CD[i][j], CE[i][j]), min(CC[i][j], CB[i][j]));
      mm--;
      pair<int, int> aux = linha[i][j + mm] - linha[i][j - mm - 1] +
                           coluna[i + mm][j] - coluna[i - mm - 1][j];
      if (!allright[i - 1][j - 1]) continue;
      int c = mat[i - 1][j - 1];
      if (c == 0) continue;
      if (c == 2) aux.first--;
      if (c == 3) aux.second--;
      max1 = maior(max1, aux);
    }
  }
  return max1;
}
string inp[MAXN];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 0; i < n; i++) cin >> inp[i];
    int tudozero = 0;
    memset(allright, 0, sizeof allright);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (inp[i][j] != '0') tudozero = 1;
        mat[i][j] = inp[i][j] - '0';
        allright[i][j] = 1;
      }
    }
    long long ans = 1;
    if (tudozero == 0) ans = 0;
    pair<int, int> r1 = solve(n);
    memset(allright, 0, sizeof allright);
    for (int i = 0; i < MAXN; i++)
      for (int j = 0; j < MAXN; j++) mat[i][j] = 1;
    for (int i = 0; i < n; i++) {
      int idx1 = i + (-1), idx2 = (-1) - i + n - 1;
      if (idx1 < 0 || idx1 >= 2 * n - 1) continue;
      if (idx2 < 0 || idx2 >= 2 * n - 1) continue;
      mat[idx1][idx2] = 0;
    }
    for (int i = 0; i < n; i++) {
      int idx1 = i + (n), idx2 = (n)-i + n - 1;
      if (idx1 < 0 || idx1 >= 2 * n - 1) continue;
      if (idx2 < 0 || idx2 >= 2 * n - 1) continue;
      mat[idx1][idx2] = 0;
    }
    for (int i = 0; i < n; i++) {
      int idx1 = (-1) + (i), idx2 = (i) - (-1) + n - 1;
      if (idx1 < 0 || idx1 >= 2 * n - 1) continue;
      if (idx2 < 0 || idx2 >= 2 * n - 1) continue;
      mat[idx1][idx2] = 0;
    }
    for (int i = 0; i < n; i++) {
      int idx1 = (n) + (i), idx2 = (i) - (n) + n - 1;
      if (idx1 < 0 || idx1 >= 2 * n - 1) continue;
      if (idx2 < 0 || idx2 >= 2 * n - 1) continue;
      mat[idx1][idx2] = 0;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        int idx1 = i + j, idx2 = j - i + n - 1;
        mat[idx1][idx2] = inp[i][j] - '0';
        allright[idx1][idx2] = 1;
      }
    }
    pair<int, int> r2 = solve(2 * n - 1);
    r1 = maior(r1, r2);
    for (int i = 0; i < r1.first; i++) {
      ans *= 2;
      ans %= MOD;
    }
    for (int i = 0; i < r1.second; i++) {
      ans *= 3;
      ans %= MOD;
    }
    cout << ans << endl;
  }
}
