We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.  Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.  Find the inversion number of B, modulo 10^9 + 7.  Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = sorted(a)
#print(b.index(a[0]))
ans = 0
in_ = [0]*n 
after = [0]*n 
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            
            in_[i] += 1
            if i < j:
                after[i] += 1
print(in_)
print(after)
for i in range(n):
    ans += after[i]*k + (k*(k-1)//2) * in_[i]
ans %= 1000000007
print(int(ans))

n,k = map(int,input().split())
a = list(map(int,input().split()))
b = sorted(a)
#print(b.index(a[0]))
ans = 0
in_ = [0]*n 
after = [0]*n 
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            
            in_[i] += 1
            if i < j:
                after[i] += 1
#print(in_)
#print(after)
for i in range(n):
    ans += after[i]*k + (k*(k-1)//2) * in_[i]
ans %= 1000000007
print(int(ans))
