MOD = 1e+9.to_i + 7

def total(n)
  (n * (n + 1)) / 2
end

def main(argv)
  (n, k) = gets.chomp.split(' ').map(&:to_i)
  a = gets.chomp.split(' ').map(&:to_i)
  
  cnt = 0
  
  n.times do |i|
    l = 0
    (0...i).each do |j|
      if a[j] < a[i] then
        l += 1
      end
    end
    
    r = 0
    ((i + 1)...n).each do |j|
      if a[j] < a[i] then
        r += 1
      end
    end
    
    xl = (total(k - 1) * l) % MOD
    cnt = (cnt + xl) % MOD
    
    xr  = (total(k) * r) % MOD
    cnt = (cnt + xr) % MOD
  end
  
  puts cnt.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end