[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let tentou (xs: int64 list) =
    let rec aux acc = function
        | [] -> acc
        | x :: xs ->
            let d = List.filter (fun y -> y < x) xs |> List.length
            aux (acc + d) xs
    aux 0 xs |> int64

let lower (xs: int64 list) =
    let rec aux acc = function
        | [] -> acc
        | y :: ys ->
            let d = List.filter (fun x -> x < y) xs |> List.length
            aux (acc + d) ys
    aux 0 xs |> int64

[<EntryPoint>]
let main _ =
    let [N;K] = reads int64
    let K = int64 K
    let AS = reads int64
    let INF = 1000000007L

    let t1 = tentou AS
    let t2 = lower AS
    // eprintfn "*%A" (t1, t2)
    let a1 = (t1 * K) % INF
    let a2 = ((K * (K - 1L) / 2L) % INF) * t2
    // eprintfn "*%A" (a1, a2)
    let ans = (a1 + a2) % INF
    printfn "%i" ans
    0