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 long long INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e3, mod = 1e9 + 7;
int n, a[N + 7][N + 7];
pair<int, int> operator+(const pair<int, int> p, const int q) {
  if (q == 2) return make_pair(p.first + 1, p.second);
  if (q == 3) return make_pair(p.first, p.second + 1);
  return make_pair(p.first, p.second);
}
pair<int, int> operator-(const pair<int, int> p, const int q) {
  if (q == 2) return make_pair(p.first - 1, p.second);
  if (q == 3) return make_pair(p.first, p.second - 1);
  return make_pair(p.first, p.second);
}
pair<int, int> operator+(const pair<int, int> p, const pair<int, int> q) {
  return make_pair(p.first + q.first, p.second + q.second);
}
pair<int, int> operator-(const pair<int, int> p, const pair<int, int> q) {
  return make_pair(p.first - q.first, p.second - q.second);
}
int operator<(const pair<int, int> p, const pair<int, int> q) {
  if (p.first < q.first && p.second < q.second) return 1;
  if (p.first > q.first && p.second > q.second) return 0;
  return 1. * (p.first - q.first) < log2(3) * (q.second - p.second);
}
int Pow(int a, int first) {
  if (a == 0) return 0;
  int res = 1;
  for (; first; a = 1ll * a * a % mod, first >>= 1)
    if (first & 1) res = 1ll * res * a % mod;
  return res;
}
int get(const pair<int, int> p) {
  return 1ll * Pow(2, p.first) * Pow(3, p.second) % mod;
}
pair<int, int> sh[N + 7][N + 7], sl[N + 7][N + 7];
int ph[N + 7][N + 7], bh[N + 7][N + 7];
int pl[N + 7][N + 7], bl[N + 7][N + 7];
pair<int, int> sp[N + 7][N + 7], sn[N + 7][N + 7];
int pp[N + 7][N + 7], bp[N + 7][N + 7];
int pn[N + 7][N + 7], bn[N + 7][N + 7];
int main() {
  scanf("%d", &n);
  char c;
  int ok = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      while (!isdigit(c = getchar()))
        ;
      ok |= (a[i][j] = c - '0');
    }
  if (!ok) return puts("0"), 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) sh[i][j] = sh[i][j - 1] + a[i][j];
    for (int j = 0; j <= n; j++)
      if (a[i][j])
        ph[i][j] = ph[i][j - 1];
      else
        ph[i][j] = j;
    for (int j = n + 1; j >= 1; j--)
      if (a[i][j])
        bh[i][j] = bh[i][j + 1];
      else
        bh[i][j] = j;
  }
  for (int j = 1; j <= n; j++) {
    for (int i = 1; i <= n; i++) sl[i][j] = sl[i - 1][j] + a[i][j];
    for (int i = 0; i <= n; i++)
      if (a[i][j])
        pl[i][j] = pl[i - 1][j];
      else
        pl[i][j] = i;
    for (int i = n + 1; i >= 1; i--)
      if (a[i][j])
        bl[i][j] = bl[i + 1][j];
      else
        bl[i][j] = i;
  }
  for (int s = 2; s <= n * 2; s++) {
    for (int i = max(1, s - n); i <= min(n, s - 1); i++) {
      int j = s - i;
      sp[i][j] = sp[i - 1][j + 1] + a[i][j];
    }
    for (int i = max(1, s - n) - 1; i <= min(n, s - 1); i++) {
      int j = s - i;
      if (a[i][j])
        pp[i][j] = pp[i - 1][j + 1];
      else
        pp[i][j] = i;
    }
    for (int i = min(n, s - 1) + 1; i >= max(1, s - n); i--) {
      int j = s - i;
      if (a[i][j])
        bp[i][j] = bp[i + 1][j - 1];
      else
        bp[i][j] = i;
    }
  }
  for (int c = -n + 1; c <= n - 1; c++) {
    for (int i = max(1, c + 1); i <= min(n, c + n); i++) {
      int j = i - c;
      sn[i][j] = sn[i - 1][j - 1] + a[i][j];
    }
    for (int i = max(1, c + 1) - 1; i <= min(n, c + n); i++) {
      int j = i - c;
      if (a[i][j])
        pn[i][j] = pn[i - 1][j - 1];
      else
        pn[i][j] = i;
    }
    for (int i = min(n, c + n) + 1; i >= max(1, c + 1); i--) {
      int j = i - c;
      if (a[i][j])
        bn[i][j] = bn[i + 1][j + 1];
      else
        bn[i][j] = i;
    }
  }
  pair<int, int> ans(0, 0);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (a[i][j]) {
        pair<int, int> now(0, 0);
        int len = min(min(j - ph[i][j], bh[i][j] - j),
                      min(i - pl[i][j], bl[i][j] - i));
        now = now + sh[i][j + len - 1] - sh[i][j - len];
        now = now + sl[i + len - 1][j] - sl[i - len][j];
        now = now - a[i][j];
        if (ans < now) ans = now;
      }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (a[i][j]) {
        pair<int, int> now(0, 0);
        int len = min(min(i - pp[i][j], bp[i][j] - i),
                      min(i - pn[i][j], bn[i][j] - i));
        now = now + sp[i + len - 1][j - len + 1] - sp[i - len][j + len];
        now = now + sn[i + len - 1][j + len - 1] - sn[i - len][j - len];
        now = now - a[i][j];
        if (ans < now) ans = now;
      }
  printf("%d\n", get(ans));
  return 0;
}
