fun main(args : Array<String>) {
    val (N, K) = readLine()!!.split(" ").map { it.toLong() }
    val A = readLine()!!.split(" ").map { it.toLong() }.toLongArray()

    var n = N.toInt()

    val all = LongArray(n, { 0 })
    val onlyAfter = LongArray(n, { 0 })

    val MOD = 1000000000 + 7
    var answer = 0L

    (0 until n).forEach { i ->
        (0 until n).forEach { j ->
            if (A[i] > A[j]) {
                if (j >= i) {
                    onlyAfter[i] = (onlyAfter[i] + 1) % MOD
                }
                all[i] = (all[i] + 1) % MOD
            }
        }
    }

    (0 until n).forEach { i ->
        answer = (answer + (onlyAfter[i] * K)) % MOD
        answer = (answer + ((K * (K - 1) / 2 % MOD) *  (all[i]))) % MOD
    }

    println(answer)
}
