n,k,*a=list(map(int,open(0).read().split()))

l=k*~-k//2

s=0

for i,c in enumerate(a):

 for d in a[i:]:s+=l*(c<d)+(l+k)*(c>d)

print((s%(10**9+7)))
n,k,*a=list(map(int,open(0).read().split()))

l=k*~-k//2

print((sum(l*(c<d)+(l+k)*(c>d)for i,c in enumerate(a)for d in a[i:])%(10**9+7)))
n, k, *a = list(map(int, open(0).read().split()))
l = k * ~-k // 2
s = 0
for i, c in enumerate(a):
    for d in a[i:]:
        s += l * (c < d) + (l + k) * (c > d)
print((s % (10**9 + 7)))

n, k, *a = list(map(int, open(0).read().split()))
l = k * ~-k // 2
print(
    (
        sum(l * (c < d) + (l + k) * (c > d) for i, c in enumerate(a) for d in a[i:])
        % (10**9 + 7)
    )
)

-s = 0 -for i, c in enumerate(a): -    for d in a[i:]: -        s += l * (c < d) + (l + k) * (c > d) -print((s % (10**9 + 7))) +print( +    ( +        sum(l * (c < d) + (l + k) * (c > d) for i, c in enumerate(a) for d in a[i:]) +        % (10**9 + 7) +    ) +)