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;
long long modpow(int a, short b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  if (b & 1) return (modpow(a, b - 1) * a) % 1000000007;
  long long v = modpow(a, b / 2);
  return (v * v) % 1000000007;
}
struct p23 {
  short p2, p3, rad;
  p23(short p2 = 0, short p3 = 0, short rad = 0) : p2(p2), p3(p3), rad(rad) {}
  void add(int v, bool ch) {
    if (ch) rad++;
    if (v == 2)
      p2++;
    else if (v == 3)
      p3++;
    else if (v == 0)
      p2 = p3 = rad = 0;
  }
  int val() {
    if (rad == 0) return 0;
    return int((modpow(2, p2) * modpow(3, p3)) % 1000000007);
  }
};
bool operator<(const p23& lhs, const p23& rhs) {
  return float(lhs.p2 - rhs.p2) < 1.58496250072 * float(rhs.p3 - lhs.p3);
}
int n, brd[1011][1011], pi, pj, qi, qj;
p23 dp[1011][1011][8], ncr, crs, ans;
int dx[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};
void build(int i, int j, int k) {
  pi = i + dy[k];
  pj = j + dx[k];
  if (pi >= 0 && pi < n && pj >= 0 && pj < n) dp[i][j][k] = dp[pi][pj][k];
  dp[i][j][k].add(brd[i][j], true);
}
void process(int i, int j) {
  ncr = crs = p23(0, 0, 1011);
  for (int(k) = int(0); (k) <= int(3); (k)++) {
    ncr.rad = min(ncr.rad, dp[i][j][2 * k].rad);
    crs.rad = min(crs.rad, dp[i][j][2 * k + 1].rad);
  }
  ncr.add(brd[i][j], false);
  if (ncr.rad - 1 > 0)
    for (int(k) = int(0); (k) <= int(3); (k)++) {
      pi = i + dy[2 * k];
      pj = j + dx[2 * k];
      qi = i + ncr.rad * dy[2 * k];
      qj = j + ncr.rad * dx[2 * k];
      if (qi >= 0 && qi < n && qj >= 0 && qj < n) {
        ncr.p2 += dp[pi][pj][2 * k].p2 - dp[qi][qj][2 * k].p2;
        ncr.p3 += dp[pi][pj][2 * k].p3 - dp[qi][qj][2 * k].p3;
      } else {
        ncr.p2 += dp[pi][pj][2 * k].p2;
        ncr.p3 += dp[pi][pj][2 * k].p3;
      }
    }
  ans = max(ncr, ans);
  crs.add(brd[i][j], false);
  if (crs.rad - 1 > 0)
    for (int(k) = int(0); (k) <= int(3); (k)++) {
      pi = i + dy[2 * k + 1];
      pj = j + dx[2 * k + 1];
      qi = i + crs.rad * dy[2 * k + 1];
      qj = j + crs.rad * dx[2 * k + 1];
      if (qi >= 0 && qi < n && qj >= 0 && qj < n) {
        crs.p2 += dp[pi][pj][2 * k + 1].p2 - dp[qi][qj][2 * k + 1].p2;
        crs.p3 += dp[pi][pj][2 * k + 1].p3 - dp[qi][qj][2 * k + 1].p3;
      } else {
        crs.p2 += dp[pi][pj][2 * k + 1].p2;
        crs.p3 += dp[pi][pj][2 * k + 1].p3;
      }
    }
  ans = max(crs, ans);
}
int main() {
  scanf("%d", &n);
  for (int(i) = int(0); (i) <= int(n - 1); (i)++)
    for (int(j) = int(0); (j) <= int(n - 1); (j)++) scanf("%1d", &brd[i][j]);
  for (int(i) = int(0); (i) <= int(n - 1); (i)++)
    for (int(j) = int(0); (j) <= int(n - 1); (j)++)
      for (int(k) = int(0); (k) <= int(3); (k)++) build(i, j, k);
  for (int(i) = int(n - 1); (i) >= int(0); (i)--)
    for (int(j) = int(n - 1); (j) >= int(0); (j)--)
      for (int(k) = int(4); (k) <= int(7); (k)++) build(i, j, k);
  for (int(i) = int(0); (i) <= int(n - 1); (i)++)
    for (int(j) = int(0); (j) <= int(n - 1); (j)++) process(i, j);
  printf("%d\n", ans.val());
}
