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

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



mod = 10 ** 9 + 7

ans = 0



if K == 1:

    for i in range(N-1):

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

            if A[i] > A[j]:

                ans += 1

        ans %= mod

    print(ans)

    exit()





for i in range(N):

    tmp = 0

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

        if A[i] > A[j]:

            tmp += ((K * (K+1) // 2) % mod)

    for j in range(i):

        if A[i] > A[j]:

            tmp += ((K * (K-1) // 2) % mod)

    tmp %= mod

    ans += tmp



print((ans % mod))

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

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



mod = 10 ** 9 + 7



x, y = 0, 0



for i in range(N):

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

        if A[i] > A[j]:

            x += 1

    for j in range(i):

        if A[i] > A[j]:

            y += 1



ans = x * K * (K+1) // 2 + y * (K-1) * K // 2



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

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

-ans = 0 -if K == 1: -    for i in range(N - 1): -        for j in range(i + 1, N): -            if A[i] > A[j]: -                ans += 1 -        ans %= mod -    print(ans) -    exit() +x, y = 0, 0 -    tmp = 0 -            tmp += (K * (K + 1) // 2) % mod +            x += 1 -            tmp += (K * (K - 1) // 2) % mod -    tmp %= mod -    ans += tmp +            y += 1 +ans = x * K * (K + 1) // 2 + y * (K - 1) * K // 2