#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 10, MOD = 1e9 + 7;
int dp[N][N], pd[N][N], adj[N][N], n;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) scanf("%d", &adj[i][j]);
  for (int i = 0; i < n; i++) dp[i][i] = pd[i][i] = 1;
  for (int len = 2; len <= n; len++) {
    for (int l = 0; l < n; l++) {
      int r = (l + len - 1 + n) % n;
      for (int i = l; i != r; i = (i + 1) % n) {
        if (adj[l][r])
          pd[l][r] =
              (pd[l][r] + 1ll * dp[l][i] * dp[(i + 1) % n][r] % MOD) % MOD;
        dp[l][r] =
            (dp[l][r] + 1ll * pd[l][(i + 1) % n] * dp[(i + 1) % n][r] % MOD) %
            MOD;
      }
    }
  }
  printf("%d\n", dp[0][n - 1]);
  return 0;
}
