MOD_N = 10 ** 9 + 7

def main
  n, k = gets.chop.split.map(&:to_i)
  arr = gets.chop.split.map(&:to_i)
  index = make_index(arr)
  res = 0
  index.each do |n1, n2|
    c = (n1 + n2) * k * (k + 1) / 2 - n1 * k
    res += c
    res = res % MOD_N
  end
  puts res
end

def make_index(arr)
  arr.map.with_index do |a, i|
    [small_before(arr, a, i), small_after(arr, a, i)]
  end
end

def small_after(arr, a, i)
  c = 0
  (i+1).upto(arr.size - 1) do |j|
    c += 1 if arr[j] < a
  end
  return c
end

def small_before(arr, a, i)
  c = 0
  0.upto(i - 1) do |j|
    c += 1 if arr[j] < a
  end
  return c
end

if __FILE__ == $0
  main
end