#P10004. [集训队互测 2023] Permutation Counting 2
[集训队互测 2023] Permutation Counting 2
Problem Description
Given , for each pair , find how many permutations of satisfy the following conditions:
-
.
-
.
Here denotes the inverse permutation of , satisfying .
Output the answer modulo the given prime .
Input Format
One line with two integers, .
Output Format
Output lines, each containing integers. The number in row and column denotes the answer when .
3 1000000007
1 0 0
0 4 0
0 0 1
5 1000000007
1 0 0 0 0
0 20 6 0 0
0 6 54 6 0
0 0 6 20 0
0 0 0 0 1
10 1000000007
1 0 0 0 0 0 0 0 0 0
0 165 462 330 55 1 0 0 0 0
0 462 9273 22023 13750 2266 66 0 0 0
0 330 22023 147301 203610 75306 6556 66 0 0
0 55 13750 203610 592130 423236 75306 2266 1 0
0 1 2266 75306 423236 592130 203610 13750 55 0
0 0 66 6556 75306 203610 147301 22023 330 0
0 0 0 66 2266 13750 22023 9273 462 0
0 0 0 0 1 55 330 462 165 0
0 0 0 0 0 0 0 0 0 1
Hint
For of the testdata, , , and is guaranteed to be prime.
.
.
.
.
No special constraints.
Translated by ChatGPT 5