let k = nk.[1]
let a = stdin.ReadLine().Split() |> Array.map int64 |> Array.toList

let rec f ls acc =
 match ls with
 | [] -> acc
 | hd :: tl -> let count = (tl |> List.map (fun x -> if x < hd then 1 else 0) |> List.sum)
               f tl (acc + count)

let syokou = (f a 0 |> int64)
let nikou = (f (a @ a) 0 |> int64)

let g(x)= x % 1000000007L
let h(x,y)= g(g(x) - g(y) + 1000000007L)
let i(x,y) = g(g(x) * g(y))
let kk = if k % 2L = 0L then g(g(k / 2L) * g(k + 1L)) else g(g(k) * g((k + 1L) / 2L))

g(i(h(nikou,i(syokou,2L)),kk) + i(h(i(syokou,3L),nikou),k))
|>stdout.WriteLine