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 long long md = 1000000007;
char cz[1010][1010];
double mt[1010][1010][8];
double lgt[1010][1010];
int le[1010][1010][8];
int n;
int vc[8][2] = {{0, -1}, {-1, -1}, {-1, 0}, {-1, 1},
                {0, 1},  {1, 1},   {1, 0},  {1, -1}};
inline bool _ck(int a, int b) {
  return a >= 0 && b >= 0 && a < n && b < n && cz[a][b] != '0';
};
inline bool _sbck(int a, int b) { return a >= 0 && b >= 0 && a < n && b < n; };
double __cl(int a, int b, int k, int d) {
  int r = a + d * vc[k][0], c = b + d * vc[k][1];
  return mt[a][b][k] - mt[r][c][k];
};
int _bfi(int a, int b) {
  ++a, ++b;
  if (a > b) swap(a, b);
  int s = 0, e = n, m, r = 0;
  while (s <= e) {
    m = (s + e) >> 1;
    if (r <= a && n - m + 1 >= b)
      r = m, s = m + 1;
    else
      e = m - 1;
  }
  return r;
};
void _dx(int a, int b, double &mx, bool &fg, int &r, int &c) {
  if (cz[a][b] == '0') return;
  int i, j, d = _bfi(a, b);
  double t = lgt[a][b];
  if (!d) {
    if (t > mx) mx = t, r = a, c = b, fg = 1;
    return;
  }
  int sb = d - 1;
  for (i = 0; i < 8; i += 2) {
    sb = min(sb, le[a][b][i]);
  }
  for (i = 0; i < 8; i += 2) {
    t += __cl(a, b, i, sb);
  }
  if (t > mx) mx = t, r = a, c = b, fg = 0;
  sb = d - 1;
  for (i = 1; i < 8; i += 2) {
    sb = min(sb, le[a][b][i]);
  }
  for (t = lgt[a][b], i = 1; i < 8; i += 2) {
    t += __cl(a, b, i, sb);
  }
  if (t > mx) mx = t, r = a, c = b, fg = 1;
};
long long _cl(int a, int b, bool fg) {
  long long t = (long long)(cz[a][b] - '0');
  int i, j, k, r, c, d = _bfi(a, b);
  int sb = d - 1;
  for (i = fg ? 1 : 0; i < 8; i += 2) {
    sb = min(sb, le[a][b][i]);
  }
  for (i = fg ? 1 : 0; i < 8; i += 2) {
    r = a + vc[i][0], c = b + vc[i][1], k = 1;
    for (; k <= sb && _ck(r, c); r += vc[i][0], c += vc[i][1], ++k)
      t = t * (long long)(cz[r][c] - '0') % md;
  }
  return t;
};
bool cl() {
  int i, j, k, a, b;
  if (scanf("%d", &n) == -1) return 0;
  for (i = 0; i < n; scanf("%s", cz[i++]))
    ;
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n; ++j) {
      lgt[i][j] = log((double)(cz[i][j] - '0'));
      if (cz[i][j] == '0') lgt[i][j] = 0;
      for (k = 0; k < 4; ++k) {
        a = i + vc[k][0], b = j + vc[k][1];
        if (!_ck(a, b))
          le[i][j][k] = 0;
        else
          le[i][j][k] = le[a][b][k] + 1;
        mt[i][j][k] = _sbck(a, b) ? mt[a][b][k] + lgt[a][b] : 0;
      }
    }
    mt[i][n - 1][4] = 0;
    for (j = n - 2; j >= 0; --j) {
      a = i, b = j + 1;
      if (!_ck(a, b))
        le[i][j][4] = 0;
      else
        le[i][j][4] = le[a][b][k] + 1;
      mt[i][j][4] = mt[a][b][4] + lgt[a][b];
    }
  }
  for (i = n - 1; i >= 0; --i) {
    for (j = 0; j < n; ++j) {
      for (k = 5; k < 8; ++k) {
        a = i + vc[k][0], b = j + vc[k][1];
        if (!_ck(a, b))
          le[i][j][k] = 0;
        else
          le[i][j][k] = le[a][b][k] + 1;
        mt[i][j][k] = _sbck(a, b) ? mt[a][b][k] + lgt[a][b] : 0;
      }
    }
  }
  double mx = -1;
  bool fg = 0;
  for (i = 0; i < n; ++i)
    for (j = 0; j < n; ++j) _dx(i, j, mx, fg, a, b);
  if (mx < 0)
    printf("0\n");
  else
    printf("%I64d\n", _cl(a, b, fg));
  return 1;
};
int main() {
  while (cl())
    ;
  return 0;
};
