#include <fstream>
#include <vector>
#include <bitset>
#include <string.h>
using namespace std;
const char infile[] = "copii.in";
const char outfile[] = "copii.out";
ifstream fin(infile);
ofstream fout(outfile);
const int MAXN = 12;
const int oo = 0x3f3f3f3f;
typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;
const inline int min(const int &a, const int &b) { if( a > b ) return b; return a; }
const inline int max(const int &a, const int &b) { if( a < b ) return b; return a; }
const inline void Get_min(int &a, const int b) { if( a > b ) a = b; }
const inline void Get_max(int &a, const int b) { if( a < b ) a = b; }
int N, gr[MAXN];
bool d[MAXN][MAXN];
int comp, Ans;
char a[MAXN][MAXN];
inline bool verify() {
memset(d, 0, sizeof(d));
for(int i = 1 ; i <= N ; ++ i)
for(int j = 1 ; j <= N ; ++ j)
if(a[i][j] == '1')
d[gr[i]][gr[j]] = 1;
for(int i = 1 ; i <= comp ; ++ i)
for(int j = 1; j <= comp ; ++ j)
if(i != j && !d[i][j])
return 0;
return 1;
}
void Back(int k) {
if(k > N) {
if(comp > 1)
Ans += verify();
return;
}
for(int i = 1 ; i <= comp ; ++ i) {
gr[k] = i;
Back(k + 1);
}
++ comp;
gr[k] = comp;
Back(k + 1);
-- comp;
}
int main() {
fin >> N;
for(int i = 1 ; i <= N ; ++ i)
fin >> (a[i] + 1);
Back(1);
fout << Ans << '\n';
fin.close();
fout.close();
return 0;
}