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

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

ans1 = 0

ans3 = 0

for i in range(n-1):

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

        if a[i]>a[j]:

            ans1+=1

        elif a[i]==a[j]:

            ans3+=1

ans2 = (n*(n-1))//2 - ans1 - ans3

print(((ans1*((1+k)*k)//2+ans2*(k*(k-1))//2)%(10**9+7)))
n,k = list(map(int,input().split()))

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

inv = lambda w:sum([sum([a[i]>a[j] for j in range(i+1,n)]) for i in range(n-1)])

inv1 = lambda w:sum([sum([a[i]==a[j] for j in range(i+1,n)]) for i in range(n-1)])

ans1 = inv(a)

ans3 = inv1(a)

ans2 = (n*(n-1))//2 - ans1 - ans3

print(((ans1*((1+k)*k)//2+ans2*(k*(k-1))//2)%(10**9+7)))
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans1 = 0
ans3 = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if a[i] > a[j]:
            ans1 += 1
        elif a[i] == a[j]:
            ans3 += 1
ans2 = (n * (n - 1)) // 2 - ans1 - ans3
print(((ans1 * ((1 + k) * k) // 2 + ans2 * (k * (k - 1)) // 2) % (10**9 + 7)))

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
inv = lambda w: sum([sum([a[i] > a[j] for j in range(i + 1, n)]) for i in range(n - 1)])
inv1 = lambda w: sum(
    [sum([a[i] == a[j] for j in range(i + 1, n)]) for i in range(n - 1)]
)
ans1 = inv(a)
ans3 = inv1(a)
ans2 = (n * (n - 1)) // 2 - ans1 - ans3
print(((ans1 * ((1 + k) * k) // 2 + ans2 * (k * (k - 1)) // 2) % (10**9 + 7)))

-ans1 = 0 -ans3 = 0 -for i in range(n - 1): -    for j in range(i + 1, n): -        if a[i] > a[j]: -            ans1 += 1 -        elif a[i] == a[j]: -            ans3 += 1 +inv = lambda w: sum([sum([a[i] > a[j] for j in range(i + 1, n)]) for i in range(n - 1)]) +inv1 = lambda w: sum( +    [sum([a[i] == a[j] for j in range(i + 1, n)]) for i in range(n - 1)] +) +ans1 = inv(a) +ans3 = inv1(a)