input_lines = gets.chop.split.map(&:to_i)
input_lines2 = gets.chop.split.map(&:to_i)

n = input_lines[0]
k = input_lines[1]
count = 0
lines2Count = 0
lastNumCount = 0
sumK = 0

for arrayRow in 0...input_lines2.size
    for arrayRow2 in (arrayRow+1)...input_lines2.size
        if input_lines2[arrayRow] > input_lines2[arrayRow2]
            lines2Count = lines2Count + 1
        end
    end
end

if input_lines2[input_lines2.length - 1] > input_lines2[0]
    for arrayRow in 0...input_lines2.size
        if input_lines2[input_lines2.length - 1] > input_lines2[arrayRow]
            lastNumCount = lastNumCount + 1
        end
    end
end


a = k/2
b = k%2 + a
sumK = (k + 1) * a
if k%2 == 1
    sumK = sumK + b
end

decreaseK = k - 1
a = decreaseK/2
b = decreaseK%2 + a
sumL = (decreaseK + 1) * a
if decreaseK%2 == 1
    sumL = sumL + b
end


count = lines2Count*sumK + lastNumCount*sumL
puts count%1000000007