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



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

L=[0]*N

R=[0]*N



for i in range(N):

    for j in range(N):

        if j<i and A[j]<A[i]:

            L[i]+=1

        if j>i and A[j]<A[i]:

            R[i]+=1

ans = 0

K1=((1+K)*K//2)%(10**9+7)

K2=(K*(K-1)//2)%(10**9+7)



for i in range(N):

    ans +=(R[i]*K1+L[i]*K2)%(10**9+7)



ans =ans%(10**9+7)



print((int(ans)))



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

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



mod=10**9+7



B=[]

for i in range(N):

    l=0

    r=0

    for j in range(i):

        if A[i]>A[j]:

            l+=1



    for k in range(i,N):

        if A[i]>A[k]:

            r+=1

    B.append([l,r])



ans=0

for i in range(N):

    ans+=B[i][0]*(K-1)*K//2+B[i][1]*K*(K+1)//2

ans%=mod



print(ans)
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
L = [0] * N
R = [0] * N
for i in range(N):
    for j in range(N):
        if j < i and A[j] < A[i]:
            L[i] += 1
        if j > i and A[j] < A[i]:
            R[i] += 1
ans = 0
K1 = ((1 + K) * K // 2) % (10**9 + 7)
K2 = (K * (K - 1) // 2) % (10**9 + 7)
for i in range(N):
    ans += (R[i] * K1 + L[i] * K2) % (10**9 + 7)
ans = ans % (10**9 + 7)
print((int(ans)))

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

-L = [0] * N -R = [0] * N +mod = 10**9 + 7 +B = [] -    for j in range(N): -        if j < i and A[j] < A[i]: -            L[i] += 1 -        if j > i and A[j] < A[i]: -            R[i] += 1 +    l = 0 +    r = 0 +    for j in range(i): +        if A[i] > A[j]: +            l += 1 +    for k in range(i, N): +        if A[i] > A[k]: +            r += 1 +    B.append([l, r]) -K1 = ((1 + K) * K // 2) % (10**9 + 7) -K2 = (K * (K - 1) // 2) % (10**9 + 7) -    ans += (R[i] * K1 + L[i] * K2) % (10**9 + 7) -ans = ans % (10**9 + 7) -print((int(ans))) +    ans += B[i][0] * (K - 1) * K // 2 + B[i][1] * K * (K + 1) // 2 +ans %= mod +print(ans)