MOD = 10**9+7
n,k = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
b = Array.new(n,0)
n.times do |i|
  x = a[i]
  (n-1).times do |j|
    if x > a[(i+j+1)%n]
      b[i] += 1
    end
  end
end
ans = 0
n.times do |i|
  ans += (b[i] * (k-1) * k / 2) % MOD
  ans %= MOD
end
for i in 0..n-2
  for j in (i+1)..n-1
    if a[i] > a[j]
      ans += k
      ans %= MOD
    end
  end
end
puts ans