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 S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  int l = v.size();
  for (int i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
const long double PI = 3.1415926535897932384626433832795;
const int mod = 1e9 + 7;
const int N = 1005;
int n, fl = 0;
long long a[N][N], res;
pair<int, int> rcp[N][N], ccp[N][N], fdcp[N][N], bdcp[N][N], ans;
set<int> ro[N], co[N], fd[2 * N], bd[2 * N];
set<int>::iterator it1, it2;
char x;
void pre() {
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= n + 1; j++) {
      if (a[i][j] == 0)
        ro[i].insert(j);
      else {
        rcp[i][j] = rcp[i][j - 1];
        if (a[i][j] == 2)
          rcp[i][j].first++;
        else if (a[i][j] == 3)
          rcp[i][j].second++;
      }
    }
  }
  for (int j = 0; j <= n + 1; j++) {
    for (int i = 0; i <= n + 1; i++) {
      if (a[i][j] == 0)
        co[j].insert(i);
      else {
        ccp[i][j] = ccp[i - 1][j];
        if (a[i][j] == 2)
          ccp[i][j].first++;
        else if (a[i][j] == 3)
          ccp[i][j].second++;
      }
    }
  }
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= n + 1; j++) {
      if (a[i][j] == 0)
        fd[n + 1 - i + j].insert(j);
      else {
        fdcp[i][j] = fdcp[i - 1][j - 1];
        if (a[i][j] == 2)
          fdcp[i][j].first++;
        else if (a[i][j] == 3)
          fdcp[i][j].second++;
      }
    }
  }
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= n + 1; j++) {
      if (a[i][j] == 0)
        bd[i + j].insert(j);
      else {
        bdcp[i][j] = bdcp[i - 1][j + 1];
        if (a[i][j] == 2)
          bdcp[i][j].first++;
        else if (a[i][j] == 3)
          bdcp[i][j].second++;
      }
    }
  }
}
pair<int, int> solvedi(int i, int j) {
  int bdn = i + j, fdn = n + 1 - i + j, j1, j2, j3, j4, mj;
  int cnt2, cnt3;
  bd[bdn].insert(j);
  fd[fdn].insert(j);
  it1 = bd[bdn].find(j);
  it2 = fd[fdn].find(j);
  it1--;
  it2--;
  j1 = *(it1);
  j2 = *(it2);
  it1 = bd[bdn].find(j);
  it2 = fd[fdn].find(j);
  it1++;
  it2++;
  j3 = *(it1);
  j4 = *(it2);
  bd[bdn].erase(j);
  fd[fdn].erase(j);
  mj = min(abs(j - j1), min(abs(j - j2), min(abs(j - j3), abs(j - j4))));
  cnt2 = bdcp[i + mj - 1][j - mj + 1].first - bdcp[i - mj][j + mj].first;
  cnt3 = bdcp[i + mj - 1][j - mj + 1].second - bdcp[i - mj][j + mj].second;
  cnt2 += fdcp[i + mj - 1][j + mj - 1].first - fdcp[i - mj][j - mj].first;
  cnt3 += fdcp[i + mj - 1][j + mj - 1].second - fdcp[i - mj][j - mj].second;
  cnt2 -= (a[i][j] == 2);
  cnt3 -= (a[i][j] == 3);
  return {cnt2, cnt3};
}
pair<int, int> solveve(int i, int j) {
  int i1, i2, j1, j2, cnt2, cnt3, mj;
  ro[i].insert(j);
  co[j].insert(i);
  it1 = ro[i].find(j);
  it2 = co[j].find(i);
  it1--;
  it2--;
  i1 = *(it2);
  j1 = *(it1);
  it1 = ro[i].find(j);
  it2 = co[j].find(i);
  it1++;
  it2++;
  i2 = *(it2);
  j2 = *(it1);
  ro[i].erase(j);
  co[j].erase(i);
  mj = min(abs(i - i1), min(abs(i - i2), min(abs(j - j1), abs(j - j2))));
  cnt2 = rcp[i][j + mj - 1].first - rcp[i][j - mj].first;
  cnt3 = rcp[i][j + mj - 1].second - rcp[i][j - mj].second;
  cnt2 += ccp[i + mj - 1][j].first - ccp[i - mj][j].first;
  cnt3 += ccp[i + mj - 1][j].second - ccp[i - mj][j].second;
  cnt2 -= (a[i][j] == 2);
  cnt3 -= (a[i][j] == 3);
  return {cnt2, cnt3};
}
pair<int, int> max(pair<int, int> p1, pair<int, int> p2) {
  if ((p1.first) + (p1.second * log2(3)) > p2.first + (p2.second * log2(3)))
    return p1;
  return p2;
}
void solve() {
  ans = {0, 0};
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] == 0) continue;
      ans = max(ans, solvedi(i, j));
      ans = max(ans, solveve(i, j));
    }
  }
  if (ans.first == 0 and ans.second == 0) {
    if (fl == 0)
      cout << 0 << endl;
    else
      cout << 1 << endl;
    return;
  }
  res = 1;
  for (int i = 0; i < ans.first; i++) res = (res * 2) % mod;
  for (int i = 0; i < ans.second; i++) res = (res * 3) % mod;
  cout << res << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      cin >> x;
      a[i][j] = (int)x - '0';
      if (a[i][j] == 1) fl = 1;
    }
  pre();
  solve();
  return 0;
}
