import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

string my_readln() { return chomp(readln()); }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto tokens = my_readln.split;
	auto N = tokens[0].to!uint;
	auto a = new ulong[][](N);
	foreach (i; 0..N)
	{
		foreach (j, token; my_readln.split)
		{
			auto x = token.to!(ulong);
			if (x == 0) continue;
			a[i] ~= x << j;
		}
	}

	auto dp = new long[](1<<N);
	dp[0] = 1;

	foreach (j; 1..1<<N)
	{
		auto i = popcnt(j) - 1;
		foreach (e; a[i])
		{
			if ((j & e) == 0) continue;

			auto x = j | e;
			dp[j] = moda(dp[j], dp[j^e]);
		}
	}
	//stderr.writeln(dp[i+1]);
	
	writeln(dp[(1<<N)-1]);
	stdout.flush();
}