open System

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<EntryPoint>]
let main _ =
    let [|N;K|] = reada int
    let A = reada int64

    let m = (int64 1e9) + 7L

    /// 初項1, 公差1, 項数 K * x, 末項 1 + (k - 1) * 1 の総和
    let f x =
        if x <= 0L then 0L
        else
            let n = (x % m) * ((int64 K) % m)
            let n = n % m
            let l = 1L + (n - 1L) * 1L
            (n % m) * ((1L + l) % m) / 2L

    let s = seq {
        for i in 0..N-1 do
            let a = A.[i]
            let _, rem = Array.splitAt i A
            yield Array.filter (fun x -> a > x) rem |> Array.length |> int64
    }
    s
    |> Seq.map f
    |> Seq.sumBy (fun x -> x % m)
    |> fun x -> x % m
    |> printfn "%d"
    0 // return an integer exit code
