atcoder#ABC150E. [ABC150E] Change a Little Bit
[ABC150E] Change a Little Bit
Score : points
Problem Statement
For two sequences and of length consisting of and , let us define as follows:
- Consider repeating the following operation on so that will be equal to . is the minimum possible total cost of those operations.
- Change (from to or vice versa). The cost of this operation is , where is the number of integers such that just before this change.
There are pairs of different sequences of length consisting of and . Compute the sum of over all of those pairs, modulo .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the sum of , modulo .
1
1000000000
999999993
There are two pairs of different sequences of length consisting of and , as follows:
- by changing to , we can have at the cost of , so .
- by changing to , we can have at the cost of , so .
The sum of these is , and we should print it modulo , that is, .
2
5 8
124
There are pairs of different sequences of length consisting of and , which include:
In this case, if we first change to then change to , the total cost is . We cannot have at a smaller cost, so .
5
52 67 72 25 79
269312