#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
const int mod = 1e9 + 7;
int n, a[MAXN][MAXN];
long long f[MAXN][MAXN], g[MAXN][MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      scanf("%d", &a[i][j]);
      a[i + n][j + n] = a[i + n][j] = a[i][j + n] = a[i][j];
    }
  for (int i = 1; i <= n + 1; i++) f[i][i] = g[i][i] = 1;
  for (int i = 1; i <= n; i++) f[i][i + 1] = g[i][i + 1] = a[i][i + 1];
  for (int l = 3; l <= n; l++)
    for (int i = 1; i <= n - l + 2; i++) {
      int j = i + l - 1;
      for (int k = i + 1; k < j; k++)
        g[i][j] = (g[i][j] + g[i][k] * f[k][j] % mod) % mod;
      if (a[i][j])
        for (int k = i; k < j; k++) {
          g[i][j] = (g[i][j] + g[i][k] * g[k + 1][j] % mod) % mod;
          f[i][j] = (f[i][j] + g[i][k] * g[k + 1][j] % mod) % mod;
        }
    }
  printf("%lld", g[1][n] % mod);
  return 0;
}
