#include<bits/stdc++.h>

using namespace std;

#define debug(n) cerr << #n << ':' << (n) << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

template<long long mod>
class modint{
private:
  long long num;
  long long extgcd(long long a, long long b, long long&x, long long&y)const {
    long long d = a;
    if(b != 0){d = extgcd(b, a%b, y, x);  y -= (a/b) * x;}
    else{x = 1; y = 0;}
    return d;
  }
  long long modinverse()const{
    long long x, y;
    extgcd(num, mod, x, y);
    return (mod + x%mod)%mod;
  }
public:
  modint():num(0){}
  modint(const long long x):num((x < 0?(x+mod):x)%mod ){}
  friend modint operator+(const modint&a, const modint&b)
  {    return modint(a.num + b.num);  }
  friend modint operator-(const modint&a, const modint&b)
  {    return modint(a.num - b.num);  }
  friend modint operator*(const modint&a, const modint&b)
  {    return modint(a.num * b.num);  }
  friend modint operator/(const modint&a, const modint&b)
  {    return modint(a*b.modinverse());  }
  modint& operator+=(const modint&b)
  {    return (*this) = (*this) + b;  }
  modint& operator-=(const modint&b)
  {    return (*this) = (*this) - b;  }
  modint& operator*=(const modint&b)
  {    return (*this) = (*this) * b;  }
  modint& operator/=(const modint&b)
  {    return (*this) = (*this) / b;  }
  modint& operator++()
  {    (*this)+=1; return (*this);  }
  modint& operator--()
  {    (*this)-=1; return (*this);  }
  modint operator++(int){
    modint tmp(*this);
    ++(*this);
    return tmp;
  }
  modint operator--(int){
    modint tmp(*this);
    --(*this);
    return tmp;
  }    
  friend ostream& operator<<(ostream&os, const modint&a){
    os << a.num;
    return os;
  }
  friend istream& operator>>(istream&is, modint&a){
    long long x; is >> x;
    a = x;
    return is;
  }
};


using mint = modint<int(1e+9)+7>;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin >> n;
  vector<vector<int>> a(n);
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      int x; cin >> x;
      if(x)a[i].push_back(j);
    }
    // debug(a[i].size());
  }
  

  int x = 0;
  // set<int> v;
  for(int cnter = 0,i = 1; cnter < n; ++cnter,i <<= 1){
    x |= i;
    // v.insert(i);
  }
  //  debug(x);
  vector<vector<mint>> dp(n+1,vector<mint>(x+1,0));

  dp[n][x] = 1;
  //set<int> st1; st1.insert(x);
  vector<int> st1 = {x};
  for(int i = n; i > 0; --i){
    vector<int> st2;
    bitset<2100000> bss;
    //    bitset
    // debug(i);
    for(int&e:st1){
      // debug(e);
      for(int&cnter:a[i-1]){
      // for(int cnter:a[i-1]){
	// debug(cnter);
	bitset<32> bs; bs[cnter] = 1;
	int j = (int)bs.to_ulong();
	// debug(j);
	// debug(e&j);
	//debug(a[i-1][cnter]);
	if(e&j){
	  // debug((~j)&e);
	  dp[i-1][(~j)&e] += dp[i][e];
	  if(!bss[(~j)&e]){
	    st2.emplace_back((~j)&e);
	    bss[(~j)&e] = 1;
	  }
	}
      }
    }
    // debug(st2.size());
    st1 = move(st2);
    //swap(st1,st2);
  }
  // for(int i = 0; i < n+1; ++i){
  //   debug(i);
  //   for(int j = 0; j < x+1; ++j){
  //     debug(j);
  //     cerr << dp[i][j] << endl;
  //   }
  // }
  cout << dp[0][0] << endl;
  return 0;
}


Measured memory_bytes: 377216