# -*- 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 , dtype='int64')



if N==1:

    print((0))

    exit()





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

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



def BIT_update(tree,x):

    while x <= 2000:

        tree[x] += 1

        y = x

        z = 1

        while y > 0:

            if y % 2 == 1:

                x += z

                break

            y //= 2

            z *= 2



def BIT_sum(tree,x):

    s = 0

    while x > 0:

        s += tree[x]

        y = x

        z = 1

        while y > 0:

            if y % 2 == 1:

                x -= z

                break

            y //= 2

            z *= 2

    return s

 

answer = N*(N-1)//2

for i in A:

    answer -= BIT_sum(tree,i)

    BIT_update(tree,i)



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

 

answer = answer * K + 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 , dtype='int64')
if N == 1:
    print((0))
    exit()
nn = int(math.log2(2000)) + 1
tree = [0] * (2**nn)


def BIT_update(tree, x):
    while x <= 2000:
        tree[x] += 1
        y = x
        z = 1
        while y > 0:
            if y % 2 == 1:
                x += z
                break
            y //= 2
            z *= 2


def BIT_sum(tree, x):
    s = 0
    while x > 0:
        s += tree[x]
        y = x
        z = 1
        while y > 0:
            if y % 2 == 1:
                x -= z
                break
            y //= 2
            z *= 2
    return s


answer = N * (N - 1) // 2
for i in A:
    answer -= BIT_sum(tree, i)
    BIT_update(tree, i)
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
answer = answer * K + q * K * (K - 1) // 2
answer = answer % DIV_NUM
print(answer)

+# import numpy as np -N, K = list(map(int, input().split())) +INPUT_NUMS = list(map(int, input().split())) +N = int(INPUT_NUMS[0]) +K = int(INPUT_NUMS[1]) +# AA = np.array(A , dtype='int64') -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 +nn = int(math.log2(2000)) + 1 +tree = [0] * (2**nn) + + +def BIT_update(tree, x): +    while x <= 2000: +        tree[x] += 1 +        y = x +        z = 1 +        while y > 0: +            if y % 2 == 1: +                x += z +                break +            y //= 2 +            z *= 2 + + +def BIT_sum(tree, x): +    s = 0 +    while x > 0: +        s += tree[x] +        y = x +        z = 1 +        while y > 0: +            if y % 2 == 1: +                x -= z +                break +            y //= 2 +            z *= 2 +    return s + + +answer = N * (N - 1) // 2 +for i in A: +    answer -= BIT_sum(tree, i) +    BIT_update(tree, i) +B = sorted(A) -p = A[0] +p = B[0] -    if A[i] > p: -        p = A[i] +    if B[i] > p: +        p = B[i] -answer = answer % DIV_NUM -answer = (answer * K) % DIV_NUM -q = q % DIV_NUM -answer = answer + q * K * (K - 1) // 2 +answer = answer * K + q * K * (K - 1) // 2