[<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

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

    let ll = (K - 1L) * K / 2L
    let rr = K * (K + 1L) / 2L
    let mutable ans = 0L
    for i in [0 .. N - 1] do
        let l, r = List.splitAt i AS
        let ls = l
        let m :: rs = r
        let ln = List.filter (fun x -> x < m) ls |> List.length |> int64
        let rn = List.filter (fun x -> x < m) rs |> List.length |> int64
        ans <- (ans + ln * ll + rn * rr) % INF

    printfn "%i" ans
    0