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;
struct sum {
  int two, three;
};
vector<vector<int> > transform(vector<vector<int> > v) {
  vector<vector<int> > w(2 * v.size() - 1, vector<int>(2 * v.size() - 1, 1));
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < v.size(); j++) {
      w[i + j][v.size() - 1 - i + j] = v[i][j];
    }
  }
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < v.size() - i - 1; j++) {
      w[i][j] = 0;
      w[w.size() - i - 1][j] = 0;
      w[i][w.size() - j - 1] = 0;
      w[w.size() - i - 1][w.size() - j - 1] = 0;
    }
  }
  return w;
}
long double value(sum s) {
  return double(s.two) * log(2.0) + double(s.three) * log(3.0);
}
int main() {
  int n;
  cin >> n;
  bool allzeros = true;
  vector<vector<int> > v(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      char c;
      cin >> c;
      v[i][j] = c - '0';
      if (v[i][j] != 0) allzeros = false;
    }
  }
  sum null;
  null.two = 0, null.three = 0;
  vector<vector<int> > zx(n);
  vector<vector<int> > zy(n);
  vector<vector<sum> > sx(n, vector<sum>(n, null));
  vector<vector<sum> > sy(n, vector<sum>(n, null));
  sum max = null;
  for (int i = 0; i < n; i++) zx[i].push_back(-1);
  for (int i = 0; i < n; i++) zy[i].push_back(-1);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (v[i][j] == 0) {
        zx[i].push_back(j);
        zy[j].push_back(i);
      }
      if (j != 0) sx[i][j] = sx[i][j - 1];
      if (v[i][j] == 2) sx[i][j].two++;
      if (v[i][j] == 3) sx[i][j].three++;
      if (i != 0) sy[i][j] = sy[i - 1][j];
      if (v[i][j] == 2) sy[i][j].two++;
      if (v[i][j] == 3) sy[i][j].three++;
    }
  }
  for (int i = 0; i < n; i++) zx[i].push_back(n);
  for (int i = 0; i < n; i++) zy[i].push_back(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int x, y;
      x = lower_bound(zx[i].begin(), zx[i].end(), j) - zx[i].begin();
      y = lower_bound(zy[j].begin(), zy[j].end(), i) - zy[j].begin();
      x = min(j - zx[i][x - 1], zx[i][x] - j);
      y = min(i - zy[j][y - 1], zy[j][y] - i);
      int r = min(x, y) - 1;
      sum t = null;
      if (r >= 0) {
        t.two = sx[i][j + r].two - sx[i][j - r].two + sy[i + r][j].two -
                sy[i - r][j].two;
        t.three = sx[i][j + r].three - sx[i][j - r].three + sy[i + r][j].three -
                  sy[i - r][j].three;
        if (v[i][j - r] == 2) t.two++;
        if (v[i - r][j] == 2) t.two++;
        if (v[i][j - r] == 3) t.three++;
        if (v[i - r][j] == 3) t.three++;
        if (v[i][j] == 2) t.two--;
        if (v[i][j] == 3) t.three--;
      }
      if (value(t) > value(max)) {
        max = t;
      }
    }
  }
  v = transform(v);
  zx = vector<vector<int> >(2 * n - 1);
  zy = vector<vector<int> >(2 * n - 1);
  sx = vector<vector<sum> >(2 * n - 1, vector<sum>(2 * n - 1, null));
  sy = vector<vector<sum> >(2 * n - 1, vector<sum>(2 * n - 1, null));
  for (int i = 0; i < 2 * n - 1; i++) zx[i].push_back(-1);
  for (int i = 0; i < 2 * n - 1; i++) zy[i].push_back(-1);
  for (int i = 0; i < 2 * n - 1; i++) {
    for (int j = 0; j < 2 * n - 1; j++) {
      if (v[i][j] == 0) {
        zx[i].push_back(j);
        zy[j].push_back(i);
      }
      if (j != 0) sx[i][j] = sx[i][j - 1];
      if (v[i][j] == 2) sx[i][j].two++;
      if (v[i][j] == 3) sx[i][j].three++;
      if (i != 0) sy[i][j] = sy[i - 1][j];
      if (v[i][j] == 2) sy[i][j].two++;
      if (v[i][j] == 3) sy[i][j].three++;
    }
  }
  for (int i = 0; i < 2 * n - 1; i++) zx[i].push_back(2 * n - 1);
  for (int i = 0; i < 2 * n - 1; i++) zy[i].push_back(2 * n - 1);
  for (int i = 0; i < 2 * n - 1; i++) {
    for (int j = (i + n + 1) % 2; j < 2 * n - 1; j += 2) {
      int x, y;
      x = lower_bound(zx[i].begin(), zx[i].end(), j) - zx[i].begin();
      y = lower_bound(zy[j].begin(), zy[j].end(), i) - zy[j].begin();
      x = min(j - zx[i][x - 1], zx[i][x] - j);
      y = min(i - zy[j][y - 1], zy[j][y] - i);
      int r = min(x, y) - 1;
      sum t = null;
      if (r >= 0) {
        t.two = sx[i][j + r].two - sx[i][j - r].two + sy[i + r][j].two -
                sy[i - r][j].two;
        t.three = sx[i][j + r].three - sx[i][j - r].three + sy[i + r][j].three -
                  sy[i - r][j].three;
        if (v[i][j - r] == 2) t.two++;
        if (v[i - r][j] == 2) t.two++;
        if (v[i][j - r] == 3) t.three++;
        if (v[i - r][j] == 3) t.three++;
        if (v[i][j] == 2) t.two--;
        if (v[i][j] == 3) t.three--;
      }
      if (value(t) > value(max)) {
        max = t;
      }
    }
  }
  if (allzeros)
    cout << 0 << endl;
  else {
    long long total = 1;
    for (int i = 0; i < max.two; i++) {
      total *= 2;
      total %= 1000000007;
    }
    for (int i = 0; i < max.three; i++) {
      total *= 3;
      total %= 1000000007;
    }
    cout << total << endl;
  }
}
