require 'pp'

MOD = 10 ** 9 + 7

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

ans = Array.new(n, 0)
ans2 = Array.new(n, 0)

(n-1).times do |i|
    (i+1).upto(n-1) do |j|
        if a_n[i] > a_n[j]
            ans[i] += 1
        end
    end
end

sorta_n = a_n.sort!.reverse!
(n-1).times do |i|
    (i+1).upto(n-1) do |j|
        if sorta_n[i] > sorta_n[j]
            ans2[i] += 1
        end
    end
end

def ss(a, d, n)
    (n * (2 * a + (n - 1) * d)) / 2
end

sum = 0
ans2.each do |i|
    sum = (sum + ss(i, i, k - 1)) % MOD
end

ans.length.times do |i|
    sum = (ans[i] + sum + ans2[i] * (k - 1)) % MOD
end

pp sum % MOD

