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 N = 2e3, M = 1e6, INF = 1e9 + 123, MOD = 1e9 + 7, KEY = 1001;
const double EPS = 0.000000001;
template <typename T>
inline T sqr(T t) {
  return t * t;
}
inline void file() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
char ch;
struct point {
  int x, y;
};
int n, H[N][N][4], V[N][N][4], D1[N][N][4], D2[N][N][4], a[N][N];
pair<int, int> ans;
bool ok;
inline point pt(int x, int y) {
  point res;
  res.x = x;
  res.y = y;
  return res;
}
inline int get(point a, point b, int col) {
  if (a.x == b.x) {
    if (a.y > b.y) swap(a, b);
    return H[b.x][b.y][col] - H[a.x][a.y - 1][col];
  } else if (a.y == b.y) {
    if (a.x > b.x) swap(a, b);
    return V[b.x][b.y][col] - V[a.x - 1][a.y][col];
  } else if (a.x + a.y == b.x + b.y) {
    if (a.x < b.x) swap(a, b);
    return D1[b.x][b.y][col] - D1[a.x + 1][a.y - 1][col];
  } else {
    if (a.x > b.x) swap(a, b);
    return D2[b.x][b.y][col] - D2[a.x - 1][a.y - 1][col];
  }
}
inline void initDP() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 0; k < 4; k++) H[i][j][k] = H[i][j - 1][k] + (a[i][j] == k);
  for (int j = 1; j <= n; j++)
    for (int i = 1; i <= n; i++)
      for (int k = 0; k < 4; k++) V[i][j][k] = V[i - 1][j][k] + (a[i][j] == k);
  for (int st = 1; st <= n; st++) {
    for (int i = st, j = 1; i > 0 && j <= n; i--, j++)
      for (int k = 0; k < 4; k++)
        D1[i][j][k] = D1[i + 1][j - 1][k] + (a[i][j] == k);
    for (int i = n, j = st; i > 0 && j <= n; i--, j++)
      for (int k = 0; k < 4; k++)
        D1[i][j][k] = D1[i + 1][j - 1][k] + (a[i][j] == k);
    for (int i = 1, j = st; i <= n && j <= n; i++, j++)
      for (int k = 0; k < 4; k++)
        D2[i][j][k] = D2[i - 1][j - 1][k] + (a[i][j] == k);
    for (int i = st, j = 1; i <= n && j <= n; i++, j++)
      for (int k = 0; k < 4; k++)
        D2[i][j][k] = D2[i - 1][j - 1][k] + (a[i][j] == k);
  }
}
inline int takeHV(point a, int r, int k) {
  int res = get(pt(a.x - r + 1, a.y), pt(a.x + r - 1, a.y), k);
  if (r > 1)
    res += get(pt(a.x, a.y - r + 1), pt(a.x, a.y - 1), k) +
           get(pt(a.x, a.y + r - 1), pt(a.x, a.y + 1), k);
  return res;
}
inline int takeD(point a, int r, int k) {
  int res = get(pt(a.x - r + 1, a.y - r + 1), pt(a.x + r - 1, a.y + r - 1), k);
  if (r > 1)
    res += get(pt(a.x + r - 1, a.y - r + 1), pt(a.x + 1, a.y - 1), k) +
           get(pt(a.x - 1, a.y + 1), pt(a.x - r + 1, a.y + r - 1), k);
  return res;
}
inline pair<int, int> checkHV(point a) {
  int l = 1, r = min(a.x, min(a.y, min(n - a.x + 1, n - a.y + 1)));
  while (r - l > 1) {
    int md = (l + r) >> 1;
    if (takeHV(a, md, 0))
      r = md;
    else
      l = md;
  }
  if (takeHV(a, r, 0)) r = l;
  return make_pair(takeHV(a, r, 2), takeHV(a, r, 3));
}
inline pair<int, int> checkD(point a) {
  int l = 1, r = min(a.x, min(a.y, min(n - a.x + 1, n - a.y + 1)));
  while (r - l > 1) {
    int md = (l + r) >> 1;
    if (takeD(a, md, 0))
      r = md;
    else
      l = md;
  }
  if (takeD(a, r, 0)) r = l;
  return make_pair(takeD(a, r, 2), takeD(a, r, 3));
}
inline double getLog(pair<int, int> x) {
  return (double)x.first * log10(2) + x.second * log10(3);
}
int main() {
  file();
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      cin >> ch;
      a[i][j] = (ch - '0');
      if (a[i][j]) ok = true;
    }
  initDP();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      pair<int, int> res = checkHV(pt(i, j));
      if (getLog(ans) < getLog(res)) ans = res;
      res = checkD(pt(i, j));
      if (getLog(ans) < getLog(res)) ans = res;
    }
  if (ans.first == 0 && ans.second == 0) {
    if (ok)
      cout << 1;
    else
      cout << 0;
  } else {
    long long res = 1;
    for (int i = 1; i <= ans.first; i++) {
      res <<= 1;
      res %= MOD;
    }
    for (int i = 1; i <= ans.second; i++) {
      res *= 3;
      res %= MOD;
    }
    cout << res;
  }
}
