N,K = gets.split.map &:to_i
as = gets.split.map &:to_i
surp=Array.new(N,0)
surp_re=Array.new(N,0)

(0..N-1).to_a.repeated_permutation(2) do |i,j|
    surp[i]+=1 if as[i]>as[j]
    surp_re[i]+=1 if as[i]>as[j] && i<j
end
puts (0..N-1).to_a.map{|i|surp_re[i]*K+surp[i]*(K*(K-1)/2)}.inject(:+) % 1000000007
