Problem:
Score : 500 points

Problem Statement

There are N blocks arranged in a row. Let us paint these blocks.

We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways.

Find the number of ways to paint the blocks under the following conditions:

For each block, use one of the M colors, Color 1 through Color M, to paint it. It is not mandatory to use all the colors.

There may be at most K pairs of adjacent blocks that are painted in the same color.

Since the count may be enormous, print it modulo 998244353.

Constraints

All values in input are integers.

1 \leq N, M \leq 2 \times 10^5

0 \leq K \leq N - 1

Input

Input is given from Standard Input in the following format:

N M K

Output

Print the answer.

Sample Input 1

3 2 1

Sample Output 1

6

The following ways to paint the blocks satisfy the conditions: 112, 121, 122, 211, 212, and 221. Here, digits represent the colors of the blocks.

Sample Input 2

100 100 0

Sample Output 2

73074801

Sample Input 3

60522 114575 7559

Sample Output 3

479519525

Solution in Kotlin (1.3.71) (judge verdict: Accepted)

class ModInt(private var value: Long = 0L) {
    companion object {
        var modulo = 100_000_007L
    }
    constructor(value: Byte): this(value.toLong())
    constructor(value: Short): this(value.toLong())
    constructor(value: Int): this(value.toLong())

    init { initialize() }

    private fun initialize() {
        if (value in 0L until modulo) return
        value %= modulo
        if (value < 0L) value += modulo
    }

    fun inv(): ModInt {
        var (a, b, c, n) = listOf(value, modulo, 0L, 1L)
        while (b != 0L) {
            val (x, y, z, m) = listOf(b, a % b, n - a / b * c, c)
            a = x
            b = y
            c = z
            n = m
        }
        return ModInt(n)
    }

    fun <T : Number> pow(power: T): ModInt {
        var ret = 1L
        var i = value
        var n = power.toLong()
        while (n > 0L) {
            if (n and 1L == 1L) ret = ret * i % modulo
            i = i * i % modulo
            n = n shr 1
        }
        return ModInt(ret)
    }

    override fun toString(): String = value.toString()

    operator fun unaryPlus(): ModInt = this
    operator fun unaryMinus(): ModInt = if (value == 0L) this else ModInt(modulo-value)
    operator fun inc(): ModInt = if (value == 0L) this else ModInt(modulo-value)
    operator fun dec(): ModInt = if (value == 0L) ModInt(modulo-1L) else ModInt(value-1L)
    operator fun plus(other: ModInt): ModInt = if (value + other.value < modulo) ModInt(value + other.value)
    else ModInt(value + other.value - modulo)
    operator fun minus(other: ModInt): ModInt = if (value - other.value >= 0L) ModInt(value - other.value)
    else ModInt(value - other.value + modulo)
    operator fun times(other: ModInt): ModInt = if (value * other.value < modulo) ModInt(value * other.value)
    else ModInt(value * other.value % modulo)
    operator fun div(other: ModInt): ModInt = times(other.inv())

    operator fun <T : Number> plus(other: T): ModInt = plus(ModInt(other.toLong()))
    operator fun <T : Number> minus(other: T): ModInt = minus(ModInt(other.toLong()))
    operator fun <T : Number> times(other: T): ModInt = times(ModInt(other.toLong()))
    operator fun <T : Number> div(other: T): ModInt = div(ModInt(other.toLong()))
}

class ModUtils(private val n: Int) {

    private val f = Array(n+1) { ModInt() }
    private val invf = Array(n+1) { ModInt() }

    init { initialize() }

    private fun initialize() {
        f[0] = ModInt(1L)
        for (i in 1 until n+1) f[i] = f[i-1] * i
        invf[n] = f[n].inv()
        for (i in n downTo 1) invf[i-1] = invf[i] * i
    }

    fun perm(n: Int, k: Int) = f[n] * invf[n-k]
    fun comb(n: Int, k: Int) = perm(n, k) * invf[k]
    fun homo(n: Int, k: Int) = if (n == 0 && k == 0) ModInt(1L) else comb(n + k - 1, k)
}

lateinit var modUtils: ModUtils

fun main(args: Array<String>) {
    ModInt.modulo = 998244353L
    val (n, m, k) = readLine()!!.split(" ").map { it.toInt() }
    modUtils = ModUtils(n)
    var ans = ModInt()
    val p = ModInt(m-1)
    for (i in 0..k) ans += (n-1 C i) * p.pow(n-i-1)
    println(ans * m)
}

infix fun Int.P(other: Int) = modUtils.perm(this, other)
infix fun Int.C(other: Int) = modUtils.comb(this, other)
infix fun Int.H(other: Int) = modUtils.homo(this, other)