n = gets.to_i
@m = 10 ** 9 + 7

@a = n.times.map {gets.split.map(&:to_i)}

@memo = Array.new(n) {Array.new(1 << n)}

def calc(i, bv)
    return @memo[i][bv] if @memo[i][bv]

    sum = 0
    @a[i].each_with_index do |e,j|
        next if e & bv[j] == 0
        sum += i == 0 ? 1 : calc(i-1, bv ^ (1 << j))
    end

    @memo[i][bv] = sum % @m
end

p calc(n-1, (1 << n) - 1)