n,k = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)

num1 = Array.new(2000,0)
for i in 1..a.size do
    num1[a[-i]-1] += 1
end

num2 = Array.new(2000,0)

for i in 1..1999 do
    num2[i] = num2[i-1] + num1[i-1]
end

num1 = Array.new(2000,0)
cnt = 0
for i in 1..a.size do
    # print "--",a[-i],"--\n"
    tar = a[-i]-1
    a0 = 0
    d = num2[tar]
    for j in 1..a[-i]-1 do
        a0 += num1[j-1]
    end
    cnt += a0*k + d*k*(k-1)/2
    # print "a0 = ",a0,"\n"
    # print "d = ", d,"\n"
    num1[a[-i]-1] += 1
    # p cnt
end

# p ""
p cnt % (10**9 +7)