N, K = list(map(int, input().split()))

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



x = 0

for l in range(N - 1):

  for r in range(l + 1, N):

    if A[l] > A[r]:

      x += 1

# print(x)

      

AA = A + A

y = 0

for l in range(2 * N - 1):

  for r in range(l + 1, 2 * N):

    if AA[l] > AA[r]:

      y += 1

y -= 2 * x

# print(y)

  

print((int((K * x + K * (K - 1) * y // 2) % (10 ** 9 + 7))))

N, K = list(map(int, input().split()))

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



x = 0

for l in range(N - 1):

  for r in range(l + 1, N):

    if A[l] > A[r]:

      x += 1

# print(x)

      

AA = A + A

y = 0

for l in range(N):

  for r in range(N):

    if AA[l] > AA[r]:

      y += 1

# print(y)

  

print((int((K * x + K * (K - 1) * y // 2) % (10 ** 9 + 7))))

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
x = 0
for l in range(N - 1):
    for r in range(l + 1, N):
        if A[l] > A[r]:
            x += 1
# print(x)
AA = A + A
y = 0
for l in range(2 * N - 1):
    for r in range(l + 1, 2 * N):
        if AA[l] > AA[r]:
            y += 1
y -= 2 * x
# print(y)
print((int((K * x + K * (K - 1) * y // 2) % (10**9 + 7))))

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
x = 0
for l in range(N - 1):
    for r in range(l + 1, N):
        if A[l] > A[r]:
            x += 1
# print(x)
AA = A + A
y = 0
for l in range(N):
    for r in range(N):
        if AA[l] > AA[r]:
            y += 1
# print(y)
print((int((K * x + K * (K - 1) * y // 2) % (10**9 + 7))))

-for l in range(2 * N - 1): -    for r in range(l + 1, 2 * N): +for l in range(N): +    for r in range(N): -y -= 2 * x