#include <bits/stdc++.h>
using namespace std;
char grid[1005][1005];
int n;
int zeros[8][1005][2005];
const double lookup[] = {-9e99, 0, 1, 1.5849625007211563, 2};
const long long mod = 1000000007;
long long power2mod[2005], power3mod[2005];
int sums[2][4][1005][2005];
void genpowers() {
  power2mod[0] = 1;
  power3mod[0] = 1;
  for (int i = 1; i < 2005; i++) {
    power2mod[i] = (2 * power2mod[i - 1]) % mod;
    power3mod[i] = (3 * power3mod[i - 1]) % mod;
  }
}
void gensums() {
  for (int i = 1; i <= n; i++) {
    for (int y = 1; y <= n; y++) {
      sums[0][0][i][y] = sums[0][0][i - 1][y] + (int)(grid[i][y] == '2');
      sums[1][0][i][y] = sums[1][0][i - 1][y] + (int)(grid[i][y] == '3');
      sums[0][1][i][y] = sums[0][1][i][y - 1] + (int)(grid[i][y] == '2');
      sums[1][1][i][y] = sums[1][1][i][y - 1] + (int)(grid[i][y] == '3');
      sums[0][2][i][i + y] =
          sums[0][2][i - 1][i + y] + (int)(grid[i][y] == '2');
      sums[1][2][i][i + y] =
          sums[1][2][i - 1][i + y] + (int)(grid[i][y] == '3');
      sums[0][3][i][i - y + n] =
          sums[0][3][i - 1][i - y + n] + (int)(grid[i][y] == '2');
      sums[1][3][i][i - y + n] =
          sums[1][3][i - 1][i - y + n] + (int)(grid[i][y] == '3');
    }
  }
}
double getplusval(int x, int y, int r) {
  int no2 = sums[0][0][x + r][y] - sums[0][0][x - r - 1][y] +
            sums[0][1][x][y + r] - sums[0][1][x][y - r - 1];
  int no3 = sums[1][0][x + r][y] - sums[1][0][x - r - 1][y] +
            sums[1][1][x][y + r] - sums[1][1][x][y - r - 1];
  if (grid[x][y] == '2') no2--;
  if (grid[x][y] == '3') no3--;
  return (double)no2 + 1.5849625007211563 * no3;
}
long long getplusansw(int x, int y, int r) {
  int no2 = sums[0][0][x + r][y] - sums[0][0][x - r - 1][y] +
            sums[0][1][x][y + r] - sums[0][1][x][y - r - 1];
  int no3 = sums[1][0][x + r][y] - sums[1][0][x - r - 1][y] +
            sums[1][1][x][y + r] - sums[1][1][x][y - r - 1];
  if (grid[x][y] == '2') no2--;
  if (grid[x][y] == '3') no3--;
  return power2mod[no2] * power3mod[no3] % mod;
}
double getxval(int x, int y, int r) {
  int no2 = sums[0][2][x + r][x + y] - sums[0][2][x - r - 1][x + y] +
            sums[0][3][x + r][x - y + n] - sums[0][3][x - r - 1][x - y + n];
  int no3 = sums[1][2][x + r][x + y] - sums[1][2][x - r - 1][x + y] +
            sums[1][3][x + r][x - y + n] - sums[1][3][x - r - 1][x - y + n];
  if (grid[x][y] == '2') no2--;
  if (grid[x][y] == '3') no3--;
  return (double)no2 + 1.5849625007211563 * no3;
}
long long getxansw(int x, int y, int r) {
  int no2 = sums[0][2][x + r][x + y] - sums[0][2][x - r - 1][x + y] +
            sums[0][3][x + r][x - y + n] - sums[0][3][x - r - 1][x - y + n];
  int no3 = sums[1][2][x + r][x + y] - sums[1][2][x - r - 1][x + y] +
            sums[1][3][x + r][x - y + n] - sums[1][3][x - r - 1][x - y + n];
  if (grid[x][y] == '2') no2--;
  if (grid[x][y] == '3') no3--;
  return power2mod[no2] * power3mod[no3] % mod;
}
void gencrosses() {
  for (int i = 1; i <= n; i++) {
    for (int y = 1; y <= n; y++) {
      if (grid[i][y] != '0') zeros[0][i][y] = 1 + zeros[0][i - 1][y];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int y = 1; y <= n; y++) {
      if (grid[i][y] != '0') zeros[1][i][y] = 1 + zeros[1][i][y - 1];
    }
  }
  for (int i = n; i > 0; i--) {
    for (int y = n; y > 0; y--) {
      if (grid[i][y] != '0') zeros[2][i][y] = 1 + zeros[2][i + 1][y];
    }
  }
  for (int i = n; i > 0; i--) {
    for (int y = n; y > 0; y--) {
      if (grid[i][y] != '0') zeros[3][i][y] = 1 + zeros[3][i][y + 1];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int y = 1; y <= n; y++) {
      if (grid[i][y] != '0') zeros[4][i][i + y] = 1 + zeros[4][i - 1][i + y];
    }
  }
  for (int i = n; i > 0; i--) {
    for (int y = n; y > 0; y--) {
      if (grid[i][y] != '0') zeros[5][i][i + y] = 1 + zeros[5][i + 1][i + y];
    }
  }
  for (int i = 0; i <= n; i++) {
    for (int y = 0; y <= n; y++) {
      if (grid[i][y] != '0')
        zeros[6][i][i - y + n] = 1 + zeros[6][i - 1][i - y + n];
    }
  }
  for (int i = n; i > 0; i--) {
    for (int y = n; y > 0; y--) {
      if (grid[i][y] != '0')
        zeros[7][i][i - y + n] = 1 + zeros[7][i + 1][i - y + n];
    }
  }
}
void readinput() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf(" %s", &grid[i][1]);
  }
  for (int i = 0; i <= n + 1; i++) {
    grid[i][0] = '0';
    grid[0][i] = '0';
    grid[n + 1][i] = '0';
    grid[i][n + 1] = '0';
  }
}
void makeanswer() {
  long long answ = 0;
  double best = -999999999999.;
  for (int i = 1; i <= n; i++) {
    for (int y = 1; y <= n; y++) {
      if (grid[i][y] != '0') {
        int m = min(min(zeros[0][i][y], zeros[1][i][y]),
                    min(zeros[2][i][y], zeros[3][i][y]));
        int b = min(min(zeros[4][i][i + y], zeros[5][i][i + y]),
                    min(zeros[6][i][i - y + n], zeros[7][i][i - y + n]));
        double plusval = getplusval(i, y, m - 1);
        double xval = getxval(i, y, b - 1);
        if (plusval > best) {
          best = plusval;
          answ = getplusansw(i, y, m - 1);
        }
        if (xval > best) {
          best = xval;
          answ = getxansw(i, y, b - 1);
        }
      }
    }
  }
  printf("%lld\n", answ);
}
int main() {
  genpowers();
  readinput();
  gencrosses();
  gensums();
  makeanswer();
  return 0;
}
