#include <bits/stdc++.h>
const int mu = 1000000007;
long long f[505][505], g[505][505];
int n, a[505][505];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; i++)
    if (a[i][i % n + 1]) g[i][i % n + 1] = 1;
  for (int i = 1; i <= n; i++) f[i][i] = 1;
  for (int l = 2; l < n; l++)
    for (int j = 1; j + l <= n; j++) {
      int t = j + l;
      for (int k = j + 1; k < t; k++)
        if (a[j][k])
          f[j][t] = (f[j][t] + 1ll * g[j][k] * (f[k][t] + g[k][t])) % mu;
      if (a[j][t])
        for (int k = j; k <= t; k++)
          g[j][t] = (g[j][t] +
                     1ll * (g[j][k] + f[j][k]) * (g[k + 1][t] + f[k + 1][t])) %
                    mu;
    }
  printf("%I64d\n", (f[1][n] + g[1][n]) % mu);
}
