# jsc2019-qualB - Kleene Inversion

from collections import Counter

from itertools import accumulate





def main():

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

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

    MOD = 10 ** 9 + 7

    C = list(Counter(A).values())

    ac = list(accumulate(C[:-1]))

    x = sum(i * j for i, j in zip(C[1:], ac)) % MOD

    y = sum(sum(b > a for b in A[i + 1 :]) for i, a in enumerate(A[:-1]))

    ans = (x * (1 + K) * K // 2) % MOD

    ans = (ans - y * K) % MOD

    print(ans)





if __name__ == "__main__":

    main()
# jsc2019-qualB - Kleene Inversion

class BIT:  # Binary Indexed Tree (Fenwick Tree)

    def __init__(self, lim):

        self.size = lim

        self.tree = [0] * (lim + 1)  # 1-idx



    def add(self, i, x):  # add x to tree[i], O(logN)

        while i <= self.size:

            self.tree[i] += x

            i += i & -i



    def sum(self, i):  # sum of [1, i], O(logN)

        ret = 0

        while i > 0:

            ret += self.tree[i]

            i -= i & -i

        return ret



    def range_sum(self, l, r):  # range sum of [l, r]

        return self.sum(r) - self.sum(l - 1)





def main():

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

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

    MOD = 10 ** 9 + 7

    bit = BIT(2000)

    x = 0

    for i, a in enumerate(A, 1):  # internal inversion

        bit.add(a, 1)

        x += i - bit.sum(a)

    y = -x

    for i, a in enumerate(A, 1):  # external inversion

        bit.add(a, 1)

        y += i + N - bit.sum(a)

    ans = (x * K + y * K * (K - 1) // 2) % MOD

    print(ans)





if __name__ == "__main__":

    main()
# jsc2019-qualB - Kleene Inversion
from collections import Counter
from itertools import accumulate


def main():
    N, K = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))
    MOD = 10**9 + 7
    C = list(Counter(A).values())
    ac = list(accumulate(C[:-1]))
    x = sum(i * j for i, j in zip(C[1:], ac)) % MOD
    y = sum(sum(b > a for b in A[i + 1 :]) for i, a in enumerate(A[:-1]))
    ans = (x * (1 + K) * K // 2) % MOD
    ans = (ans - y * K) % MOD
    print(ans)


if __name__ == "__main__":
    main()

# jsc2019-qualB - Kleene Inversion
class BIT:  # Binary Indexed Tree (Fenwick Tree)
    def __init__(self, lim):
        self.size = lim
        self.tree = [0] * (lim + 1)  # 1-idx

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

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

    def range_sum(self, l, r):  # range sum of [l, r]
        return self.sum(r) - self.sum(l - 1)


def main():
    N, K = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))
    MOD = 10**9 + 7
    bit = BIT(2000)
    x = 0
    for i, a in enumerate(A, 1):  # internal inversion
        bit.add(a, 1)
        x += i - bit.sum(a)
    y = -x
    for i, a in enumerate(A, 1):  # external inversion
        bit.add(a, 1)
        y += i + N - bit.sum(a)
    ans = (x * K + y * K * (K - 1) // 2) % MOD
    print(ans)


if __name__ == "__main__":
    main()

-from collections import Counter -from itertools import accumulate +class BIT:  # Binary Indexed Tree (Fenwick Tree) +    def __init__(self, lim): +        self.size = lim +        self.tree = [0] * (lim + 1)  # 1-idx + +    def add(self, i, x):  # add x to tree[i], O(logN) +        while i <= self.size: +            self.tree[i] += x +            i += i & -i + +    def sum(self, i):  # sum of [1, i], O(logN) +        ret = 0 +        while i > 0: +            ret += self.tree[i] +            i -= i & -i +        return ret + +    def range_sum(self, l, r):  # range sum of [l, r] +        return self.sum(r) - self.sum(l - 1) -    C = list(Counter(A).values()) -    ac = list(accumulate(C[:-1])) -    x = sum(i * j for i, j in zip(C[1:], ac)) % MOD -    y = sum(sum(b > a for b in A[i + 1 :]) for i, a in enumerate(A[:-1])) -    ans = (x * (1 + K) * K // 2) % MOD -    ans = (ans - y * K) % MOD +    bit = BIT(2000) +    x = 0 +    for i, a in enumerate(A, 1):  # internal inversion +        bit.add(a, 1) +        x += i - bit.sum(a) +    y = -x +    for i, a in enumerate(A, 1):  # external inversion +        bit.add(a, 1) +        y += i + N - bit.sum(a) +    ans = (x * K + y * K * (K - 1) // 2) % MOD