#dpo. [dp_o]Matching

[dp_o]Matching

Problem Statement

There are NN men and NN women, both numbered 1,2,ldots,N1, 2, \\ldots, N.

For each i,ji, j (1leqi,jleqN1 \\leq i, j \\leq N), the compatibility of Man ii and Woman jj is given as an integer ai,ja_{i, j}. If ai,j=1a_{i, j} = 1, Man ii and Woman jj are compatible; if ai,j=0a_{i, j} = 0, they are not.

Taro is trying to make NN pairs, each consisting of a man and a woman who are compatible. Here, each man and each woman must belong to exactly one pair.

Find the number of ways in which Taro can make NN pairs, modulo 109+710^9 + 7.

Constraints

  • All values in input are integers.
  • 1leqNleq211 \\leq N \\leq 21
  • ai,ja_{i, j} is 00 or 11.

Input

Input is given from Standard Input in the following format:

NN a1,1a_{1, 1} ldots\\ldots a1,Na_{1, N} :: aN,1a_{N, 1} ldots\\ldots aN,Na_{N, N}

Output

Print the number of ways in which Taro can make NN pairs, modulo 109+710^9 + 7.


Sample Input 1

3
0 1 1
1 0 1
1 1 1

Sample Output 1

3

There are three ways to make pairs, as follows ((i,j)(i, j) denotes a pair of Man ii and Woman jj):

  • (1,2),(2,1),(3,3)(1, 2), (2, 1), (3, 3)
  • (1,2),(2,3),(3,1)(1, 2), (2, 3), (3, 1)
  • (1,3),(2,1),(3,2)(1, 3), (2, 1), (3, 2)

Sample Input 2

4
0 1 0 0
0 0 0 1
1 0 0 0
0 0 1 0

Sample Output 2

1

There is one way to make pairs, as follows:

  • (1,2),(2,4),(3,1),(4,3)(1, 2), (2, 4), (3, 1), (4, 3)

Sample Input 3

1
0

Sample Output 3

0

Sample Input 4

21
0 0 0 0 0 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1
1 1 1 0 0 1 0 0 0 1 0 0 0 0 1 1 1 0 1 1 0
0 0 1 1 1 1 0 1 1 0 0 1 0 0 1 1 0 0 0 1 1
0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 0 0 0 1 1 0
1 1 0 0 1 0 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0
0 1 1 0 1 1 1 0 1 1 1 0 0 0 1 1 1 1 0 0 1
0 1 0 0 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 1 0
0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1
0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 0 1 0 1 1 1
0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 0 1
0 1 1 0 1 1 0 0 1 1 0 0 0 1 1 1 1 0 1 1 0
0 0 1 0 0 1 1 1 1 0 1 1 0 1 1 1 0 0 0 0 1
0 1 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 0 1 1
1 1 1 1 1 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 1
0 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1
1 0 1 1 0 1 0 1 0 0 1 0 0 1 1 0 1 0 1 1 0
0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1
0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 0 0 1 1 0 1
0 0 0 0 1 1 1 0 1 0 1 1 1 0 1 1 0 0 1 1 0
1 1 0 1 1 0 0 1 1 0 1 1 0 1 1 1 1 1 0 1 0
1 0 0 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 0 0 0

Sample Output 4

102515160

Be sure to print the number modulo 109+710^9 + 7.