

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
長さ の整数列 があります。
を 回繰り返した長さ の整数列を とします。たとえば 、 のとき、 です。
の転倒数を で割った余りを求めてください。
ここで の転倒数は、整数の順序対 であって を満たすものの個数として定義されます。
制約
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
出力
の転倒数を で割った余りを出力せよ。
入力例 1Copy
2 2 2 1
出力例 1Copy
3
このケースでは です。
であり、 の転倒数は です。
入力例 2Copy
3 5 1 1 1
出力例 2Copy
0
は同じ数を複数含むこともあります。
入力例 3Copy
10 998244353 10 9 8 7 5 6 3 4 2 1
出力例 3Copy
185297239
で割った余りを出力することに注意してください。
Score : points
Problem Statement
We have a sequence of integers .
Let be a sequence of integers obtained by concatenating copies of . For example, if and , .
Find the inversion number of , modulo .
Here the inversion number of is defined as the number of ordered pairs of integers 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 .
Sample Input 1Copy
2 2 2 1
Sample Output 1Copy
3
In this case, . We have:
Thus, the inversion number of is .
Sample Input 2Copy
3 5 1 1 1
Sample Output 2Copy
0
may contain multiple occurrences of the same number.
Sample Input 3Copy
10 998244353 10 9 8 7 5 6 3 4 2 1
Sample Output 3Copy
185297239
Be sure to print the output modulo .