MOD = 1000000007

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

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

def bubble_sort(A):

    cnt = 0

    for i in range(len(A)):

        for j in range(len(A)-1, i, -1):

            if A[j] < A[j-1]:

                A[j], A[j-1] = A[j-1], A[j]

                cnt += 1

    return cnt

def sigma(k):

    return int(k*(k+1)//2)

C = []

for k in range(2):

    C.extend(A)

cnt = bubble_sort(A)

diff = bubble_sort(C) - 2 * cnt

a = (K*cnt)

b = (diff*sigma(K-1))

print(((a+b)%MOD))

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)



import numpy as np



MOD = 10**9 + 7



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

A = np.array(input().split(), dtype=np.int64)



# 同じグループ内

def type_1():

    bl1 = A[:,None] > A[None,:]

    bl2 = np.arange(N,dtype=np.int64)[:,None] < np.arange(N,dtype=np.int64)[None,:]

    x = ((bl1 & bl2)*1).astype(np.int64).sum() % MOD

    return x*K%MOD



def type_2():

    # グループ間

    counter = np.bincount(A)

    cum = counter.cumsum()

    larger = N-cum

    x = (larger * counter % MOD).sum() % MOD

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

    return x*y%MOD



answer = (type_1() + type_2()) % MOD

print(answer)

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


def bubble_sort(A):
    cnt = 0
    for i in range(len(A)):
        for j in range(len(A) - 1, i, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                cnt += 1
    return cnt


def sigma(k):
    return int(k * (k + 1) // 2)


C = []
for k in range(2):
    C.extend(A)
cnt = bubble_sort(A)
diff = bubble_sort(C) - 2 * cnt
a = K * cnt
b = diff * sigma(K - 1)
print(((a + b) % MOD))

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
import numpy as np

MOD = 10**9 + 7
N, K = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.int64)
# 同じグループ内
def type_1():
    bl1 = A[:, None] > A[None, :]
    bl2 = np.arange(N, dtype=np.int64)[:, None] < np.arange(N, dtype=np.int64)[None, :]
    x = ((bl1 & bl2) * 1).astype(np.int64).sum() % MOD
    return x * K % MOD


def type_2():
    # グループ間
    counter = np.bincount(A)
    cum = counter.cumsum()
    larger = N - cum
    x = (larger * counter % MOD).sum() % MOD
    y = K * (K - 1) // 2 % MOD
    return x * y % MOD


answer = (type_1() + type_2()) % MOD
print(answer)

-MOD = 1000000007 +import sys + +input = sys.stdin.readline +sys.setrecursionlimit(10**7) +import numpy as np + +MOD = 10**9 + 7 -A = list(map(int, input().split())) +A = np.array(input().split(), dtype=np.int64) +# 同じグループ内 +def type_1(): +    bl1 = A[:, None] > A[None, :] +    bl2 = np.arange(N, dtype=np.int64)[:, None] < np.arange(N, dtype=np.int64)[None, :] +    x = ((bl1 & bl2) * 1).astype(np.int64).sum() % MOD +    return x * K % MOD -def bubble_sort(A): -    cnt = 0 -    for i in range(len(A)): -        for j in range(len(A) - 1, i, -1): -            if A[j] < A[j - 1]: -                A[j], A[j - 1] = A[j - 1], A[j] -                cnt += 1 -    return cnt +def type_2(): +    # グループ間 +    counter = np.bincount(A) +    cum = counter.cumsum() +    larger = N - cum +    x = (larger * counter % MOD).sum() % MOD +    y = K * (K - 1) // 2 % MOD +    return x * y % MOD -def sigma(k): -    return int(k * (k + 1) // 2) - - -C = [] -for k in range(2): -    C.extend(A) -cnt = bubble_sort(A) -diff = bubble_sort(C) - 2 * cnt -a = K * cnt -b = diff * sigma(K - 1) -print(((a + b) % MOD)) +answer = (type_1() + type_2()) % MOD +print(answer)