atcoder#ARC107C. [ARC107C] Shuffle Permutation
[ARC107C] Shuffle Permutation
Score : points
Problem Statement
Given are an matrix and an integer . The entry in the -th row and -th column of this matrix is denoted as . This matrix contains each of exactly once.
Sigma can repeat the following two kinds of operation arbitrarily many times in any order.
- Pick two integers that satisfy for all () and swap the -th and the -th columns.
- Pick two integers that satisfy for all () and swap the -th and the -th rows.
How many matrices can he obtain by these operations? Find it modulo .
Constraints
- 's are a rearrangement of .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the number of matrices Sigma can obtain modulo .
3 13
3 2 7
4 8 9
1 6 5
12
For example, Sigma can swap two columns, by setting . After that, the resulting matrix will be:
2 3 7
8 4 9
6 1 5
After that, he can swap two row vectors by setting , resulting in the following matrix:
6 1 5
8 4 9
2 3 7
10 165
82 94 21 65 28 22 61 80 81 79
93 35 59 85 96 1 78 72 43 5
12 15 97 49 69 53 18 73 6 58
60 14 23 19 44 99 64 17 29 67
24 39 56 92 88 7 48 75 36 91
74 16 26 10 40 63 45 76 86 3
9 66 42 84 38 51 25 2 33 41
87 54 57 62 47 31 68 11 83 8
46 27 55 70 52 98 20 77 89 34
32 71 30 50 90 4 37 95 13 100
348179577