#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 510;
const int mod = 1e9 + 7;
long long pw(long long a, long long b, long long md = mod) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (a * res) % md;
    }
    a = (a * a) % md;
    b >>= 1;
  }
  return (res);
}
int dp[maxn][maxn];
int ans[maxn][maxn];
int n, m;
int e[maxn][maxn];
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> e[i][j];
  for (int i = 0; i < n; i++) dp[i][i] = ans[i][i] = 1;
  for (int i = 0; i < n - 1; i++) ans[i][i + 1] = dp[i][i + 1] = e[i][i + 1];
  for (int sz = 2; sz < n; sz++) {
    for (int i = sz; i < n; i++) {
      for (int j = i - sz; j < i; j++) {
        ans[i - sz][i] =
            (ans[i - sz][i] + dp[i - sz][j] * 1ll * ans[j][i]) % mod;
        dp[i - sz][i] =
            e[i - sz][i] *
            ((dp[i - sz][i] + ans[i - sz][j] * 1ll * ans[j + 1][i]) % mod);
      }
      ans[i - sz][i] = (ans[i - sz][i] + dp[i - sz][i]) % mod;
    }
  }
  cout << ans[0][n - 1];
  return (0);
}
