n,k = list(map(int,input().split()))

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



leftCount = 0

rightCount = 0

mod = 10**9 + 7



for i in range(n):

    for j in range(n):

        if arr[i] > arr[j]:

            if i < j:

                rightCount +=1

            else:

                leftCount +=1

leftCount = leftCount*k*(k-1)//2

rightCount = rightCount*k*(k+1)//2

count = (leftCount % mod) + (rightCount % mod)

count %= mod

print(count)
n, k = input().split()

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

n = int(n)

k = int(k)



rn_0 , rn_2 = 0, 0



for i in range(n-1):

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

    if l[i] > l[j]:

      rn_0 += 1



for i in range(n):

  for j in range(0, i):

    if l[i] > l[j]:

      rn_2 += 1



rn_0 *= k*(k+1)//2

rn_2 *= k*(k-1)//2



rn = (rn_0 % (10**9+7)) + (rn_2 % (10**9+7))

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

n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
leftCount = 0
rightCount = 0
mod = 10**9 + 7
for i in range(n):
    for j in range(n):
        if arr[i] > arr[j]:
            if i < j:
                rightCount += 1
            else:
                leftCount += 1
leftCount = leftCount * k * (k - 1) // 2
rightCount = rightCount * k * (k + 1) // 2
count = (leftCount % mod) + (rightCount % mod)
count %= mod
print(count)

n, k = input().split()
l = list(map(int, input().split()))
n = int(n)
k = int(k)
rn_0, rn_2 = 0, 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if l[i] > l[j]:
            rn_0 += 1
for i in range(n):
    for j in range(0, i):
        if l[i] > l[j]:
            rn_2 += 1
rn_0 *= k * (k + 1) // 2
rn_2 *= k * (k - 1) // 2
rn = (rn_0 % (10**9 + 7)) + (rn_2 % (10**9 + 7))
print((rn % (10**9 + 7)))

-n, k = list(map(int, input().split())) -arr = list(map(int, input().split())) -leftCount = 0 -rightCount = 0 -mod = 10**9 + 7 +n, k = input().split() +l = list(map(int, input().split())) +n = int(n) +k = int(k) +rn_0, rn_2 = 0, 0 +for i in range(n - 1): +    for j in range(i + 1, n): +        if l[i] > l[j]: +            rn_0 += 1 -    for j in range(n): -        if arr[i] > arr[j]: -            if i < j: -                rightCount += 1 -            else: -                leftCount += 1 -leftCount = leftCount * k * (k - 1) // 2 -rightCount = rightCount * k * (k + 1) // 2 -count = (leftCount % mod) + (rightCount % mod) -count %= mod -print(count) +    for j in range(0, i): +        if l[i] > l[j]: +            rn_2 += 1 +rn_0 *= k * (k + 1) // 2 +rn_2 *= k * (k - 1) // 2 +rn = (rn_0 % (10**9 + 7)) + (rn_2 % (10**9 + 7)) +print((rn % (10**9 + 7)))