import Foundation
let N = Int(readLine()!)!

var grid: [[Int]] = .init(repeating: [], count: N)

for i in 0..<N {
  grid[i] = readLine()!.split(separator: " ").map { Int($0)! }
}

let n = Int(pow(2.0, Double(N)))
var dp: [Int] = .init(repeating: -1, count: n)
let mod = 1000000007
func dfs(_ i: Int, _ grid: [[Int]], _ current: Int) -> Int {
  if i == grid.count {
    return current == n - 1 ? 1 : 0
  }
  if dp[current] != -1 {
    return dp[current]
  }
  var sum = 0
  for j in 0..<grid[i].count {
    if grid[i][j] == 0 {
      continue
    }
    if current & 1 << j == 0 {
      sum = (sum + dfs(i+1, grid, current | 1 << j)) % mod
    }
  }
  dp[current] = sum
  return sum
}

print(dfs(0, grid, 0))