#P10353. [PA 2024] Grupa permutacji
[PA 2024] Grupa permutacji
Background
PA 2024 2A
Problem Description
This problem is translated from PA 2024 Round 2 Grupa permutacji.
In this problem, we deal with permutations of elements. A permutation of elements is a sequence of distinct natural numbers from to (inclusive). Composing the permutation with the permutation results in the permutation . We call any pair such that and an inversion of the permutation .
Bytie is a loyal fan of permutations of elements. He likes them very much, and some of them are his favorites. He decided to start writing on a piece of paper all permutations that can be obtained by composing his favorite permutations (in any order, possibly using some of them multiple times), carefully making sure that he does not write any permutation more than once.
Without a doubt, he quickly ran out of paper. Then Bytie has a question: if he listed all possible permutations, how many inversions would they have on average?
Help him write a program to compute this value. More specifically, output the answer modulo (see the “Output Format” section for details).
Input Format
The first line contains two integers and , representing the length of the permutations and the number of Bytie’s favorite permutations.
The next lines each contain pairwise distinct integers $a_{i,1},a_{i,2},\ldots,a_{i,n}\ (1\le a_{i,j}\le n)$, describing Bytie’s -th favorite permutation.
Output Format
Output one integer in a single line: the average number of inversions among all permutations that Bytie may write down, taken modulo .
Formally, let the result be , where and . Output , where is the unique integer in such that .
It can be proven that for all valid testdata, the result is a rational number whose denominator in lowest terms is not divisible by .
3 1
2 3 1
333333337
5 2
2 1 3 4 5
2 3 4 5 1
5
Hint
In the first sample, Bytie will write the permutation (which has inversions), the permutation (which has inversions), and the permutation (which has inversions). Therefore, the average number of inversions is . Also, , so the answer is $333333336\cdot 4\equiv 1333333344\equiv 333333337\pmod{10^9+7}$.
In the second sample, Bytie will write all permutations of elements. It is easy to prove that their average number of inversions is .
Translated by ChatGPT 5