import java.math.BigDecimal

const val mod: Long = 1000000007L

fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toLong() }
    val arr = readLine()!!.split(" ").map { it.toInt() }
    val leftCnt: Array<Long> = Array(n.toInt()) { 0L }
    for (i in 0 until arr.size) {
        var count = 0
        for (j in i + 1 until arr.size) {
            if (arr[i] > arr[j]) {
                count++
            }
        }
        leftCnt[i] = count.toLong()
    }
    val cnt = arr.map { i ->
        arr.filter { i > it }.count()
    }
    var ans = BigDecimal.ZERO
    val kk = (k*(k-1)/2) % mod
    ans += BigDecimal.valueOf(cnt.sum().toLong()) * BigDecimal.valueOf(kk) % BigDecimal.valueOf(mod)
    ans += BigDecimal.valueOf(leftCnt.sum() * k % mod)
    println(ans % BigDecimal.valueOf(mod))
}