atcoder#KEYENCE2019D. Double Landscape
Double Landscape
Score : points
Problem Statement
Consider writing each of the integers from to in a grid with rows and columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions:
- The largest among the values in the -th row is .
- The largest among the values in the -th column is .
For him, find the number of ways to write the numbers under these conditions, modulo .
Constraints
- and are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the number of ways to write the numbers under the conditions, modulo .
2 2
4 3
3 4
2
and . In this case, there are two ways to write the numbers, as follows:
- in , in , in and in .
- in , in , in and in .
Here, denotes the square at the -th row and the -th column.
3 3
5 9 7
3 6 9
0
Since there is no way to write the numbers under the condition, should be printed.
2 2
4 4
4 4
0
14 13
158 167 181 147 178 151 179 182 176 169 180 129 175 168
181 150 178 179 167 180 176 169 182 177 175 159 173
343772227