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

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



mod = 10**9 + 7

intra, inter = 0, 0

for i in range(N):

    ai = A[i]

    for j in range(i, N):

        aj = A[j]

        if ai > aj:

            intra += 1

    for j in range(i + 1):

        aj = A[j]

        if ai > aj:

            inter += 1



ans = (intra * K * (K + 1) // 2) % mod

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

print((ans % mod))

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

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



class Bit:

    def __init__(self, n):

        self.size = n

        self.tree = [0] * (n + 1)



    def sum(self, i):

        ret = 0

        while i > 0:

            ret += self.tree[i]

            i -= i & -i

        return ret



    def add(self, i, x):

        while i <= self.size:

            self.tree[i] += x

            i += i & -i



inter = 0

for i in range(N):

    ai = A[i]

    for j in range(i + 1):

        aj = A[j]

        if ai > aj:

            inter += 1



bit = Bit(2000)



intra = 0

for i in range(len(A)):

    a = A[i]

    bit.add(a, 1)

    intra += i + 1 - bit.sum(a)



# print(inter, intra)



mod = 10**9 + 7



ans = (intra * K * (K + 1) // 2) % mod

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

print((ans % mod))

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

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


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        ret = 0
        while i > 0:
            ret += self.tree[i]
            i -= i & -i
        return ret

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


inter = 0
for i in range(N):
    ai = A[i]
    for j in range(i + 1):
        aj = A[j]
        if ai > aj:
            inter += 1
bit = Bit(2000)
intra = 0
for i in range(len(A)):
    a = A[i]
    bit.add(a, 1)
    intra += i + 1 - bit.sum(a)
# print(inter, intra)
mod = 10**9 + 7
ans = (intra * K * (K + 1) // 2) % mod
ans += (inter * (K - 1) * K // 2) % mod
print((ans % mod))

-mod = 10**9 + 7 -intra, inter = 0, 0 + + +class Bit: +    def __init__(self, n): +        self.size = n +        self.tree = [0] * (n + 1) + +    def sum(self, i): +        ret = 0 +        while i > 0: +            ret += self.tree[i] +            i -= i & -i +        return ret + +    def add(self, i, x): +        while i <= self.size: +            self.tree[i] += x +            i += i & -i + + +inter = 0 -    for j in range(i, N): -        aj = A[j] -        if ai > aj: -            intra += 1 +bit = Bit(2000) +intra = 0 +for i in range(len(A)): +    a = A[i] +    bit.add(a, 1) +    intra += i + 1 - bit.sum(a) +# print(inter, intra) +mod = 10**9 + 7