atcoder#JSC2019QUALB. Kleene Inversion
Kleene Inversion
Score : points
Problem Statement
We have a sequence of integers $A \sim = \sim A_0, \sim A_1, \sim ..., \sim A_{N - 1}$.
Let be a sequence of integers obtained by concatenating copies of . For example, if and , $B \sim = \sim 1, \sim 3, \sim 2, \sim 1, \sim 3, \sim 2$.
Find the inversion number of , modulo .
Here the inversion number of is defined as the number of ordered pairs of integers $(i, \sim j) \sim (0 \leq i < j \leq K \times N - 1)$ such that .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the inversion number of , modulo .
2 2
2 1
3
In this case, . We have:
Thus, the inversion number of is .
3 5
1 1 1
0
may contain multiple occurrences of the same number.
10 998244353
10 9 8 7 5 6 3 4 2 1
185297239
Be sure to print the output modulo .