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>
static int field[1005][1005];
static int rightDown[1005][1005];
static int rightUp[1005][1005];
static int leftDown[1005][1005];
static int leftUp[1005][1005];
static int right[1005][1005];
static int left[1005][1005];
static int down[1005][1005];
static int up[1005][1005];
static double rightDownLogs[1005][1005];
static double rightUpLogs[1005][1005];
static double leftDownLogs[1005][1005];
static double leftUpLogs[1005][1005];
static double rightLogs[1005][1005];
static double leftLogs[1005][1005];
static double downLogs[1005][1005];
static double upLogs[1005][1005];
void calculatePartialLogs(int n) {
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      rightDown[i][j] =
          field[i - 1][j - 1] == 0 ? 0 : rightDown[i - 1][j - 1] + 1;
      right[i][j] = field[i - 1][j - 1] == 0 ? 0 : right[i][j - 1] + 1;
      down[i][j] = field[i - 1][j - 1] == 0 ? 0 : down[i - 1][j] + 1;
      rightDownLogs[i][j] =
          field[i - 1][j - 1] == 0
              ? rightDownLogs[i - 1][j - 1]
              : rightDownLogs[i - 1][j - 1] + log(field[i - 1][j - 1]);
      rightLogs[i][j] = field[i - 1][j - 1] == 0
                            ? rightLogs[i][j - 1]
                            : rightLogs[i][j - 1] + log(field[i - 1][j - 1]);
      downLogs[i][j] = field[i - 1][j - 1] == 0
                           ? downLogs[i - 1][j]
                           : downLogs[i - 1][j] + log(field[i - 1][j - 1]);
    }
  }
  for (int i = n; i >= 1; --i) {
    for (int j = 1; j <= n; ++j) {
      rightUp[i][j] = field[i - 1][j - 1] == 0 ? 0 : rightUp[i + 1][j - 1] + 1;
      up[i][j] = field[i - 1][j - 1] == 0 ? 0 : up[i + 1][j] + 1;
      rightUpLogs[i][j] =
          field[i - 1][j - 1] == 0
              ? rightUpLogs[i + 1][j - 1]
              : rightUpLogs[i + 1][j - 1] + log(field[i - 1][j - 1]);
      upLogs[i][j] = field[i - 1][j - 1] == 0
                         ? upLogs[i + 1][j]
                         : upLogs[i + 1][j] + log(field[i - 1][j - 1]);
    }
  }
  for (int i = n; i >= 1; --i) {
    for (int j = n; j >= 1; --j) {
      leftUp[i][j] = field[i - 1][j - 1] == 0 ? 0 : leftUp[i + 1][j + 1] + 1;
      leftUpLogs[i][j] =
          field[i - 1][j - 1] == 0
              ? leftUpLogs[i + 1][j + 1]
              : leftUpLogs[i + 1][j + 1] + log(field[i - 1][j - 1]);
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = n; j >= 1; --j) {
      leftDown[i][j] =
          field[i - 1][j - 1] == 0 ? 0 : leftDown[i - 1][j + 1] + 1;
      left[i][j] = field[i - 1][j - 1] == 0 ? 0 : left[i][j + 1] + 1;
      leftDownLogs[i][j] =
          field[i - 1][j - 1] == 0
              ? leftDownLogs[i - 1][j + 1]
              : leftDownLogs[i - 1][j + 1] + log(field[i - 1][j - 1]);
      leftLogs[i][j] = field[i - 1][j - 1] == 0
                           ? leftLogs[i][j + 1]
                           : leftLogs[i][j + 1] + log(field[i - 1][j - 1]);
    }
  }
}
static long long calculateResult(int x, int y, int cross, int d) {
  long long res = field[x][y];
  if (cross == 1) {
    for (int i = 1; i < d; ++i) {
      res *= static_cast<long long>(field[x - i][y] * field[x + i][y] *
                                    field[x][y - i] * field[x][y + i]);
      res %= 1000000007LL;
    }
  } else if (cross == 2) {
    for (int i = 1; i < d; ++i) {
      res *= static_cast<long long>(field[x - i][y - i] * field[x + i][y - i] *
                                    field[x - i][y + i] * field[x + i][y + i]);
      res %= 1000000007LL;
    }
  }
  return res;
}
static void destroyCross(int n) {
  double maxLog = 0;
  int maxX = 0;
  int maxY = 0;
  int whichCross = 0;
  int maxD = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (field[i][j] > 0) {
        if (log(field[i][j]) > maxLog) {
          maxLog = log(field[i][j]);
          maxX = i;
          maxY = j;
          whichCross = 0;
          maxD = 0;
        }
        int d = SHRT_MAX;
        d = std::min(d, right[i + 1][j + 1]);
        d = std::min(d, left[i + 1][j + 1]);
        d = std::min(d, down[i + 1][j + 1]);
        d = std::min(d, up[i + 1][j + 1]);
        double prodLog = 0;
        prodLog += (rightLogs[i + 1][j + 1] - rightLogs[i + 1][j - d + 1]);
        prodLog += (leftLogs[i + 1][j + 1] - leftLogs[i + 1][j + d + 1]);
        prodLog += (downLogs[i + 1][j + 1] - downLogs[i - d + 1][j + 1]);
        prodLog += (upLogs[i + 1][j + 1] - upLogs[i + d + 1][j + 1]);
        prodLog -= (3 * log(field[i][j]));
        if (prodLog > maxLog) {
          maxLog = prodLog;
          maxX = i;
          maxY = j;
          whichCross = 1;
          maxD = d;
        }
        d = SHRT_MAX;
        d = std::min(d, rightDown[i + 1][j + 1]);
        d = std::min(d, leftDown[i + 1][j + 1]);
        d = std::min(d, rightUp[i + 1][j + 1]);
        d = std::min(d, leftUp[i + 1][j + 1]);
        prodLog = 0;
        prodLog +=
            (rightDownLogs[i + 1][j + 1] - rightDownLogs[i - d + 1][j - d + 1]);
        prodLog +=
            (leftDownLogs[i + 1][j + 1] - leftDownLogs[i - d + 1][j + d + 1]);
        prodLog +=
            (rightUpLogs[i + 1][j + 1] - rightUpLogs[i + d + 1][j - d + 1]);
        prodLog +=
            (leftUpLogs[i + 1][j + 1] - leftUpLogs[i + d + 1][j + d + 1]);
        prodLog -= (3 * log(field[i][j]));
        if (prodLog > maxLog) {
          maxLog = prodLog;
          maxX = i;
          maxY = j;
          whichCross = 2;
          maxD = d;
        }
      }
    }
  }
  long long max = calculateResult(maxX, maxY, whichCross, maxD);
  printf("%lld\n", max);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    char c;
    scanf("%c", &c);
    for (int j = 0; j < n; ++j) {
      char c;
      scanf("%c", &c);
      field[i][j] = static_cast<int>(c) - static_cast<int>('0');
    }
  }
  calculatePartialLogs(n);
  destroyCross(n);
  return 0;
}
