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

nums = gets.split.map(&:to_i)

DIV = 10**9 + 7

$FACT_MUL = {}

def fact(num, i) 
    res = num
    mul = 0
    if $FACT_MUL.has_key?(i)
        mul = $FACT_MUL[i]
    else
        i.downto(1) { |j| mul += j }
        $FACT_MUL[i] = mul
    end
    res * [mul, 1].max
end

res = 0
nums.each_with_index do |outer_num, outer_idx|
    left_num = 0
    right_num = 0
    
    nums.each_with_index do |inner_num, inner_idx |
        if outer_num > inner_num
            if inner_idx < outer_idx
                left_num += 1
            else
                right_num += 1
            end
        end
    end
    res += fact(right_num, k)
    res += fact(left_num, k - 1)
end

puts res % DIV