#include <bits/stdc++.h>
using namespace std;
constexpr double log23 =
    1.58496250072115618147405857740750434459187090396881103515625;
bool cmp_logs(const int a2, const int a3, const int b2, const int b3) {
  return (double)a2 + log23 * a3 < (double)b2 + log23 * b3;
}
using sq_mat = vector<vector<int>>;
vector<vector<int>> get_sq_mat(const int n) {
  return vector<vector<int>>(n, vector<int>(n, 0));
}
constexpr int mod = 1000 * 1000 * 1000 + 7;
template <int baza>
long long exp_mod(long long e) {
  long long tmp = baza, rez = 1;
  for (; e; e /= 2, tmp *= tmp, tmp %= mod) {
    if (e % 2) {
      rez *= tmp;
      rez %= mod;
    }
  }
  return rez;
}
void pr(const sq_mat& s, const string& name) {
  cout << name << endl;
  for (const auto x : s) {
    for (const auto y : x) {
      cout << y << ' ';
    }
    cout << endl;
  }
  cout << endl;
}
int main() {
  int n;
  cin >> n;
  sq_mat v = get_sq_mat(n + 2);
  {
    string str;
    for (int i = 1; i <= n; ++i) {
      cin >> ws >> str;
      transform(begin(str), end(str), begin(v[i]) + 1,
                [](const char ch) { return ch - '0'; });
    }
  }
  sq_mat nr_l = get_sq_mat(n + 2), nr_ul = get_sq_mat(n + 2),
         nr_u = get_sq_mat(n + 2), nr_ur = get_sq_mat(n + 2),
         nr_r = get_sq_mat(n + 2), nr_dr = get_sq_mat(n + 2),
         nr_d = get_sq_mat(n + 2), nr_dl = get_sq_mat(n + 2),
         sum_2_l = get_sq_mat(n + 2), sum_2_ul = get_sq_mat(n + 2),
         sum_2_u = get_sq_mat(n + 2), sum_2_ur = get_sq_mat(n + 2),
         sum_3_l = get_sq_mat(n + 2), sum_3_ul = get_sq_mat(n + 2),
         sum_3_u = get_sq_mat(n + 2), sum_3_ur = get_sq_mat(n + 2);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (v[i][j] == 0) {
        nr_l[i][j] = nr_ul[i][j] = nr_u[i][j] = nr_ur[i][j] = 0;
      } else {
        nr_l[i][j] = nr_l[i][j - 1] + 1;
        nr_ul[i][j] = nr_ul[i - 1][j - 1] + 1;
        nr_u[i][j] = nr_u[i - 1][j] + 1;
        nr_ur[i][j] = nr_ur[i - 1][j + 1] + 1;
      }
    }
  }
  for (int i = n; i >= 1; --i) {
    for (int j = n; j >= 1; --j) {
      if (v[i][j] == 0) {
        nr_r[i][j] = nr_dr[i][j] = nr_d[i][j] = nr_dl[i][j] = 0;
      } else {
        nr_r[i][j] = nr_r[i][j + 1] + 1;
        nr_dr[i][j] = nr_dr[i + 1][j + 1] + 1;
        nr_d[i][j] = nr_d[i + 1][j] + 1;
        nr_dl[i][j] = nr_dl[i + 1][j - 1] + 1;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (v[i][j] == 2) {
        ++sum_2_l[i][j], ++sum_2_ul[i][j], ++sum_2_u[i][j], ++sum_2_ur[i][j];
      } else if (v[i][j] == 3) {
        ++sum_3_l[i][j], ++sum_3_ul[i][j], ++sum_3_u[i][j], ++sum_3_ur[i][j];
      }
      sum_2_l[i][j] += sum_2_l[i][j - 1];
      sum_3_l[i][j] += sum_3_l[i][j - 1];
      sum_2_ul[i][j] += sum_2_ul[i - 1][j - 1];
      sum_3_ul[i][j] += sum_3_ul[i - 1][j - 1];
      sum_2_u[i][j] += sum_2_u[i - 1][j];
      sum_3_u[i][j] += sum_3_u[i - 1][j];
      sum_2_ur[i][j] += sum_2_ur[i - 1][j + 1];
      sum_3_ur[i][j] += sum_3_ur[i - 1][j + 1];
    }
  }
  int best_2 = -1, best_3 = -1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      const int d = min({nr_u[i][j], nr_l[i][j], nr_d[i][j], nr_r[i][j]});
      if (d == 0) {
        continue;
      }
      const int cur_2 = sum_2_u[i + d - 1][j] - sum_2_u[i - d][j] +
                        sum_2_l[i][j + d - 1] - sum_2_l[i][j - d] -
                        (v[i][j] == 2);
      const int cur_3 = sum_3_u[i + d - 1][j] - sum_3_u[i - d][j] +
                        sum_3_l[i][j + d - 1] - sum_3_l[i][j - d] -
                        (v[i][j] == 3);
      if (cmp_logs(best_2, best_3, cur_2, cur_3)) {
        best_2 = cur_2, best_3 = cur_3;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      const int d = min({nr_ul[i][j], nr_ur[i][j], nr_dl[i][j], nr_dr[i][j]});
      if (d == 0) {
        continue;
      }
      const int cur_2 = sum_2_ul[i + d - 1][j + d - 1] -
                        sum_2_ul[i - d][j - d] +
                        sum_2_ur[i + d - 1][j - d + 1] -
                        sum_2_ur[i - d][j + d] - (v[i][j] == 2);
      const int cur_3 = sum_3_ul[i + d - 1][j + d - 1] -
                        sum_3_ul[i - d][j - d] +
                        sum_3_ur[i + d - 1][j - d + 1] -
                        sum_3_ur[i - d][j + d] - (v[i][j] == 3);
      if (cmp_logs(best_2, best_3, cur_2, cur_3)) {
        best_2 = cur_2, best_3 = cur_3;
      }
    }
  }
  if (best_2 < 0 || best_3 < 0) {
    cout << 0 << endl;
  } else {
    cout << (exp_mod<2>(best_2) * exp_mod<3>(best_3)) % mod << '\n';
  }
  return 0;
}
