object Main extends App {

  import scala.io.StdIn._

  val n = readLine.trim.toInt
  val prefer = Array.tabulate(n){_ ⇒ readLine.trim.split(' ').map(_ == "1")}
  println(search(prefer))
  def search(prefer: Array[Array[Boolean]]): Long = {
    val memo = Array.tabulate(1 << prefer.length){_ ⇒ -1l}
    val mod = 1000000007L
    def solve(current: Int, used: Flag): Long = {
      if (current < 0) 1L
      else if (memo(used.index) >= 0) memo(used.index)
      else{
        prefer.indices.filter(p ⇒ !used(p) && prefer(current)(p)).map(p ⇒ solve(current - 1, used.updated(p, true))).sum.let{_ % mod}.also{max ⇒ memo(used.index) = max}
      }
    }
    solve(prefer.length - 1, new Flag)
  }
  class Flag(var index: Int = 0){
    def update(position: Int, value: Boolean): Unit = if (value) index |= 1 << position else index &= ~(1 << position)
    def apply(position: Int): Boolean = (index & (1 << position)) != 0
    def updated(position: Int, value: Boolean): Flag = if (value) new Flag(index | (1 << position)) else new Flag(index & ~(1 << position))
  }
  implicit class Extend[T](value: T){
    def also(func: T ⇒ Unit): T = {func(value); value}
    def let[A](func: T ⇒ A): A = func(value)
  }
}