# -*- coding: utf-8 -*-

# 

import math

import sys

import itertools

import numpy as np



DIV_NUM = 1000000000 + 7



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

N=int(INPUT_NUMS[0])

K=int(INPUT_NUMS[1])



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

AA = np.array(A)

if N==1:

    print((0))

    exit()



# https://kira000.hatenadiary.jp/entry/2019/02/23/053917

def bubble_sort(A):

    cnt = 0

    for i in range(len(A)):

        for j in range(len(A)-1, i, -1):

            if A[j] < A[j-1]:

                A[j], A[j-1] = A[j-1], A[j]

                cnt += 1

    return cnt



answer = bubble_sort(AA)



B = sorted(A)

q=0

p=B[0]

r=0

for i in range(1,N):

    if B[i]>p:

        p=B[i]

        r=i

    q += r



# print(answer,K)

answer = answer % DIV_NUM

answer = int(answer)

answer = (answer * K) % DIV_NUM

q = q % DIV_NUM

answer = answer + q * K * (K-1) // 2

answer = answer % DIV_NUM

print(answer)



# -*- coding: utf-8 -*-

# 

import math

import sys

import itertools



DIV_NUM = 1000000000 + 7



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

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

if N==1:

    print((0))

    exit()



answer = 0

for i in range(len(A)):

    for j in range(len(A)-1,i,-1):

        if A[j]<A[j-1]:

            A[j],A[j-1] = A[j-1],A[j]

            answer += 1



q=0

p=A[0]

r=0

for i in range(1,N):

    if A[i]>p:

        p=A[i]

        r=i

    q += r



answer = answer % DIV_NUM

answer = (answer * K) % DIV_NUM

q = q % DIV_NUM

answer = answer + q * K * (K-1) // 2

answer = answer % DIV_NUM

print(answer)



# -*- coding: utf-8 -*-
#
import math
import sys
import itertools
import numpy as np

DIV_NUM = 1000000000 + 7
INPUT_NUMS = list(map(int, input().split()))
N = int(INPUT_NUMS[0])
K = int(INPUT_NUMS[1])
A = [int(x) for x in input().split()]
AA = np.array(A)
if N == 1:
    print((0))
    exit()
# https://kira000.hatenadiary.jp/entry/2019/02/23/053917
def bubble_sort(A):
    cnt = 0
    for i in range(len(A)):
        for j in range(len(A) - 1, i, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                cnt += 1
    return cnt


answer = bubble_sort(AA)
B = sorted(A)
q = 0
p = B[0]
r = 0
for i in range(1, N):
    if B[i] > p:
        p = B[i]
        r = i
    q += r
# print(answer,K)
answer = answer % DIV_NUM
answer = int(answer)
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K - 1) // 2
answer = answer % DIV_NUM
print(answer)

# -*- coding: utf-8 -*-
#
import math
import sys
import itertools

DIV_NUM = 1000000000 + 7
N, K = list(map(int, input().split()))
A = [int(x) for x in input().split()]
if N == 1:
    print((0))
    exit()
answer = 0
for i in range(len(A)):
    for j in range(len(A) - 1, i, -1):
        if A[j] < A[j - 1]:
            A[j], A[j - 1] = A[j - 1], A[j]
            answer += 1
q = 0
p = A[0]
r = 0
for i in range(1, N):
    if A[i] > p:
        p = A[i]
        r = i
    q += r
answer = answer % DIV_NUM
answer = (answer * K) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K - 1) // 2
answer = answer % DIV_NUM
print(answer)

-import numpy as np -INPUT_NUMS = list(map(int, input().split())) -N = int(INPUT_NUMS[0]) -K = int(INPUT_NUMS[1]) +N, K = list(map(int, input().split())) -AA = np.array(A) -# https://kira000.hatenadiary.jp/entry/2019/02/23/053917 -def bubble_sort(A): -    cnt = 0 -    for i in range(len(A)): -        for j in range(len(A) - 1, i, -1): -            if A[j] < A[j - 1]: -                A[j], A[j - 1] = A[j - 1], A[j] -                cnt += 1 -    return cnt - - -answer = bubble_sort(AA) -B = sorted(A) +answer = 0 +for i in range(len(A)): +    for j in range(len(A) - 1, i, -1): +        if A[j] < A[j - 1]: +            A[j], A[j - 1] = A[j - 1], A[j] +            answer += 1 -p = B[0] +p = A[0] -    if B[i] > p: -        p = B[i] +    if A[i] > p: +        p = A[i] -# print(answer,K) -answer = int(answer)