fun main(arr: Array<String>) {
    println(solve())
}

fun solve():Long {
    val (n,k) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toInt() }
    val inner = (0 until a.lastIndex).map { idx-> (idx+1 until n).count { a[idx] > a[it] } }.sum()
    val outer = a.indices.map { idx -> a.indices.count { a[idx] > a[it] } }.sum()
    val mod = 1000000000 + 7
    var ans = k.toLong()*inner%mod
    ans += (k.toLong() * (k.toLong()-1) / 2) % mod * outer
    ans %= mod
    return ans
}

