import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.max

const val MOD = 998244353L

fun main() {
    val jin = BufferedReader(InputStreamReader(System.`in`))
    val (n, k) = jin.readLine().split(" ").map { it.toInt() }
    val p = listOf(0) + jin.readLine().split(" ").map { it.toInt() }
    val pow = LongArray(200001)
    val powInv = LongArray(200001)
    pow[0] = 1L
    pow[1] = ((k - 1).toLong() * (k.toLong() pow -1)) % MOD
    powInv[0] = 1L
    powInv[1] = pow[1] pow -1
    for (j in 2..200000) {
        pow[j] = (pow[1] * pow[j - 1]) % MOD
        powInv[j] = (powInv[1] * powInv[j - 1]) % MOD
    }
    val bitSum = BinaryIndexTree(1, n)
    val bitAMT = BinaryIndexTree(1, n)
    var answer = 0L
    for (j in 1..n) {
        val ix = max(k, j)
        answer += pow[ix] * bitSum[1, p[j] - 1]
        answer += bitAMT[p[j] + 1, n]
        answer -= pow[ix] * bitSum[p[j] + 1, n]
        answer %= MOD
        bitSum.update(p[j], powInv[ix])
        bitAMT.update(p[j], 2L)
    }
    answer *= 2L pow -1
    answer %= MOD
    answer += MOD
    answer %= MOD
    println(answer)
}

class BinaryIndexTree(val treeFrom: Int, treeTo: Int) {
    val value = LongArray(treeTo - treeFrom + 2)

    fun update(index: Int, delta: Long) {
        var i = index + 1 - treeFrom
        while (i < value.size) {
            value[i] += delta
            value[i] %= MOD
            i += i and -i
        }
    }

    fun query(to: Int): Long {
        var res = 0L
        var i = to + 1 - treeFrom
        while (i > 0) {
            res += value[i]
            res %= MOD
            i -= i and -i
        }
        return res
    }

    operator fun get(from: Int, to: Int) = if (to < from) 0L else query(to) - query(from - 1)
}

const val MOD_TOTIENT = MOD.toInt() - 1

infix fun Long.pow(power: Int): Long {
    var e = power
    e %= MOD_TOTIENT
    if (e < 0) {
        e += MOD_TOTIENT
    }
    if (e == 0 && this == 0L) {
        return this
    }
    var b = this % MOD
    var res = 1L
    while (e > 0) {
        if (e and 1 != 0) {
            res *= b
            res %= MOD
        }
        b *= b
        b %= MOD
        e = e shr 1
    }
    return res
}