#include <bits/stdc++.h>     

#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4"

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
//#define int ll
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
 
using namespace std;
 
const int maxn = (int)500;
const int mod = (int)1e9 + 7;
 
#define inf mod
 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

int n, a[22][22], dp[22][(1 << 21)], m[22];
int main () {
  scanf("%d", &n);
  forn(i, 1, n)
    forn(j, 0, n - 1)
      scanf("%d", &a[i][j]),m[i]+=a[i][j]*(1<<j);
  dp[0][0] = 1;
  forn(i, 1, n){
    forn(j, 0, (1 << n) - 1){
      int x = j&m[i];
      forn(k,0,n-1)
        if((x>>k)&1)
          dp[i][j]=(dp[i][j]+dp[i-1][j^(1<<k)])%mod;
    }  
  }
  printf("%d", dp[n][(1 << n) - 1]);
}