# coding: utf-8

# Your code here!

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



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



A=A+A



count=[0]*2*N



for i in range(N):

    for j in range(i,2*N):

        if A[i]>A[j]:

            count[j]+=1

a=(sum(count[0:N]))

b=(sum(count[N:2*N]))

c=(int((a*K+b*K*(K-1)//2)))

print((c%(10**9+7)))

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

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



mod=10**9+7



inside=0

for i in range(N-1):

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

        if A[i]>A[j]:

            inside+=1



outside=0

for i in range(N):

    for j in range(N,2*N):

        if A[i]>A[j]:

            outside+=1

    

#print(inside,outside)

print(((inside*K+outside*(K-1)*K//2)%mod))
# coding: utf-8
# Your code here!
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A = A + A
count = [0] * 2 * N
for i in range(N):
    for j in range(i, 2 * N):
        if A[i] > A[j]:
            count[j] += 1
a = sum(count[0:N])
b = sum(count[N : 2 * N])
c = int((a * K + b * K * (K - 1) // 2))
print((c % (10**9 + 7)))

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

-# coding: utf-8 -# Your code here! -A = list(map(int, input().split())) -A = A + A -count = [0] * 2 * N +A = list(map(int, input().split())) * 2 +mod = 10**9 + 7 +inside = 0 +for i in range(N - 1): +    for j in range(i + 1, N): +        if A[i] > A[j]: +            inside += 1 +outside = 0 -    for j in range(i, 2 * N): +    for j in range(N, 2 * N): -            count[j] += 1 -a = sum(count[0:N]) -b = sum(count[N : 2 * N]) -c = int((a * K + b * K * (K - 1) // 2)) -print((c % (10**9 + 7))) +            outside += 1 +# print(inside,outside) +print(((inside * K + outside * (K - 1) * K // 2) % mod))