#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  char c;
  bool nega = false;
  while ((!isdigit(c = getchar())) && (c != '-'))
    ;
  if (c == '-') {
    nega = true;
    c = getchar();
  }
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (nega) x = -x;
}
template <typename T>
inline void writep(T x) {
  if (x > 9) writep(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  writep(x);
}
template <typename T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
int c[505][505];
int f[505][505][2][2];
int n;
int main() {
  read(n);
  int i, j, k, l;
  for (i = 0; i <= n - 1; i++)
    for (j = 0; j <= n - 1; j++) read(c[i][j]);
  for (i = 0; i <= n - 1; i++) c[i][n] = c[n][i] = c[0][i];
  for (i = n; i >= 0; i--) {
    for (j = i + 1; j <= n; j++) {
      if ((i + 1) == j) {
        for (k = 0; k <= 1; k++)
          for (l = 0; l <= 1; l++) f[i][j][k][l] = 1;
        continue;
      }
      f[i][j][0][0] = 0;
      for (k = i + 1; k <= j - 1; k++) {
        if (c[k][j])
          f[i][j][0][1] =
              ((long long)f[i][k][0][1] * f[k][j][1][1] + f[i][j][0][1]) %
              1000000007;
        if (c[i][k]) {
          f[i][j][1][0] =
              ((long long)f[i][k][1][1] * f[k][j][1][0] + f[i][j][1][0]) %
              1000000007;
          f[i][j][1][1] =
              ((long long)f[i][k][1][1] * f[k][j][1][1] + f[i][j][1][1]) %
              1000000007;
        }
      }
      f[i][j][1][1] = (f[i][j][1][1] + f[i][j][0][1]) % 1000000007;
    }
  }
  long long kq = 0;
  for (i = 1; i <= n - 1; i++)
    if (c[0][i])
      kq = ((long long)f[0][i][0][1] * f[i][n][1][1] + kq) % 1000000007;
  writeln(kq);
  return 0;
}
