fun main(args: Array<String>){
    val (N,K) = readLine()!!.split(" ").map{ it.toLong()}
    var A = readLine()!!.split(" ").map{it.toInt()}
    var preOK = LongArray(N.toInt()) {0}
    var afterOK = LongArray(N.toInt()) {0}
    var wholeOK = LongArray(N.toInt()) {0}
    val MOD = 1000000007


    for(i in 0 until A.size){
        for(j in 0 until A.size){
            if(i > j && A[i] > A[j]){
                preOK[i]++
            }  else if(i < j && A[i] > A[j]) {
                afterOK[i]++
            }
        }
        wholeOK[i] = preOK[i] + afterOK[i]
    }
    var ans =0L

    for(i in 0 until A.size){
        ans += afterOK[i]*K
        ans %= MOD
        ans += ((K*(K-1)/2L) % MOD)  * wholeOK[i]
        ans %= MOD
    }


    while(ans<0) ans += MOD



    println(ans)
}