type Bit (n) =
    let size = n
    let mutable tree = Array.zeroCreate (n+1)

    member this.Sum (i) =
        let mutable sum = 0
        let mutable i' = i
        while i' > 0 do
            sum <- sum + tree.[i']
            i' <- i' - (i' &&& -i')
        sum

    member this.Add (i, x) =
        let mutable i' = i
        while i' <= size do
            tree.[i'] <- tree.[i'] + x
            i' <- i' + (i' &&& -i')

let reads f = stdin.ReadLine().Split(' ') |> Array.map f
let [| _; k |] = reads int
let xs = reads int |> Array.toList
let mutable bs = xs
for i = 0 to k - 1 do
    bs <- List.append bs xs

let bit = Bit (bs.Length)
let mutable sum = 0
for i = 0 to bs.Length-1 do
    bit.Add (bs.[i], 1)
    sum <- sum + i + 1 - bit.Sum (bs.[i])

printfn "%d" (sum%(int(10.**9.) + 7))