

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



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



mod = 1000000007



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

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

ans = 0



freq = []

before = []

for i in range(0, 3000):

	freq.append(0)

	before.append(0)

	



for i in range(0, n):

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

		if(a[i] > a[j]):

			freq[i] += 1

			

	j = i - 1

	while j >= 0:

		if(a[i] > a[j]):

			before[i] += 1

		j -= 1

		

	ans += (freq[i] * need)

	ans += (before[i] * need2)



#print(ans)

print((ans % mod))
n, k = list(map(int,input().split()))

 

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

 

mod = 1000000007

 

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

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

ans = 0

 

freq = []

before = []

for i in range(0, 3000):

	freq.append(0)

	before.append(0)

	

 

for i in range(0, n):

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

		if(a[i] > a[j]):

			freq[i] += 1

			

	j = i - 1

	while j >= 0:

		if(a[i] > a[j]):

			before[i] += 1

		j -= 1

		

	ans += (freq[i] * need)

	ans += (before[i] * need2)

	ans %= mod

 

#print(ans)

print((ans % mod))
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 1000000007
need = (k * (k + 1)) // 2
need2 = ((k - 1) * k) // 2
ans = 0
freq = []
before = []
for i in range(0, 3000):
    freq.append(0)
    before.append(0)
for i in range(0, n):
    for j in range(i + 1, n):
        if a[i] > a[j]:
            freq[i] += 1
    j = i - 1
    while j >= 0:
        if a[i] > a[j]:
            before[i] += 1
        j -= 1
    ans += freq[i] * need
    ans += before[i] * need2
# print(ans)
print((ans % mod))

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 1000000007
need = (k * (k + 1)) // 2
need2 = ((k - 1) * k) // 2
ans = 0
freq = []
before = []
for i in range(0, 3000):
    freq.append(0)
    before.append(0)
for i in range(0, n):
    for j in range(i + 1, n):
        if a[i] > a[j]:
            freq[i] += 1
    j = i - 1
    while j >= 0:
        if a[i] > a[j]:
            before[i] += 1
        j -= 1
    ans += freq[i] * need
    ans += before[i] * need2
    ans %= mod
# print(ans)
print((ans % mod))

+    ans %= mod