atcoder#JSC2019QUALB. Kleene Inversion

Kleene Inversion

Score : 300300 points

Problem Statement

We have a sequence of NN integers $A \sim = \sim A_0, \sim A_1, \sim ..., \sim A_{N - 1}$.

Let BB be a sequence of K×NK \times N integers obtained by concatenating KK copies of AA. For example, if A=1,3,2A \sim = \sim 1, \sim 3, \sim 2 and K=2K \sim = \sim 2, $B \sim = \sim 1, \sim 3, \sim 2, \sim 1, \sim 3, \sim 2$.

Find the inversion number of BB, modulo 109+710^9 + 7.

Here the inversion number of BB 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 Bi>BjB_i > B_j.

Constraints

  • All values in input are integers.
  • 1N20001 \leq N \leq 2000
  • 1K1091 \leq K \leq 10^9
  • 1Ai20001 \leq A_i \leq 2000

Input

Input is given from Standard Input in the following format:

NN KK

A0A_0 A1A_1 ...... AN1A_{N - 1}

Output

Print the inversion number of BB, modulo 109+710^9 + 7.

2 2
2 1
3

In this case, B=2,1,2,1B \sim = \sim 2, \sim 1, \sim 2, \sim 1. We have:

  • B0>B1B_0 > B_1
  • B0>B3B_0 > B_3
  • B2>B3B_2 > B_3

Thus, the inversion number of BB is 33.

3 5
1 1 1
0

AA 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 109+710^9 + 7.