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 <class T>
void print_2darray(const char* s, T arr, int n, int m) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (int i = 0, _stop = n; i < _stop; i++) {
    cout << "{";
    for (int j = 0, _stop = m; j < _stop; j++) {
      cout << arr[i][j] << (j == m - 1 ? "" : ",");
    }
    cout << "}" << '\n';
  }
  cout << "]" << '\n';
}
template <class T>
void print_2darray(const char* s, T arr, int n) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (int i = 0, _stop = n; i < _stop; i++) {
    cout << i << " - {";
    for (int j = 0, _stop = (int)arr[i].size(); j < _stop; j++) {
      cout << arr[i][j] << (j == (int)arr[i].size() - 1 ? "" : ",");
    }
    cout << "}" << '\n';
  }
  cout << "]" << '\n';
}
template <class T>
void print_1darray(const char* s, T arr, int n) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (int i = 0, _stop = n; i < _stop; i++) {
    cout << arr[i] << (i == n - 1 ? "" : ",");
  }
  cout << '\n' << "]" << '\n';
}
template <class T>
void print_1darray(const char* s, T arr) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (int i = 0, _stop = arr.size(); i < _stop; i++) {
    cout << arr[i] << (i == (int)arr.size() - 1 ? "" : ",");
  }
  cout << '\n' << "]" << '\n';
}
template <class T>
void print_set(const char* s, set<T>& myset) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (__typeof(myset.begin()) it = myset.begin(); it != myset.end(); it++) {
    cout << *it << " ";
  }
  cout << '\n' << "]" << '\n';
}
template <class T>
void print_uset(const char* s, unordered_set<T>& myset) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (__typeof(myset.begin()) it = myset.begin(); it != myset.end(); it++) {
    cout << *it << " ";
  }
  cout << '\n' << "]" << '\n';
}
template <class T1, class T2>
void print_map(const char* s, map<T1, T2>& mymap) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (__typeof(mymap.begin()) it = mymap.begin(); it != mymap.end(); it++) {
    cout << "{" << it->f << "->" << it->s << "}" << '\n';
  }
  cout << "]" << '\n';
}
template <class T1, class T2>
void print_umap(const char* s, unordered_map<T1, T2>& mymap) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (__typeof(mymap.begin()) it = mymap.begin(); it != mymap.end(); it++) {
    cout << "{" << it->f << "->" << it->s << "}" << '\n';
  }
  cout << "]" << '\n';
}
const int N = 1000;
long long int MOD = 1e9 + 7, ans = 1, d, x, y;
int n;
long long int no[N][N];
int d1[N][N];
long double dist1[N][N];
int d2[N][N];
long double dist2[N][N];
int d3[N][N];
long double dist3[N][N];
int d4[N][N];
long double dist4[N][N];
int I, J, min_d;
long double min_ans, last_min_ans;
bool valid(int x) { return (x >= 0 && x < n); }
long long int mul(long long int a, long long int b) { return (a * b) % MOD; }
void set11223344() {
  for (int i = 0, _stop = n; i < _stop; i++) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      if (no[i][j] == 0) {
        continue;
      }
      long double temp = 0;
      d = min(d1[i][j], min(d2[i][j], min(d3[i][j], d4[i][j])));
      d--;
      if (valid(i - d - 1) && valid(j)) {
        temp -= dist1[i - d - 1][j];
      }
      temp += dist1[i][j];
      if (valid(i) && valid(j + d + 1)) {
        temp -= dist2[i][j + d + 1];
      }
      temp += dist2[i][j];
      if (valid(i + d + 1) && valid(j)) {
        temp -= dist3[i + d + 1][j];
      }
      temp += dist3[i][j];
      if (valid(i) && valid(j - d - 1)) {
        temp -= dist4[i][j - d - 1];
      }
      temp += dist4[i][j];
      temp -= 3 * log(no[i][j]);
      if (temp > min_ans) {
        min_ans = temp;
        min_d = d;
        I = i;
        J = j;
      }
    }
  }
  if (last_min_ans == min_ans) {
    return;
  }
  ans = no[I][J];
  for (int i = 1, _stop = min_d; i <= _stop; i++) {
    ans = mul(ans, no[I - i][J]);
    ans = mul(ans, no[I][J + i]);
    ans = mul(ans, no[I + i][J]);
    ans = mul(ans, no[I][J - i]);
  }
}
void set44() {
  for (int i = n - 1, _stop = 0; i >= _stop; i--) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      if (no[i][j]) {
        x = i;
        y = j - 1;
        if (valid(x) && valid(y)) {
          d4[i][j] += d4[x][y];
          dist4[i][j] += dist4[x][y];
        }
        d4[i][j]++;
        dist4[i][j] += log(no[i][j]);
      }
    }
  }
}
void set33() {
  for (int i = n - 1, _stop = 0; i >= _stop; i--) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      if (no[i][j]) {
        x = i + 1;
        y = j;
        if (valid(x) && valid(y)) {
          d3[i][j] += d3[x][y];
          dist3[i][j] += dist3[x][y];
        }
        d3[i][j]++;
        dist3[i][j] += log(no[i][j]);
      }
    }
  }
}
void set22() {
  for (int i = 0, _stop = n; i < _stop; i++) {
    for (int j = n - 1, _stop = 0; j >= _stop; j--) {
      if (no[i][j]) {
        x = i;
        y = j + 1;
        if (valid(x) && valid(y)) {
          d2[i][j] += d2[x][y];
          dist2[i][j] += dist2[x][y];
        }
        d2[i][j]++;
        dist2[i][j] += log(no[i][j]);
      }
    }
  }
}
void set11() {
  for (int i = 0, _stop = n; i < _stop; i++) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      if (no[i][j]) {
        x = i - 1;
        y = j;
        if (valid(x) && valid(y)) {
          d1[i][j] += d1[x][y];
          dist1[i][j] += dist1[x][y];
        }
        d1[i][j]++;
        dist1[i][j] += log(no[i][j]);
      }
    }
  }
}
void set1234() {
  for (int i = 0, _stop = n; i < _stop; i++) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      if (no[i][j] == 0) {
        continue;
      }
      long double temp = 0;
      d = min(d1[i][j], min(d2[i][j], min(d3[i][j], d4[i][j])));
      d--;
      if (valid(i - d - 1) && valid(j - d - 1)) {
        temp -= dist1[i - d - 1][j - d - 1];
      }
      temp += dist1[i][j];
      if (valid(i - d - 1) && valid(j + d + 1)) {
        temp -= dist2[i - d - 1][j + d + 1];
      }
      temp += dist2[i][j];
      if (valid(i + d + 1) && valid(j - d - 1)) {
        temp -= dist3[i + d + 1][j - d - 1];
      }
      temp += dist3[i][j];
      if (valid(i + d + 1) && valid(j + d + 1)) {
        temp -= dist4[i + d + 1][j + d + 1];
      }
      temp += dist4[i][j];
      temp -= 3 * log(no[i][j]);
      if (temp > min_ans) {
        min_ans = temp;
        min_d = d;
        I = i;
        J = j;
      }
    }
  }
  ans = no[I][J];
  for (int i = 1, _stop = min_d; i <= _stop; i++) {
    ans = mul(ans, no[I - i][J - i]);
    ans = mul(ans, no[I - i][J + i]);
    ans = mul(ans, no[I + i][J - i]);
    ans = mul(ans, no[I + i][J + i]);
  }
  last_min_ans = min_ans;
}
void set4() {
  for (int i = n - 1, _stop = 0; i >= _stop; i--) {
    for (int j = n - 1, _stop = 0; j >= _stop; j--) {
      if (no[i][j]) {
        x = i + 1;
        y = j + 1;
        if (valid(x) && valid(y)) {
          d4[i][j] += d4[x][y];
          dist4[i][j] += dist4[x][y];
        }
        d4[i][j]++;
        dist4[i][j] += log(no[i][j]);
      }
    }
  }
}
void set3() {
  for (int i = n - 1, _stop = 0; i >= _stop; i--) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      if (no[i][j]) {
        x = i + 1;
        y = j - 1;
        if (valid(x) && valid(y)) {
          d3[i][j] += d3[x][y];
          dist3[i][j] += dist3[x][y];
        }
        d3[i][j]++;
        dist3[i][j] += log(no[i][j]);
      }
    }
  }
}
void set2() {
  for (int i = 0, _stop = n; i < _stop; i++) {
    for (int j = n - 1, _stop = 0; j >= _stop; j--) {
      if (no[i][j]) {
        x = i - 1;
        y = j + 1;
        if (valid(x) && valid(y)) {
          d2[i][j] += d2[x][y];
          dist2[i][j] += dist2[x][y];
        }
        d2[i][j]++;
        dist2[i][j] += log(no[i][j]);
      }
    }
  }
}
void set1() {
  for (int i = 0, _stop = n; i < _stop; i++) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      if (no[i][j]) {
        x = i - 1;
        y = j - 1;
        if (valid(x) && valid(y)) {
          d1[i][j] += d1[x][y];
          dist1[i][j] += dist1[x][y];
        }
        d1[i][j]++;
        dist1[i][j] += log(no[i][j]);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  bool all_zero = true;
  char ch;
  for (int i = 0, _stop = n; i < _stop; i++) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      cin >> ch;
      no[i][j] = ch - 48;
      if (no[i][j]) {
        all_zero = false;
      }
    }
  }
  if (all_zero) {
    cout << 0;
    return 0;
  }
  set1();
  set2();
  set3();
  set4();
  set1234();
  fill_n(&d1[0][0], N * N, 0);
  fill_n(&dist1[0][0], N * N, 0);
  fill_n(&d2[0][0], N * N, 0);
  fill_n(&dist2[0][0], N * N, 0);
  fill_n(&d3[0][0], N * N, 0);
  fill_n(&dist3[0][0], N * N, 0);
  fill_n(&d4[0][0], N * N, 0);
  fill_n(&dist4[0][0], N * N, 0);
  set11();
  set22();
  set33();
  set44();
  set11223344();
  cout << ans;
  return 0;
}
