#include <bits/stdc++.h>
using namespace std;
template <class T>
void print_2darray(const char* s, T arr, int n, int m) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (int i = 0, _stop = n; i < _stop; i++) {
    cout << "{";
    for (int j = 0, _stop = m; j < _stop; j++) {
      cout << arr[i][j] << (j == m - 1 ? "" : ",");
    }
    cout << "}" << '\n';
  }
  cout << "]" << '\n';
}
template <class T>
void print_2darray(const char* s, T arr, int n) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (int i = 0, _stop = n; i < _stop; i++) {
    cout << i << " - {";
    for (int j = 0, _stop = (int)arr[i].size(); j < _stop; j++) {
      cout << arr[i][j] << (j == (int)arr[i].size() - 1 ? "" : ",");
    }
    cout << "}" << '\n';
  }
  cout << "]" << '\n';
}
template <class T>
void print_1darray(const char* s, T arr, int n) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (int i = 0, _stop = n; i < _stop; i++) {
    cout << arr[i] << (i == n - 1 ? "" : ",");
  }
  cout << '\n' << "]" << '\n';
}
template <class T>
void print_1darray(const char* s, T arr) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (int i = 0, _stop = arr.size(); i < _stop; i++) {
    cout << arr[i] << (i == (int)arr.size() - 1 ? "" : ",");
  }
  cout << '\n' << "]" << '\n';
}
template <class T>
void print_set(const char* s, set<T>& myset) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (__typeof(myset.begin()) it = myset.begin(); it != myset.end(); it++) {
    cout << *it << " ";
  }
  cout << '\n' << "]" << '\n';
}
template <class T>
void print_uset(const char* s, unordered_set<T>& myset) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (__typeof(myset.begin()) it = myset.begin(); it != myset.end(); it++) {
    cout << *it << " ";
  }
  cout << '\n' << "]" << '\n';
}
template <class T1, class T2>
void print_map(const char* s, map<T1, T2>& mymap) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (__typeof(mymap.begin()) it = mymap.begin(); it != mymap.end(); it++) {
    cout << "{" << it->f << "->" << it->s << "}" << '\n';
  }
  cout << "]" << '\n';
}
template <class T1, class T2>
void print_umap(const char* s, unordered_map<T1, T2>& mymap) {
  cout << "> " << s << '\n';
  cout << "[" << '\n';
  for (__typeof(mymap.begin()) it = mymap.begin(); it != mymap.end(); it++) {
    cout << "{" << it->f << "->" << it->s << "}" << '\n';
  }
  cout << "]" << '\n';
}
const int N = 1000;
long long int MOD = 1e9 + 7, ans = 1, d, x, y;
int n;
long long int no[N][N];
int d1[N][N];
long double dist1[N][N];
int d2[N][N];
long double dist2[N][N];
int d3[N][N];
long double dist3[N][N];
int d4[N][N];
long double dist4[N][N];
int I, J, min_d;
long double min_ans, last_min_ans;
bool valid(int x) { return (x >= 0 && x < n); }
long long int mul(long long int a, long long int b) { return (a * b) % MOD; }
void set11223344() {
  for (int i = 0, _stop = n; i < _stop; i++) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      if (no[i][j] == 0) {
        continue;
      }
      long double temp = 0;
      d = min(d1[i][j], min(d2[i][j], min(d3[i][j], d4[i][j])));
      d--;
      if (valid(i - d - 1) && valid(j)) {
        temp -= dist1[i - d - 1][j];
      }
      temp += dist1[i][j];
      if (valid(i) && valid(j + d + 1)) {
        temp -= dist2[i][j + d + 1];
      }
      temp += dist2[i][j];
      if (valid(i + d + 1) && valid(j)) {
        temp -= dist3[i + d + 1][j];
      }
      temp += dist3[i][j];
      if (valid(i) && valid(j - d - 1)) {
        temp -= dist4[i][j - d - 1];
      }
      temp += dist4[i][j];
      temp -= 3 * log(no[i][j]);
      if (temp > min_ans) {
        min_ans = temp;
        min_d = d;
        I = i;
        J = j;
      }
    }
  }
  if (last_min_ans == min_ans) {
    return;
  }
  ans = no[I][J];
  for (int i = 1, _stop = min_d; i <= _stop; i++) {
    ans = mul(ans, no[I - i][J]);
    ans = mul(ans, no[I][J + i]);
    ans = mul(ans, no[I + i][J]);
    ans = mul(ans, no[I][J - i]);
  }
}
void set44() {
  for (int i = n - 1, _stop = 0; i >= _stop; i--) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      if (no[i][j]) {
        x = i;
        y = j - 1;
        if (valid(x) && valid(y)) {
          d4[i][j] += d4[x][y];
          dist4[i][j] += dist4[x][y];
        }
        d4[i][j]++;
        dist4[i][j] += log(no[i][j]);
      }
    }
  }
}
void set33() {
  for (int i = n - 1, _stop = 0; i >= _stop; i--) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      if (no[i][j]) {
        x = i + 1;
        y = j;
        if (valid(x) && valid(y)) {
          d3[i][j] += d3[x][y];
          dist3[i][j] += dist3[x][y];
        }
        d3[i][j]++;
        dist3[i][j] += log(no[i][j]);
      }
    }
  }
}
void set22() {
  for (int i = 0, _stop = n; i < _stop; i++) {
    for (int j = n - 1, _stop = 0; j >= _stop; j--) {
      if (no[i][j]) {
        x = i;
        y = j + 1;
        if (valid(x) && valid(y)) {
          d2[i][j] += d2[x][y];
          dist2[i][j] += dist2[x][y];
        }
        d2[i][j]++;
        dist2[i][j] += log(no[i][j]);
      }
    }
  }
}
void set11() {
  for (int i = 0, _stop = n; i < _stop; i++) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      if (no[i][j]) {
        x = i - 1;
        y = j;
        if (valid(x) && valid(y)) {
          d1[i][j] += d1[x][y];
          dist1[i][j] += dist1[x][y];
        }
        d1[i][j]++;
        dist1[i][j] += log(no[i][j]);
      }
    }
  }
}
void set1234() {
  for (int i = 0, _stop = n; i < _stop; i++) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      if (no[i][j] == 0) {
        continue;
      }
      long double temp = 0;
      d = min(d1[i][j], min(d2[i][j], min(d3[i][j], d4[i][j])));
      d--;
      if (valid(i - d - 1) && valid(j - d - 1)) {
        temp -= dist1[i - d - 1][j - d - 1];
      }
      temp += dist1[i][j];
      if (valid(i - d - 1) && valid(j + d + 1)) {
        temp -= dist2[i - d - 1][j + d + 1];
      }
      temp += dist2[i][j];
      if (valid(i + d + 1) && valid(j - d - 1)) {
        temp -= dist3[i + d + 1][j - d - 1];
      }
      temp += dist3[i][j];
      if (valid(i + d + 1) && valid(j + d + 1)) {
        temp -= dist4[i + d + 1][j + d + 1];
      }
      temp += dist4[i][j];
      temp -= 3 * log(no[i][j]);
      if (temp > min_ans) {
        min_ans = temp;
        min_d = d;
        I = i;
        J = j;
      }
    }
  }
  ans = no[I][J];
  for (int i = 1, _stop = min_d; i <= _stop; i++) {
    ans = mul(ans, no[I - i][J - i]);
    ans = mul(ans, no[I - i][J + i]);
    ans = mul(ans, no[I + i][J - i]);
    ans = mul(ans, no[I + i][J + i]);
  }
  last_min_ans = min_ans;
}
void set4() {
  for (int i = n - 1, _stop = 0; i >= _stop; i--) {
    for (int j = n - 1, _stop = 0; j >= _stop; j--) {
      if (no[i][j]) {
        x = i + 1;
        y = j + 1;
        if (valid(x) && valid(y)) {
          d4[i][j] += d4[x][y];
          dist4[i][j] += dist4[x][y];
        }
        d4[i][j]++;
        dist4[i][j] += log(no[i][j]);
      }
    }
  }
}
void set3() {
  for (int i = n - 1, _stop = 0; i >= _stop; i--) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      if (no[i][j]) {
        x = i + 1;
        y = j - 1;
        if (valid(x) && valid(y)) {
          d3[i][j] += d3[x][y];
          dist3[i][j] += dist3[x][y];
        }
        d3[i][j]++;
        dist3[i][j] += log(no[i][j]);
      }
    }
  }
}
void set2() {
  for (int i = 0, _stop = n; i < _stop; i++) {
    for (int j = n - 1, _stop = 0; j >= _stop; j--) {
      if (no[i][j]) {
        x = i - 1;
        y = j + 1;
        if (valid(x) && valid(y)) {
          d2[i][j] += d2[x][y];
          dist2[i][j] += dist2[x][y];
        }
        d2[i][j]++;
        dist2[i][j] += log(no[i][j]);
      }
    }
  }
}
void set1() {
  for (int i = 0, _stop = n; i < _stop; i++) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      if (no[i][j]) {
        x = i - 1;
        y = j - 1;
        if (valid(x) && valid(y)) {
          d1[i][j] += d1[x][y];
          dist1[i][j] += dist1[x][y];
        }
        d1[i][j]++;
        dist1[i][j] += log(no[i][j]);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  bool all_zero = true;
  char ch;
  for (int i = 0, _stop = n; i < _stop; i++) {
    for (int j = 0, _stop = n; j < _stop; j++) {
      cin >> ch;
      no[i][j] = ch - 48;
      if (no[i][j]) {
        all_zero = false;
      }
    }
  }
  if (all_zero) {
    cout << 0;
    return 0;
  }
  set1();
  set2();
  set3();
  set4();
  set1234();
  fill_n(&d1[0][0], N * N, 0);
  fill_n(&dist1[0][0], N * N, 0);
  fill_n(&d2[0][0], N * N, 0);
  fill_n(&dist2[0][0], N * N, 0);
  fill_n(&d3[0][0], N * N, 0);
  fill_n(&dist3[0][0], N * N, 0);
  fill_n(&d4[0][0], N * N, 0);
  fill_n(&dist4[0][0], N * N, 0);
  set11();
  set22();
  set33();
  set44();
  set11223344();
  cout << ans;
  return 0;
}
