mod=10**9+7



N,K=list(map(int,input().split()))

A=list(map(int,input().split()))



s=[0]*N

t=[0]*N



for i in range(N):

  for j in range(i+1,N):

    if A[i]>A[j]:

      s[i]+=1

#print(s)



for i in range(N):

  for j in range(N):

    if A[i]>A[j]:

      t[i]+=1

#print(t)



for i in range(N):

  s[i]=(s[i]*K)%mod

  t[i]=(t[i]*(K-1)*K//2)%mod

#print(s)

#print(t)



print(((sum(s)+sum(t))%mod))
N, K = list(map(int, input().split()))

A = list(map(int, input().split()))



MOD = 10 ** 9 + 7

in_A, out_A = 0, 0



for i in range(N):

  for j in range(i + 1, N):

    if A[i] > A[j]:

      in_A += 1

  for j in range(N):

    if A[i] > A[j]:

      out_A += 1



print(((in_A * K + out_A * K * (K - 1) // 2) % MOD))



mod = 10**9 + 7
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
s = [0] * N
t = [0] * N
for i in range(N):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            s[i] += 1
# print(s)
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            t[i] += 1
# print(t)
for i in range(N):
    s[i] = (s[i] * K) % mod
    t[i] = (t[i] * (K - 1) * K // 2) % mod
# print(s)
# print(t)
print(((sum(s) + sum(t)) % mod))

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
in_A, out_A = 0, 0
for i in range(N):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            in_A += 1
    for j in range(N):
        if A[i] > A[j]:
            out_A += 1
print(((in_A * K + out_A * K * (K - 1) // 2) % MOD))

-mod = 10**9 + 7 -s = [0] * N -t = [0] * N +MOD = 10**9 + 7 +in_A, out_A = 0, 0 -            s[i] += 1 -# print(s) -for i in range(N): +            in_A += 1 -            t[i] += 1 -# print(t) -for i in range(N): -    s[i] = (s[i] * K) % mod -    t[i] = (t[i] * (K - 1) * K // 2) % mod -# print(s) -# print(t) -print(((sum(s) + sum(t)) % mod)) +            out_A += 1 +print(((in_A * K + out_A * K * (K - 1) // 2) % MOD))