#include <bits/stdc++.h>
using namespace std;
int n;
bool a[505][505];
int dp[505][505][2][2];
const int mod = 1e9 + 7;
int cal(int l, int r, bool allow, bool con) {
  int &ret = dp[l][r][allow][con];
  if (ret != -1) return ret;
  ret = 0;
  if (l + 1 == r) {
    if (allow == con) return ret = 1;
    return ret = a[l][r];
  }
  if (l == r) return ret = 1;
  if (allow) {
    if (!con) {
      if (a[l][r]) ret = (ret + cal(l, r, allow, 1)) % mod;
      for (int mid = l + 1; mid <= r - 1; mid++) {
        if (a[l][mid])
          ret = (ret + 1LL * cal(l, mid, 1, 1) * cal(mid, r, 1, 0)) % mod;
      }
    } else {
      for (int mid = l + 1; mid <= r - 1; mid++) {
        if (a[l][mid])
          ret = (ret + 1LL * cal(l, mid, 1, 1) * cal(mid, r, 0, 0)) % mod;
        if (a[mid][r])
          ret = (ret + 1LL * cal(l + 1, mid, 1, 0) * cal(mid, r, 1, 1)) % mod;
      }
    }
  } else {
    for (int mid = l + 1; mid <= r - 1; mid++) {
      if (a[l][mid])
        ret = (ret + 1LL * cal(l, mid, 1, 1) * cal(mid, r, 0, 0)) % mod;
      if (a[mid][r])
        ret = (ret + 1LL * cal(l + 1, mid, 1, 0) * cal(mid, r, 1, 1)) % mod;
    }
  }
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) cin >> a[i][j];
  memset(dp, -1, sizeof(dp));
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    if (a[1][i]) ans = (ans + 1LL * cal(1, i, 1, 1) * cal(i, n, 1, 0)) % mod;
  }
  cout << ans << '\n';
}
