#include <bits/stdc++.h>
using namespace std;
const long long maxn = 505, mod = 1e9 + 7;
long long dp[maxn][maxn], a[maxn][maxn], pd[maxn][maxn];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    dp[i][i] = 1;
    for (long long j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  for (long long t = 1; t < n - 1; t++) {
    for (long long l = 0; l < n; l++) {
      long long r = (l + t) % n;
      if (r < l) {
        for (long long i = l; i < n; i++) {
          pd[l][r] += dp[l][i] * dp[(i + 1) % n][r] % mod;
          pd[l][r] %= mod;
        }
        for (long long i = 0; i < r; i++) {
          pd[l][r] += dp[l][i] * dp[i + 1][r] % mod;
          pd[l][r] %= mod;
        }
        for (long long i = r; ~i; i--) {
          dp[l][r] += a[l][i] * dp[i][r] * pd[l][i] % mod;
          dp[l][r] %= mod;
        }
        for (long long i = n - 1; i > l; i--) {
          dp[l][r] += a[l][i] * dp[i][r] * pd[l][i] % mod;
          dp[l][r] %= mod;
        }
      } else {
        for (long long i = l; i < r; i++) {
          pd[l][r] += dp[l][i] * dp[i + 1][r] % mod;
          pd[l][r] %= mod;
        }
        for (long long i = r; i > l; i--) {
          dp[l][r] += a[l][i] * dp[i][r] * pd[l][i] % mod;
          dp[l][r] %= mod;
        }
      }
    }
  }
  long long ans = 0;
  for (long long i = 1; i < n; i++) {
    for (long long j = i; j < n; j++) {
      ans += a[0][i] * dp[1][i] * dp[i][j] % mod * dp[(j + 1) % n][0] % mod;
      ans %= mod;
    }
  }
  cout << ans;
}
