#include <bits/stdc++.h>
using namespace std;
int get() {
  char ch;
  while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
    ;
  if (ch == '-') {
    int s = 0;
    while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
    return -s;
  }
  int s = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
  return s;
}
const int N = 505;
const int mo = 1e+9 + 7;
long long f[N][N], g[N][N];
int n;
int a[N][N];
long long quickmi(long long x, long long tim) {
  long long ans = 1;
  for (; tim; tim /= 2, x = x * x % mo)
    if (tim & 1) ans = ans * x % mo;
  return ans;
}
int main() {
  n = get();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) a[i][j] = get();
  for (int i = 1; i <= n; i++) g[i][i] = f[i][i] = 1;
  for (int l = 2; l <= n; l++) {
    for (int x = 1; x <= n; x++) {
      int y = (x + l - 2) % n + 1;
      for (int z = x; z != y; z = z == n ? 1 : z + 1)
        g[x][y] = (g[x][y] + f[x][z] * f[z == n ? 1 : z + 1][y] % mo) % mo;
      for (int z = x; z != y; z = z == n ? 1 : z + 1)
        if (a[y][z]) f[x][y] = (f[x][y] + f[x][z] * g[z][y] % mo) % mo;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans = (ans + f[i][i == 1 ? n : i - 1]) % mo;
  ans = ans * quickmi(n, mo - 2) % mo;
  printf("%I64d\n", ans);
  return 0;
}
