mod = 10**9 + 7

n, k = list(map(int, input().split()))

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

v1 = v2 = 0

for i in range(n-1):

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

        if a[i] > a[j]: v1 += 1

for i in range(1, n):

    for j in range(i):

        if a[i] > a[j]: v2 += 1

x1 = k * (k + 1) // 2

x2 = k * (k - 1) // 2

ans = ((v1 * x1) + (v2 * x2)) % mod

print((int(ans)))
mod = 10**9 + 7

n, k = list(map(int, input().split()))

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

h = [0 for _ in range(2001)]

ans_1 = []

mi = 2001

for ai in reversed(a):

    h[ai] += 1

    mi = min(mi, ai)

    if mi == ai: continue

    ans_1.append(sum(h[:ai]))

h = [0 for _ in range(2001)]

ans_2 = []

mi = 2001

for ai in a:

    h[ai] += 1

    mi = min(mi, ai)

    if mi == ai: continue

    ans_2.append(sum(h[:ai]))

print((int((sum(ans_1) * (k * (k+1) // 2)) +

          (sum(ans_2) * (k * (k-1) // 2))) % mod))
mod = 10**9 + 7
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
v1 = v2 = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if a[i] > a[j]:
            v1 += 1
for i in range(1, n):
    for j in range(i):
        if a[i] > a[j]:
            v2 += 1
x1 = k * (k + 1) // 2
x2 = k * (k - 1) // 2
ans = ((v1 * x1) + (v2 * x2)) % mod
print((int(ans)))

mod = 10**9 + 7
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
h = [0 for _ in range(2001)]
ans_1 = []
mi = 2001
for ai in reversed(a):
    h[ai] += 1
    mi = min(mi, ai)
    if mi == ai:
        continue
    ans_1.append(sum(h[:ai]))
h = [0 for _ in range(2001)]
ans_2 = []
mi = 2001
for ai in a:
    h[ai] += 1
    mi = min(mi, ai)
    if mi == ai:
        continue
    ans_2.append(sum(h[:ai]))
print(
    (int((sum(ans_1) * (k * (k + 1) // 2)) + (sum(ans_2) * (k * (k - 1) // 2))) % mod)
)

-v1 = v2 = 0 -for i in range(n - 1): -    for j in range(i + 1, n): -        if a[i] > a[j]: -            v1 += 1 -for i in range(1, n): -    for j in range(i): -        if a[i] > a[j]: -            v2 += 1 -x1 = k * (k + 1) // 2 -x2 = k * (k - 1) // 2 -ans = ((v1 * x1) + (v2 * x2)) % mod -print((int(ans))) +h = [0 for _ in range(2001)] +ans_1 = [] +mi = 2001 +for ai in reversed(a): +    h[ai] += 1 +    mi = min(mi, ai) +    if mi == ai: +        continue +    ans_1.append(sum(h[:ai])) +h = [0 for _ in range(2001)] +ans_2 = [] +mi = 2001 +for ai in a: +    h[ai] += 1 +    mi = min(mi, ai) +    if mi == ai: +        continue +    ans_2.append(sum(h[:ai])) +print( +    (int((sum(ans_1) * (k * (k + 1) // 2)) + (sum(ans_2) * (k * (k - 1) // 2))) % mod) +)