require 'pp'

MOD = 10 ** 9 + 7

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

left = Array.new(n, 0)
right = Array.new(n, 0)

n.times do |i|
    n.times do |j|
        next if i == j

        if j < i && a_n[j] < a_n[i]
            left[i] += 1
        elsif j > i && a_n[j] < a_n[i]
            right[i] += 1
        end
    end
end

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

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

puts sum % MOD
