#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
template <class C, class I>
bool has(C con, I item) {
  return con.find(item) != con.end();
}
const long long MOD = 1000LL * 1000 * 1000 + 7;
const int maxN = 1000 + 8;
int N;
int grid[3][maxN][maxN];
int maxSize[maxN][maxN];
double val[maxN][maxN];
double sumR[maxN][maxN];
double sumC[maxN][maxN];
double trans[4] = {-1, 0, 1, 1.584962500721156};
bool valid(int r, int c) { return r >= 0 && r < N && c >= 0 && c < N; }
void findSize(int g, int r, int c, int dr, int dc) {
  int cur = 0;
  while (valid(r, c)) {
    cur = grid[g][r][c] ? cur + 1 : 0;
    maxSize[r][c] = min(maxSize[r][c], cur);
    r += dr;
    c += dc;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  cin.ignore(42, '\n');
  for (int r = (0); r < (N); r++) {
    string input;
    getline(cin, input);
    for (int c = (0); c < (N); c++) grid[0][r][c] = input[c] - '0';
  }
  for (int r = (0); r < (N); r++)
    for (int c = (0); c < (N); c++) {
      int g = ((r + c) & 1) ? 1 : 2;
      grid[g][(r + c) / 2][(N - r + c) / 2] = grid[0][r][c];
    }
  double best = -1e10;
  int bg = -1, br = 0, bc = 0, bms = 0;
  for (int g = (0); g < (3); g++) {
    for (int r = (0); r < (N); r++)
      for (int c = (0); c < (N); c++) val[r][c] = trans[grid[g][r][c]];
    for (int r = (0); r < (N); r++)
      for (int c = (0); c < (N); c++) maxSize[r][c] = N;
    for (int r = (0); r < (N); r++) findSize(g, r, 0, 0, 1);
    for (int r = (0); r < (N); r++) findSize(g, r, N - 1, 0, -1);
    for (int c = (0); c < (N); c++) findSize(g, 0, c, 1, 0);
    for (int c = (0); c < (N); c++) findSize(g, N - 1, c, -1, 0);
    for (int r = (0); r < (N); r++) sumR[r][0] = val[r][0];
    for (int r = (0); r < (N); r++)
      for (int c = (1); c < (N); c++) sumR[r][c] = sumR[r][c - 1] + val[r][c];
    for (int c = (0); c < (N); c++) sumC[0][c] = val[0][c];
    for (int r = (1); r < (N); r++)
      for (int c = (0); c < (N); c++) sumC[r][c] = sumC[r - 1][c] + val[r][c];
    for (int r = (0); r < (N); r++)
      for (int c = (0); c < (N); c++)
        if (maxSize[r][c] > 0) {
          int s = maxSize[r][c];
          double tmp = -val[r][c];
          tmp += sumR[r][c + s - 1];
          if (c - s >= 0) tmp -= sumR[r][c - s];
          tmp += sumC[r + s - 1][c];
          if (r - s >= 0) tmp -= sumC[r - s][c];
          if (tmp > best) {
            best = tmp;
            bg = g, br = r, bc = c, bms = maxSize[r][c];
          }
        }
  }
  long long result = 0;
  result = grid[bg][br][bc];
  for (int i = (1); i < (bms); i++) {
    result = result * grid[bg][br - i][bc] * grid[bg][br][bc - i] *
             grid[bg][br + i][bc] * grid[bg][br][bc + i] % MOD;
  }
  cout << result << endl;
}
