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


for sum in 0...k
    sumK = sumK + sum + 1
end

count =  lines2Count * sumK + lastNumCount * (sumK- 1)

puts count % (1000000000+7)