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)

//package abc167.F

import java.io.*
import java.math.*
import java.util.*
import kotlin.math.*

var reader: BufferedReader = System.`in`.bufferedReader()
var writer: PrintWriter = PrintWriter(System.`out`)

fun next() = reader.readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextStrings() = next().split(" ")
fun nextInts() = nextStrings().map { it.toInt() }
fun nextLongs() = nextStrings().map { it.toLong() }
fun nextDoubles() = nextStrings().map { it.toDouble() }

fun put(v: Any?) = writer.print(v)
fun puts() = writer.println()
fun puts(v: Any?) = writer.println(v)

var debug = false
fun dp(v: Any?) {
    if (debug) println(v)
}
fun dp() {
    if (debug) println()
}

class ModInt(
    v: Long
) {
    val value: Long

    init {
        value = v % M
    }

    constructor (value: Int): this(value.toLong())

    operator fun plus(rhs: ModInt): ModInt {
        return ModInt((value + rhs.value) % M)
    }
    operator fun minus(rhs: ModInt): ModInt {
        return ModInt((value - rhs.value + M) % M)
    }
    operator fun times(rhs: ModInt): ModInt {
        return ModInt((value * rhs.value) % M)
    }
    operator fun div(rhs: ModInt): ModInt {
        return ModInt(value * inv(rhs.value) % M)
    }
    private fun inv(v: Long): Long {
        return M - (((M / v) * inv(M % v)) % M)
    }

    fun pow(v: Int): ModInt {
        var result = 1L
        var x = v
        var vv = value
        while (x != 0) {
            if ((x and 1) != 0) {
                result = (result * vv) % M
            }
            vv = (vv * vv) % M
            x = x ushr 1
        }
        return ModInt(result)
    }

    override fun toString(): String {
        return value.toString()
    }

    companion object {
        private const val M = 998244353

        val ZERO = ModInt(0)
        val ONE = ModInt(1)

        var FACT = Array<ModInt>(0) { ModInt.ZERO }
        var INV = Array<ModInt>(0) { ModInt.ZERO }
        var INVFACT = Array<ModInt>(0) { ModInt.ZERO }

        fun prepareFact(N: Int) {
            FACT = Array<ModInt>(N+1) { ModInt.ONE }
            INV = Array<ModInt>(N+1) { ModInt.ONE }
            INVFACT = Array<ModInt>(N+1) { ModInt.ONE }

            val MM = ModInt(M)

            if (N > 1) FACT[1] = FACT[0] * ModInt(1)
            for (i in 2..N) {
                FACT[i] = FACT[i-1] * ModInt(i)
                INV[i] = MM - ModInt(M / i) * INV[M % i]
                INVFACT[i] = INVFACT[i-1] * INV[i]
            }
        }

        fun comb(n: Int, k: Int): ModInt {
            return FACT[n] * INVFACT[k] * INVFACT[n-k]
        }
    }
}

class Indexer(
    val Y: Int,
    val X: Int,
    val dy: Int = 0,
    val dx: Int = 0
) {
    val size: Int
        get() = X * Y

    operator fun invoke(y: Int, x: Int): Int {
        return (y+dy) * X + (x+dx)
    }

    fun <T> contentToString(arr: Array<T>): String {
        val builder = StringBuilder()

        builder.appendln("----------")
        for (y in 0 until Y) {
            for (x in 0 until X) {
                builder.append(arr[this(x, y)])
                builder.append(", ")
            }
            builder.appendln()
        }
        builder.append("----------")

        return builder.toString()
    }
}

fun test(case: Int, input: String, expected: String) {
    reader = input.trimIndent().reader().buffered()

    val stringWriter = StringWriter()
    writer = PrintWriter(stringWriter)

    solve()
    writer.flush()

    val actual = stringWriter.toString()

    println("[test $case]")
    if ("${expected}" == actual) {
        println("OK")
    } else {
        println("NG")
        println()
        println("expected: \"${expected}\"")
        println("actual:   \"${actual}\"")
    }
    println()
}

@Suppress("UNUSED_PARAMETER")
fun xtest(case: Int, input: String, expected: String) {}

fun main(args: Array<String>) {
    if ((args.size == 1) && (args[0] == "test")) {
        testAll()
    } else {
        solve()
        writer.flush()
    }
}

///////////////////////////////////////////////////////////

fun testAll() {
    debug = true

    test(1,
    """
    3 2 1
    """,
    "6")
    test(2,
    """
    100 100 0
    """,
    "73074801")
    test(3,
    """
    60522 114575 7559
    """,
    "479519525"
    )
    test(4,
    """
    1 1 0
    """,
    "1")
}

fun solve() {

    val (N, M, K) = nextInts()

    ModInt.prepareFact(N-1)

    var pow = ModInt(M-1).pow(N-1-K)
    val MM = ModInt(M)

    var result = ModInt.ZERO
    for (k in K downTo 0) {
        result += pow * ModInt.comb(N-1, k) * MM
        pow *= ModInt(M-1)
    }

    put(result)
}