let scan_int () = Scanf.scanf " %d" (fun x -> x)
let print_int n = Printf.printf "%d\n" n
let scan_array len read_func = Array.init len (fun _ -> read_func())

let modulo = 1000000007
let fmod f a b = (f a b) mod modulo

let calc_inversion array len =
  let count = ref 0 in
  let _ =
    for i = 0 to len-2 do
      for j = i+1 to len-1 do
        if array.(i) > array.(j) then count := !count+1
      done
    done in
  !count

let () = 
  let n = scan_int() and k = scan_int() in
  let a = scan_array n scan_int in
  let inv_of_a = calc_inversion a n in
  let aa = Array.append a a in
  let inv_of_aa = calc_inversion aa (n*2) in
  let c = fmod (-) inv_of_aa (inv_of_a * 2) in
  let ans = fmod (+) (fmod ( * ) inv_of_a k) (fmod ( * ) c (k * (k-1) / 2 mod modulo)) in 
  print_int ans