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

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

import bisect

mod=10**9+7

AA=[]

ans1=0

for i in range(n):

  ans1+=i-bisect.bisect_right(AA,A[i])

  AA.append(A[i])

  AA.sort()

ans2=0

for i in range(n-1):

  ans2+=n-bisect.bisect_right(AA,AA[i])



ans=(ans1*k)%mod

ans=(ans+ans2*k*(k-1)//2)%mod

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

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

mod=10**9+7

import math

import bisect



n_max=2000

nn=int(math.log2(n_max))+1

BIT=[0]*(2**nn)

BIT.insert(0,0)



def bitsum(BIT,i):

  s=0

  while i>0:

    s+=BIT[i]

    i-=i&(-i)

  return s



def bitadd(BIT,i,x):

  while i<=n_max:

    BIT[i]+=x

    i+=i&(-i)

  return BIT



ans1=0

for i in range(n):

  ans1+=i-bitsum(BIT,A[i])

  bitadd(BIT,A[i],1)



ans2=0

A.sort()

for i in range(n-1):

  ans2+=n-bisect.bisect_right(A,A[i])



ans=(ans1*k)%mod

ans=(ans+ans2*k*(k-1)//2)%mod

print(ans)
n, k = list(map(int, input().split()))
A = [int(i) for i in input().split()]
import bisect

mod = 10**9 + 7
AA = []
ans1 = 0
for i in range(n):
    ans1 += i - bisect.bisect_right(AA, A[i])
    AA.append(A[i])
    AA.sort()
ans2 = 0
for i in range(n - 1):
    ans2 += n - bisect.bisect_right(AA, AA[i])
ans = (ans1 * k) % mod
ans = (ans + ans2 * k * (k - 1) // 2) % mod
print(ans)

n, k = list(map(int, input().split()))
A = [int(i) for i in input().split()]
mod = 10**9 + 7
import math
import bisect

n_max = 2000
nn = int(math.log2(n_max)) + 1
BIT = [0] * (2**nn)
BIT.insert(0, 0)


def bitsum(BIT, i):
    s = 0
    while i > 0:
        s += BIT[i]
        i -= i & (-i)
    return s


def bitadd(BIT, i, x):
    while i <= n_max:
        BIT[i] += x
        i += i & (-i)
    return BIT


ans1 = 0
for i in range(n):
    ans1 += i - bitsum(BIT, A[i])
    bitadd(BIT, A[i], 1)
ans2 = 0
A.sort()
for i in range(n - 1):
    ans2 += n - bisect.bisect_right(A, A[i])
ans = (ans1 * k) % mod
ans = (ans + ans2 * k * (k - 1) // 2) % mod
print(ans)

+mod = 10**9 + 7 +import math -mod = 10**9 + 7 -AA = [] +n_max = 2000 +nn = int(math.log2(n_max)) + 1 +BIT = [0] * (2**nn) +BIT.insert(0, 0) + + +def bitsum(BIT, i): +    s = 0 +    while i > 0: +        s += BIT[i] +        i -= i & (-i) +    return s + + +def bitadd(BIT, i, x): +    while i <= n_max: +        BIT[i] += x +        i += i & (-i) +    return BIT + + -    ans1 += i - bisect.bisect_right(AA, A[i]) -    AA.append(A[i]) -    AA.sort() +    ans1 += i - bitsum(BIT, A[i]) +    bitadd(BIT, A[i], 1) +A.sort() -    ans2 += n - bisect.bisect_right(AA, AA[i]) +    ans2 += n - bisect.bisect_right(A, A[i])