import sys, math, itertools, bisect, copy, re



from collections import Counter, deque, defaultdict

from itertools import accumulate, permutations, combinations, takewhile, compress, cycle

from functools import reduce

from math import ceil, floor, log10, log2, factorial

from pprint import pprint



# 10倍速いらしい

input = sys.stdin.readline



INF = float('inf')

MOD = 10 ** 9 + 7

EPS = 10 ** -7

sys.setrecursionlimit(1000000)



# N = int(input())

# N,M = [int(x) for x in input().split()]

# V = [[0] * 100 for _ in range(100)]

# A = [int(input()) for _ in range(N)]

# DP = [[0] * 100 for _ in range(100)]

# DP = defaultdict(lambda: float('inf'))



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

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



T1 = [0] * N

T2 = [0] * N



for i in range(N - 1):

    for j in range(i + 1, N):

        if A[i] > A[j]:

            T1[i] += 1



for i in range(N):

    for j in range(0, N):

        if A[i] > A[j]:

            T2[i] += 1



ans = sum(T1) * K

ans %= MOD

ans += sum(T2) * K * (K - 1) // 2

ans %= MOD



print(ans)

# print(T1)

# print(T2)

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

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





z = 0

for i in range(N-1):

    for j in range(i+1, N):

        if A[i] > A[j]:

            z += 1



y = 0

for a1 in A:

    for a2 in A:

        if a1 > a2:

            y+=1



mod = 10**9 + 7



ans = z * (K) + y * (K) * (K-1)//2

print((ans % mod))



import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

# 10倍速いらしい
input = sys.stdin.readline
INF = float("inf")
MOD = 10**9 + 7
EPS = 10**-7
sys.setrecursionlimit(1000000)
# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
T1 = [0] * N
T2 = [0] * N
for i in range(N - 1):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            T1[i] += 1
for i in range(N):
    for j in range(0, N):
        if A[i] > A[j]:
            T2[i] += 1
ans = sum(T1) * K
ans %= MOD
ans += sum(T2) * K * (K - 1) // 2
ans %= MOD
print(ans)
# print(T1)
# print(T2)

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
z = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            z += 1
y = 0
for a1 in A:
    for a2 in A:
        if a1 > a2:
            y += 1
mod = 10**9 + 7
ans = z * (K) + y * (K) * (K - 1) // 2
print((ans % mod))

-import sys, math, itertools, bisect, copy, re -from collections import Counter, deque, defaultdict -from itertools import accumulate, permutations, combinations, takewhile, compress, cycle -from functools import reduce -from math import ceil, floor, log10, log2, factorial -from pprint import pprint - -# 10倍速いらしい -input = sys.stdin.readline -INF = float("inf") -MOD = 10**9 + 7 -EPS = 10**-7 -sys.setrecursionlimit(1000000) -# N = int(input()) -# N,M = [int(x) for x in input().split()] -# V = [[0] * 100 for _ in range(100)] -# A = [int(input()) for _ in range(N)] -# DP = [[0] * 100 for _ in range(100)] -# DP = defaultdict(lambda: float('inf')) -T1 = [0] * N -T2 = [0] * N +z = 0 -            T1[i] += 1 -for i in range(N): -    for j in range(0, N): -        if A[i] > A[j]: -            T2[i] += 1 -ans = sum(T1) * K -ans %= MOD -ans += sum(T2) * K * (K - 1) // 2 -ans %= MOD -print(ans) -# print(T1) -# print(T2) +            z += 1 +y = 0 +for a1 in A: +    for a2 in A: +        if a1 > a2: +            y += 1 +mod = 10**9 + 7 +ans = z * (K) + y * (K) * (K - 1) // 2 +print((ans % mod))