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

print((sum(k*~-k//2*(c<d)+k*-~k//2*(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()))

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

-            k * ~-k // 2 * (c < d) + k * -~k // 2 * (c > d) +            k * ~-k * (c < d) + k * -~k * (c > d) >> 1