#include <bits/stdc++.h>
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
inline int qread() {
  register char c =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
           ? EOF
           : *p1++);
  register int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++);
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - 48;
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++);
  }
  return x * f;
}
inline int Abs(const int& x) { return (x > 0 ? x : -x); }
inline int Max(const int& x, const int& y) { return (x > y ? x : y); }
inline int Min(const int& x, const int& y) { return (x < y ? x : y); }
const long long mod = 1000000007;
bool mp[1005][1005];
long long dp[1005][1005], dp2[1005][1005], ans[1005];
int n;
inline void Read() {
  n = qread();
  for (register int i = 1; i <= n; i++) {
    for (register int j = 1; j <= n; j++)
      mp[i][j] = mp[i + n][j + n] = mp[i + n][j] = mp[i][j + n] = qread();
  }
}
inline void Solve() {
  for (register int i = 1; i <= n + 1; i++) dp2[i][i] = dp[i][i] = 1;
  for (register int i = 1; i <= n; i++)
    dp2[i][i + 1] = dp[i][i + 1] = mp[i][i + 1];
  for (register int l = 3; l <= n; l++) {
    for (register int i = 1; i <= n + 1 - l + 1; i++) {
      register int j = i + l - 1;
      for (register int k = i + 1; k < j; k++)
        dp[i][j] = (dp[i][j] + dp[i][k] * dp2[k][j] % mod) % mod;
      if (mp[i][j]) {
        register long long cur = dp[i][j];
        for (register int k = i; k < j; k++) {
          dp2[i][j] = (dp2[i][j] + dp[i][k] * dp[k + 1][j] % mod) % mod;
          dp[i][j] = (dp[i][j] + dp[i][k] * dp[k + 1][j] % mod) % mod;
        }
      }
    }
  }
  ans[1] = 1;
  for (register int i = 2; i <= n; i++) {
    for (register int j = 1; j < i; j++)
      ans[i] = (ans[i] + ans[j] * dp2[j][i] % mod) % mod;
  }
  printf("%lld", dp[1][n] % mod);
}
int main() {
  Read();
  Solve();
  return 0;
}
