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;
template <typename T>
using Matrix = vector<vector<T>>;
using Point = pair<int, int>;
struct Number {
  array<int, 4> x = {{0, 0, 0, 0}};
  Number() {}
  Number(int a) { x[a]++; }
  long double log_value() const {
    if (x[0] > 0) return -1;
    return x[2] * log(2L) + x[3] * log(3L);
  }
  int mod() const {
    long long result = 1;
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < x[i]; j++) result = (result * i) % (int)(1e9 + 7);
    return result;
  }
  bool is_zero() const { return x[0] > 0; }
};
bool operator<(const Number& a, const Number& b) {
  return a.log_value() < b.log_value();
}
Number operator+(const Number& a, const Number& b) {
  Number result;
  for (int i = 0; i < 4; i++) result.x[i] = a.x[i] + b.x[i];
  return result;
}
Number operator-(const Number& a, const Number& b) {
  Number result;
  for (int i = 0; i < 4; i++) result.x[i] = a.x[i] - b.x[i];
  return result;
}
const int MAX = 1005;
int N;
int grid[MAX][MAX];
Number hsum[MAX][MAX];
Number vsum[MAX][MAX];
Number psum[MAX][MAX];
Number nsum[MAX][MAX];
void precompute() {
  for (int r = 0; r <= N; r++) {
    hsum[r][0] = Number();
    for (int c = 1; c <= N; c++)
      hsum[r][c] = hsum[r][c - 1] + Number(grid[r][c]);
  }
  for (int c = 0; c <= N; c++) {
    vsum[0][c] = Number();
    for (int r = 1; r <= N; r++)
      vsum[r][c] = vsum[r - 1][c] + Number(grid[r][c]);
  }
  for (int i = 0; i <= N; i++) psum[i][0] = psum[0][i] = Number();
  for (int r = 1; r <= N; r++)
    for (int c = 1; c <= N; c++)
      psum[r][c] = psum[r - 1][c - 1] + Number(grid[r][c]);
  for (int i = 0; i <= N; i++) nsum[i][0] = nsum[N + 1][i] = Number();
  for (int r = N; r >= 1; r--)
    for (int c = 1; c <= N; c++)
      nsum[r][c] = nsum[r + 1][c - 1] + Number(grid[r][c]);
}
Number getv(int r, int c, int l) {
  int r1 = r - l, r2 = r + l;
  if (r1 <= 0 || r2 > N) return Number(0);
  return vsum[r2][c] - vsum[r1 - 1][c];
}
Number geth(int r, int c, int l) {
  int c1 = c - l, c2 = c + l;
  if (c1 <= 0 || c2 > N) return Number(0);
  return hsum[r][c2] - hsum[r][c1 - 1];
}
Number getpdiag(int r, int c, int l) {
  int r1 = r - l, r2 = r + l;
  int c1 = c - l, c2 = c + l;
  if (r1 <= 0 || r2 > N || c1 <= 0 || c2 > N) return Number(0);
  return psum[r2][c2] - psum[r1 - 1][c1 - 1];
}
Number getndiag(int r, int c, int l) {
  int r1 = r + l, r2 = r - l;
  int c1 = c - l, c2 = c + l;
  if (r1 > N || r2 <= 0 || c1 <= 0 || c2 > N) return Number(0);
  return nsum[r2][c2] - nsum[r1 + 1][c1 - 1];
}
bool works(int r, int c, int l) {
  Number x = getv(r, c, l) + geth(r, c, l);
  return !x.is_zero();
}
bool works2(int r, int c, int l) {
  Number x = getpdiag(r, c, l) + getndiag(r, c, l);
  return !x.is_zero();
}
Number solve(int r, int c) {
  if (grid[r][c] == 0) return Number(0);
  int a = 0, b = N;
  while (a < b) {
    int mid = (a + b + 1) / 2;
    if (works(r, c, mid))
      a = mid;
    else
      b = mid - 1;
  }
  Number result = geth(r, c, a) + getv(r, c, a) - Number(grid[r][c]);
  a = 0, b = N;
  while (a < b) {
    int mid = (a + b + 1) / 2;
    if (works2(r, c, mid))
      a = mid;
    else
      b = mid - 1;
  }
  Number result2 = getpdiag(r, c, a) + getndiag(r, c, a) - Number(grid[r][c]);
  return max(result, result2);
}
int solve() {
  precompute();
  Number best(0);
  for (int r = 1; r <= N; r++)
    for (int c = 1; c <= N; c++) best = max(best, solve(r, c));
  return best.mod();
}
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < N; j++) grid[i][j + 1] = s[j] - '0';
  }
  cout << solve() << endl;
}
