#abc273g. [abc273_g]Row Column Sums 2
[abc273_g]Row Column Sums 2
Problem Statement
Find the number, modulo , of square matrices of size whose elements are non-negative integers, that satisfy both of the following two conditions:
- for all , the sum of the elements in the -th row is ;
- for all , the sum of the elements in the -th column is .
Note that and given in the input are integers between and (see Constraints).
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
1 1 1
0 1 2
Sample Output 1
3
The following matrices satisfy the conditions:
0 1 0
0 0 1
0 0 1
``````plain
0 0 1
0 1 0
0 0 1
``````plain
0 0 1
0 0 1
0 1 0
Sample Input 2
3
1 1 1
2 2 2
Sample Output 2
0
Sample Input 3
18
2 0 1 2 0 1 1 2 1 1 2 0 1 2 2 1 0 0
1 1 0 1 1 1 1 1 1 1 1 1 2 1 1 0 2 2
Sample Output 3
968235177
Be sure to print the count modulo .