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 = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 1010;
template <class T>
T min(T a, T b, T c, T d) {
  return min(min(a, b), min(c, d));
}
int dsus[N][N], dst[N][N], djos[N][N], dsd[N][N], ddr[N][N], djs[N][N],
    djd[N][N], dss[N][N];
long double ssus[N][N], sst[N][N], sss[N][N], sjos[N][N], ssd[N][N], sdr[N][N],
    sjs[N][N], sjd[N][N], sol;
int n;
char a[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int c = 1000000000;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> (a[i] + 1);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      a[i][j] -= '0';
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      long double l = 0;
      if (a[i][j]) {
        l = log2(a[i][j]) * c;
        dsus[i][j] = dsus[i - 1][j] + 1;
        dst[i][j] = dst[i][j - 1] + 1;
        dss[i][j] = dss[i - 1][j - 1] + 1;
      }
      ssus[i][j] = ssus[i - 1][j] + l;
      sst[i][j] = sst[i][j - 1] + l;
      sss[i][j] = sss[i - 1][j - 1] + l;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = n; j >= 1; j--) {
      long double l = 0;
      if (a[i][j]) {
        l = log2(a[i][j]) * c;
        dsd[i][j] = dsd[i - 1][j + 1] + 1;
        ddr[i][j] = ddr[i][j + 1] + 1;
      }
      ssd[i][j] = ssd[i - 1][j + 1] + l;
      sdr[i][j] = sdr[i][j + 1] + l;
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= n; ++j) {
      long double l = 0;
      if (a[i][j]) {
        l = log2(a[i][j]) * c;
        djos[i][j] = djos[i + 1][j] + 1;
        djs[i][j] = djs[i + 1][j - 1] + 1;
      }
      sjos[i][j] = sjos[i + 1][j] + 1;
      sjs[i][j] = sjs[i + 1][j - 1] + 1;
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = n; j >= 1; j--) {
      long double l = 0;
      if (a[i][j]) {
        l = log2(a[i][j]) * c;
        djd[i][j] = djd[i + 1][j + 1] + 1;
      }
      sjd[i][j] = sjd[i + 1][j + 1] + l;
    }
  }
  int px = 0;
  int py = 0;
  int dir = 0;
  sol = -1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (!a[i][j]) {
        continue;
      }
      int l = min(djos[i][j], dsus[i][j], ddr[i][j], dst[i][j]);
      l--;
      long double cs = ssus[i + l][j] - ssus[i - l - 1][j] + sst[i][j + l] -
                       sst[i][j] + sst[i][j - 1] - sst[i][j - l - 1];
      if (cs > sol) {
        sol = cs;
        px = i;
        py = j;
        dir = 1;
      }
      l = min(dss[i][j], djs[i][j], dsd[i][j], djd[i][j]);
      l--;
      cs = sss[i + l][j + l] - sss[i - l - 1][j - l - 1] + ssd[i + l][j - l] -
           ssd[i][j] + ssd[i - 1][j + 1] - ssd[i - l - 1][j + l + 1];
      if (cs > sol) {
        sol = cs;
        px = i;
        py = j;
        dir = 2;
      }
    }
  }
  long long SOL = 1;
  if (sol == -1) {
    cout << 0;
    return 0;
  }
  if (dir == 1) {
    int l = min(djos[px][py], dsus[px][py], ddr[px][py], dst[px][py]);
    l--;
    for (int i = px - l; i <= px + l; ++i) {
      SOL = SOL * a[i][py] % mod;
    }
    for (int j = py - l; j <= py + l; ++j) {
      if (j == py) {
        continue;
      }
      SOL = SOL * a[px][j] % mod;
    }
  } else {
    int l = min(dss[px][py], djs[px][py], dsd[px][py], djd[px][py]);
    l--;
    for (int i = px - l, j = py - l; i <= px + l; ++i, ++j) {
      SOL = SOL * a[i][j] % mod;
    }
    for (int i = px - l, j = py + l; i <= px + l; ++i, --j) {
      if (i == px) {
        continue;
      }
      SOL = SOL * a[i][j] % mod;
    }
  }
  cout << SOL;
  return 0;
}
