n,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = a.sort
b.reverse!
a_count = 0
aa = a.dup
aa.each do |a_i|
  a_count += a.count { |a_j| a_j < a_i }
  a.delete_at(0)
end
b_count = 0
b.each do |b_i|
  b_count += b.count { |b_j| b_j < b_i }
end
puts ( a_count * k + b_count * k * (k - 1) / 2 ) % ( 10**9 + 7 )