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 inf = 0x3f3f3f3f;
const double eps = 1e-8;
int dcmp(double x) { return fabs(x) <= eps ? 0 : (x > 0 ? 1 : -1); }
const int mod = 1e9 + 7;
int ksm(int x, int y) {
  int sum = 1;
  for (; y; y >>= 1) {
    if (y & 1) sum = 1LL * sum * x % mod;
    x = 1LL * x * x % mod;
  }
  return sum;
}
pair<int, int> operator+(const pair<int, int>& p1, const pair<int, int>& p2) {
  return make_pair(p1.first + p2.first, p1.second + p2.second);
}
pair<int, int> operator-(const pair<int, int>& p1, const pair<int, int>& p2) {
  return make_pair(p1.first - p2.first, p1.second - p2.second);
}
bool cmp(const pair<int, int>& p1, const pair<int, int>& p2) {
  double x = (double)p1.first * log(2.) + (double)p1.second * log(3.);
  double y = (double)p2.first * log(2.) + (double)p2.second * log(3.);
  return dcmp(x - y) < 0;
}
int l[1005][1005], r[1005][1005], u[1005][1005], d[1005][1005];
pair<int, int> b[1005][1005], c[1005][1005];
int a[1005][1005];
char str[1005][1005];
int n, N = 0;
pair<int, int> stk[5000005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) a[i][j] = str[i][j] - '0', cnt += a[i][j] == 0;
  if (cnt == n * n)
    printf("0\n");
  else {
    for (int i = 1; i <= n; i++) {
      for (int j = n; j >= 1; j--)
        if (a[i][j] == 0)
          r[i][j] = 0;
        else
          r[i][j] = r[i][j + 1] + 1;
      for (int j = 1; j <= n; j++)
        if (a[i][j] == 0)
          l[i][j] = 0;
        else
          l[i][j] = l[i][j - 1] + 1;
    }
    for (int j = 1; j <= n; j++) {
      for (int i = 1; i <= n; i++)
        if (a[i][j] == 0)
          u[i][j] = 0;
        else
          u[i][j] = u[i - 1][j] + 1;
      for (int i = n; i >= 1; i--)
        if (a[i][j] == 0)
          d[i][j] = 0;
        else
          d[i][j] = d[i + 1][j] + 1;
    }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        pair<int, int> tmp = make_pair(0, 0);
        if (a[i][j] == 2)
          tmp = make_pair(1, 0);
        else if (a[i][j] == 3)
          tmp = make_pair(0, 1);
        b[i][j] = b[i][j - 1] + tmp;
      }
    for (int j = 1; j <= n; j++)
      for (int i = 1; i <= n; i++) {
        pair<int, int> tmp = make_pair(0, 0);
        if (a[i][j] == 2)
          tmp = make_pair(1, 0);
        else if (a[i][j] == 3)
          tmp = make_pair(0, 1);
        c[i][j] = c[i - 1][j] + tmp;
      }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        if (a[i][j] == 0) continue;
        if (i == 3 && j == 3) {
          i++;
          i--;
        }
        int dist = min(min(l[i][j], r[i][j]), min(u[i][j], d[i][j]));
        pair<int, int> tmp = make_pair(0, 0);
        if (a[i][j] == 2)
          tmp = make_pair(1, 0);
        else if (a[i][j] == 3)
          tmp = make_pair(0, 1);
        pair<int, int> ans = b[i][j + dist - 1] - b[i][j - dist];
        ans = ans + c[i + dist - 1][j] - c[i - dist][j];
        ans = ans - tmp;
        stk[++N] = ans;
      }
    memset(r, 0, sizeof(r));
    memset(l, 0, sizeof(l));
    memset(u, 0, sizeof(u));
    memset(d, 0, sizeof(d));
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++)
        if (a[i][j] == 0)
          r[i][j] = 0;
        else
          r[i][j] = r[i - 1][j - 1] + 1;
      for (int j = n; j >= 1; j--)
        if (a[i][j] == 0)
          l[i][j] = 0;
        else
          l[i][j] = l[i - 1][j + 1] + 1;
    }
    for (int i = n; i >= 1; i--) {
      for (int j = 1; j <= n; j++)
        if (a[i][j] == 0)
          u[i][j] = 0;
        else
          u[i][j] = u[i + 1][j - 1] + 1;
      for (int j = n; j >= 1; j--)
        if (a[i][j] == 0)
          d[i][j] = 0;
        else
          d[i][j] = d[i + 1][j + 1] + 1;
    }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        pair<int, int> tmp = make_pair(0, 0);
        if (a[i][j] == 2)
          tmp = make_pair(1, 0);
        else if (a[i][j] == 3)
          tmp = make_pair(0, 1);
        b[i][j] = b[i - 1][j - 1] + tmp;
      }
    for (int i = 1; i <= n; i++)
      for (int j = n; j >= 1; j--) {
        pair<int, int> tmp = make_pair(0, 0);
        if (a[i][j] == 2)
          tmp = make_pair(1, 0);
        else if (a[i][j] == 3)
          tmp = make_pair(0, 1);
        c[i][j] = c[i - 1][j + 1] + tmp;
      }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        if (a[i][j] == 0) continue;
        if (i == 3 && j == 3) {
          i++;
          i--;
        }
        int dist = min(min(l[i][j], r[i][j]), min(u[i][j], d[i][j]));
        pair<int, int> tmp = make_pair(0, 0);
        if (a[i][j] == 2)
          tmp = make_pair(1, 0);
        else if (a[i][j] == 3)
          tmp = make_pair(0, 1);
        pair<int, int> ans =
            b[i + dist - 1][j + dist - 1] - b[i - dist][j - dist];
        ans = ans + c[i + dist - 1][j - dist + 1] - c[i - dist][j + dist];
        ans = ans - tmp;
        stk[++N] = ans;
      }
    sort(stk + 1, stk + 1 + N, cmp);
    int ans = 1;
    ans = 1LL * ksm(2, stk[N].first) * ksm(3, stk[N].second) % mod;
    printf("%d\n", ans);
  }
  return 0;
}
