# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
class segtree:
    def __init__(self, n, init_val = 0):
        self.n = n
        self.init_val = init_val
        self.init = 0
        self.k = math.ceil(math.log2(n))
        if type(self.init_val) == int:
            self.bins = [init_val] * (1 << (self.k+1))
        elif len(self.init_val) >0:
            self.bins = [self.init] * (1<<(self.k+1))
            for idx, i in enumerate(range(1<<self.k, 1<<(self.k+1))):
                if len(self.init_val)>idx:
                    self.bins[i] = init_val[idx]
                else:
                    self.bins[i] = 0
        else:
            raise ValueError('init_val is invalid.')
        self.caliculate()

    def compare(self, l, r):
        return l + r

    def caliculate(self):
        k = self.k
        while k:
            for i in range(1<<k, 1<<(k+1)):
                if not i%2:
                    self.bins[i//2] = self.compare(self.bins[i], self.bins[i+1])
                else:continue
            k -= 1

    def update(self, idx, val):
        '''idx : 0-started index'''
        k = (1<<self.k) + idx
        self.bins[k] = val
        while k>1:
            self.bins[k // 2] = self.compare(self.bins[k // 2 * 2], self.bins[k // 2 * 2 + 1])
            k = k//2


    def eval(self, l, r):
        ret = self.init
        l = (1 << self.k) + l
        r = (1 << self.k) + r
        #print(l, r)
        while True:
            #print(l, r)
            if r - l == 1:
                ret = self.compare(ret, self.bins[l])
                ret = self.compare(ret, self.bins[r])
                break
            elif l == r:
                ret = self.compare(ret, self.bins[l])
                break
            else:
                done = False
                if l % 2:
                    ret = self.compare(ret, self.bins[l])
                    l += 1
                    done = True
                if not r % 2:
                    ret = self.compare(ret, self.bins[r])
                    r -= 1
                    done = True
                if not done:
                    l = l // 2
                    r = r // 2
        #print(ret)
        return ret

    def value(self, ind):
        return self.bins[(1<<self.k) + ind]

def run():
    N, K = list(map(int, sysread().split()))
    A = list(map(int, sysread().split()))
    st = segtree(2001, 0)
    T1 = [0] * N
    for i in list(range(N))[::-1]:
        T1[i] = st.eval(0, A[i]-1)
        st.update(A[i], st.value(A[i]) + 1)
        #print(st.bins)
    T2 = []
    for a in A:
        T2.append(st.eval(0, a-1))
    ret = 0
    mod = 10 ** 9 +7
    #print(T1, T2)
    tmp_k2 = K * (K-1) // 2
    tmp_k2 %= mod
    for t1, t2 in zip(T1, T2):
        ret += K * t1 % mod
        tmp = tmp_k2
        tmp %= mod
        tmp *= t2
        tmp %= mod
        ret += tmp
        ret %= mod
    print(ret)

if __name__ == "__main__":
    run()


Measured memory_bytes: 9652