import Data.Bits
import Data.List
import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.ST
import Control.Monad
import Control.Monad.ST
import Debug.Trace

type Table = UArray (Int,Int) Bool
type DP s = STUArray s (Int,Int) Int

dp_i :: DP s -> [Int] -> Int -> Int -> ST s ()
dp_i dparr [] m w = return ()
dp_i dparr (w':ws) m w = do
  if testBit w (w'-1) then return ()
    else do
      now <- readArray dparr (m,w)
      if now == 0 then return ()
        else do
          next <- readArray dparr (m+1,setBit w (w'-1))
          writeArray dparr (m+1,setBit w (w'-1)) $ mod0 (now+next)
  dp_i dparr ws m w

solve :: Table -> Int -> ST s Int
solve table n = do
  dparr <- newArray ((0,0),(n,2^n-1)) 0
  writeArray dparr (0,0) 1
  forM_ [0..n-1] $ \m -> do
    let ws = filter (\w' -> table!(m+1,w') == True) [1..n]
    forM_ [0..2^n-1] $ \w -> if popCount w == m then dp_i dparr ws m w else return ()
  readArray dparr (n,2^n-1)

main :: IO ()
main = do
  n <- read <$> getLine
  ls <- replicateM n $ do
    ms <- map read.words <$> getLine
    return $ map (\m0 -> if m0 == 1 then True else False) ms
  let table = listArray ((1,1),(n,n)) $ concat ls
  print $ runST $ solve table n

mod0 :: Int -> Int
mod0 n = mod n 1000000007
