#include <bits/stdc++.h>
using namespace std;
const int nsz = 5e2, mod = 1e9 + 7;
bool g[nsz + 5][nsz + 5];
int n, f[nsz + 5][nsz + 5], dp[nsz + 5][nsz + 5], ans;
int inline nxt(int id) { return id == n ? 1 : id + 1; }
void inline upd(int &a, int del) {
  a += del;
  if (a > mod) {
    a -= mod;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      cin >> g[i][j];
      g[i][j] &= j > i;
    }
    dp[i][i] = f[i][i] = 1;
  }
  for (int len = 1; len <= n - 1; ++len) {
    for (int l = 1; l <= n; ++l) {
      int r = ((l + len - 1) % n + n) % n + 1;
      if (g[l][r]) {
        for (int k = l; k != r; k = nxt(k)) {
          upd(f[l][r], (long long)dp[l][k] * dp[nxt(k)][r] % mod);
        }
      }
      for (int k = l; k != r; k = nxt(k)) {
        upd(dp[l][r], (long long)dp[l][k] * f[k][r] % mod);
      }
      if (len == n - 1) {
        upd(ans, dp[l][r]);
      }
    }
  }
  cout << ans << '\n';
}
