n,k = gets.chomp.split.map(&:to_i)
a = gets.split.map!{|i | i.to_i}
b = []
inversion_n = 0

for k_i in 1..k do
  b = b + a
end

b.each_with_index do |b_i, index|
  unless b_i == 1
    for comparison_i in (index + 1)..(b.length - 1)
      if b_i > b[comparison_i]
        inversion_n += 1
      end
    end
  end
end

p inversion_n % (10 ** 9 + 7)