atcoder#AGC030D. [AGC030D] Inversion Sum
[AGC030D] Inversion Sum
Score : points
Problem Statement
You are given an integer sequence of length : . Let us perform operations in order. The -th operation is described by two integers and . In this operation, we will choose one of the following two actions and perform it:
- Swap the values of and
- Do nothing
There are ways to perform these operations. Find the sum of the inversion numbers of the final sequences for all of these ways to perform operations, modulo .
Here, the inversion number of a sequence is the number of pairs of integers such that and .
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 of the final sequences, modulo .
3 2
1
2
3
1 2
1 3
6
There are four ways to perform operations, as follows:
- Do nothing, both in the first and second operations. The final sequence would be , with the inversion number of .
- Do nothing in the first operation, then perform the swap in the second. The final sequence would be , with the inversion number of .
- Perform the swap in the first operation, then do nothing in the second. The final sequence would be , with the inversion number of .
- Perform the swap, both in the first and second operations. The final sequence would be , with the inversion number of .
The sum of these inversion numbers, , should be printed.
5 3
3
2
3
1
4
1 5
2 3
4 2
36
9 5
3
1
4
1
5
9
2
6
5
3 5
8 9
7 9
3 2
3 8
425