atcoder#AGC023E. [AGC023E] Inversions
[AGC023E] Inversions
Score : points
Problem Statement
Snuke has an integer sequence whose length is . He likes permutations of , , that satisfy the following condition:
- for all ( ).
Snuke is interested in the inversion numbers of such permutations. Find the sum of the inversion numbers over all permutations that satisfy the condition. Since this can be extremely large, compute the sum modulo .
Notes
The inversion number of a sequence whose length is the number of pairs of integers and ( ) such that .
Constraints
- ( )
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the sum of the inversion numbers over all permutations that satisfy the condition.
3
2 3 3
4
There are four permutations that satisfy the condition: , , and . The inversion numbers of these permutations are , , and , respectively, for a total of .
6
4 2 5 1 6 3
7
Only one permutation satisfies the condition. The inversion number of this permutation is , so the answer is .
5
4 4 4 4 4
0
No permutation satisfies the condition.
30
22 30 15 20 10 29 11 29 28 11 26 10 18 28 22 5 29 16 24 24 27 10 21 30 29 19 28 27 18 23
848414012