class Bit:

    def __init__(self, n):

        self.size = n

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



    def sum(self, i):

        s = 0

        while i > 0:

            s += self.tree[i]

            i -= i & -i

        return s



    def add(self, i, x):

        while i <= self.size:

            self.tree[i] += x

            i += i & -i



mod = 10 ** 9 + 7

N, K = [int(i) for i in input().split()]

A = [int(i) for i in input().split()]



bit = Bit(2020)

X = 0

for i, p in enumerate(A):

    bit.add(p, 1)

    X += i + 1 - bit.sum(p)



bit = Bit(2020)

Y = 0

for i, p in enumerate(A * 2):

    bit.add(p, 1)

    Y += i + 1 - bit.sum(p)

Y -= 2 * X



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

print(ans)

class Bit:

    def __init__(self, n):

        self.size = n

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



    def sum(self, i):

        s = 0

        while i > 0:

            s += self.tree[i]

            i -= i & -i

        return s



    def add(self, i, x):

        while i <= self.size:

            self.tree[i] += x

            i += i & -i



mod = 10 ** 9 + 7

max_A = 2000

N, K = [int(i) for i in input().split()]

A = [int(i) for i in input().split()]



# internal inversion

bit = Bit(max_A)

X = 0

for i, p in enumerate(A):

    bit.add(p, 1)

    X += i + 1 - bit.sum(p)



# external inversion

Y = -X

for i, p in enumerate(A):

    bit.add(p, 1)

    Y += i + N + 1 - bit.sum(p)



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

print(ans)

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

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

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


mod = 10**9 + 7
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
bit = Bit(2020)
X = 0
for i, p in enumerate(A):
    bit.add(p, 1)
    X += i + 1 - bit.sum(p)
bit = Bit(2020)
Y = 0
for i, p in enumerate(A * 2):
    bit.add(p, 1)
    Y += i + 1 - bit.sum(p)
Y -= 2 * X
ans = (X * K + Y * K * (K - 1) // 2) % mod
print(ans)

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

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

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


mod = 10**9 + 7
max_A = 2000
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
# internal inversion
bit = Bit(max_A)
X = 0
for i, p in enumerate(A):
    bit.add(p, 1)
    X += i + 1 - bit.sum(p)
# external inversion
Y = -X
for i, p in enumerate(A):
    bit.add(p, 1)
    Y += i + N + 1 - bit.sum(p)
ans = (X * K + Y * K * (K - 1) // 2) % mod
print(ans)

+max_A = 2000 -bit = Bit(2020) +# internal inversion +bit = Bit(max_A) -bit = Bit(2020) -Y = 0 -for i, p in enumerate(A * 2): +# external inversion +Y = -X +for i, p in enumerate(A): -    Y += i + 1 - bit.sum(p) -Y -= 2 * X +    Y += i + N + 1 - bit.sum(p)