local n=io.read("n")
local a={}
for i=1,n do
    a[i]={}
    for j=1,n do
        a[i][j]=io.read("n")
    end
end

local dp={}
for i=0,n do
    dp[i]={}
end

local bit=require("bit")
local band=bit.band
local bxor=bit.bxor
local lshift=bit.lshift
local mod=1000000007
local function solve(i,S)
    if i==n then
        return 1
    end
    if dp[i][S] then
        return dp[i][S]
    end
    local pattern=0
    for j=0,n-1 do
        if band(S,lshift(1,j))<1 and a[i+1][j+1]>0 then
            pattern=pattern+solve(i+1,bxor(S,lshift(1,j)))
            pattern=pattern%mod
        end
    end
    dp[i][S]=pattern
    return dp[i][S]
end

print(solve(0,0))