private const val MODVAL = 1e9.toInt() + 7

fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val inputs = readLine()!!.split(" ").map { it.toInt() }

//    // bit を作成する
//    val bit = BIT(n)
//    for (i in 0 until inputs.size){
//        bit.add(i+1, inputs[i])
//    }

//    println(bit.tree.toList())
//    println(bit.sum(3))
//    println(BIT(6).calcInversionNumber(listOf(1,6,3,2)))


    // N の整数列, 並びに２つの間での転倒数さえ求めれば後は計算するだけでは？

    // N 内
    var inside = BIT(inputs.max()!!).calcInversionNumber(inputs) % MODVAL

    // N 間
    var bet = 0
    for ( i in inputs) {
        for (j in inputs) {
            if ( i > j) {
                bet += 1
            }
        }
    }

    // N が k 個ある時の転倒数
    var ans = 0L
    if (k == 1) {
        ans = inside.toLong()
    } else {
        ans = ((inside.toLong() * k % MODVAL) + (bet.toLong() * ((k.toLong() * (k.toLong() - 1)/2) % MODVAL)) % MODVAL) % MODVAL
    }

    println(ans)

}


class BIT(val n: Int) {
    val tree = IntArray(n + 1) { 0 }

    fun add(index: Int, value: Int) {
        var indexTmp = index
        while( indexTmp <= tree.size-1) {
            tree[indexTmp] = (tree[indexTmp] + value) % MODVAL
            indexTmp += indexTmp and -indexTmp
        }
    }

    fun sum(index: Int): Int {
        var sum = 0
        var indexTmp = index
        while( indexTmp > 0 ){
            sum = (sum + tree[indexTmp]) % MODVAL
            indexTmp -= indexTmp and -indexTmp
        }

        return sum
    }

    fun calcInversionNumber(inputs: List<Int>): Int {
        var sum = 0
        for(j in 0 until inputs.size) {
            val index = inputs[j]
            sum = sum + j - this.sum(index)
            this.add(index, 1)
        }
        return sum
    }
}