#include <bits/stdc++.h>
using namespace std;
const int N = 1111;
const int MOD = 1e9 + 7;
int n;
int a[N][N];
int psh[10][N][N];
int psv[10][N][N];
int psa[10][N][N];
int psd[10][N][N];
int count(int k, int x, int y, int d, int t) {
  if (t == 0) {
    int res = psh[k][x][y + d];
    if (y - d > 0) res -= psh[k][x][y - d - 1];
    res += psv[k][x + d][y];
    if (x - d > 0) res -= psv[k][x - d - 1][y];
    res -= (a[x][y] == k);
    return res;
  } else {
    int res = psa[k][x + d][y + d];
    if (x - d > 0 && y - d > 0) res -= psa[k][x - d - 1][y - d - 1];
    res += psd[k][x + d][y - d];
    if (x - d > 0 && y + d < n - 1) res -= psd[k][x - d - 1][y + d + 1];
    res -= (a[x][y] == k);
    return res;
  }
}
void inith(int k, int a[N][N], int n) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      psh[k][i][j] = (a[i][j] == k);
      psa[k][i][j] = (a[i][j] == k);
      if (i > 0 && j > 0) psa[k][i][j] += psa[k][i - 1][j - 1];
      if (j > 0) psh[k][i][j] += psh[k][i][j - 1];
    }
  }
}
void initv(int k, int a[N][N], int n) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      psv[k][i][j] = (a[i][j] == k);
      if (i > 0) psv[k][i][j] += psv[k][i - 1][j];
    }
  }
}
void initd(int k, int a[N][N], int n) {
  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j >= 0; j--) {
      psd[k][i][j] = (a[i][j] == k);
      if (i > 0 && j < n - 1) psd[k][i][j] += psd[k][i - 1][j + 1];
    }
  }
}
void PS(int k, int a[N][N], int n) {
  inith(k, a, n);
  initd(k, a, n);
  initv(k, a, n);
}
vector<int> mx(10, 0);
vector<int> getConf(int x, int y, int d, int t) {
  vector<int> res(10, 0);
  for (int i = 0; i < 10; i++) {
    res[i] = count(i, x, y, d, t);
  }
  return res;
}
double ls[10];
const vector<int> &selectMax(const vector<int> &a, const vector<int> &b) {
  double log1 = 0;
  double log2 = 0;
  for (int i = 1; i < a.size(); i++) {
    log1 += ls[i] * a[i];
    log2 += ls[i] * b[i];
  }
  if (log1 < log2)
    return b;
  else
    return a;
}
int64_t binpow(int64_t a, int n) {
  if (n == 0) return 1;
  if (n % 2 == 1)
    return (binpow(a, n - 1) * a) % MOD;
  else {
    int64_t b = binpow(a, n / 2);
    return (b * b) % MOD;
  }
}
int main() {
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      char c;
      scanf("%c", &c);
      a[i][j] = c - '0';
    }
    scanf("\n");
  }
  for (int i = 0; i < 10; i++) {
    ls[i] = log(i);
    PS(i, a, n);
  }
  int64_t ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] == 0) continue;
      ans = 1;
      int l = 0;
      int r = min(n - 1 - i, n - 1 - j);
      r = min(r, i);
      r = min(r, j);
      while (l < r) {
        int m = (l + r + 1) / 2;
        int c = count(0, i, j, m, 0);
        if (c > 0)
          r = m - 1;
        else
          l = m;
      }
      mx = selectMax(mx, getConf(i, j, l, 0));
      l = 0;
      r = min(n - 1 - i, n - 1 - j);
      r = min(r, i);
      r = min(r, j);
      while (l < r) {
        int m = (l + r + 1) / 2;
        int c = count(0, i, j, m, 1);
        if (c > 0)
          r = m - 1;
        else
          l = m;
      }
      mx = selectMax(mx, getConf(i, j, l, 1));
    }
  }
  for (int i = 0; i < 10; i++) {
    ans *= binpow(i, mx[i]);
    ans %= MOD;
  }
  cout << ans;
  fflush(stdout);
  fflush(stderr);
  fprintf(stderr, "\n\n Execution time: %.4fs",
          double(clock()) / CLOCKS_PER_SEC);
  return 0;
  return 0;
}
