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 Rust (1.42.0) (judge verdict: Accepted)

use proconio::{fastout, input};

const MOD: i64 = 998244353;
struct Combination {
    fact: Vec<i64>,
    fact_inv: Vec<i64>,
}
impl Combination {
    fn init(n: usize) -> Combination {
        let mut fact = vec![0 as i64; n];
        let mut fact_inv = vec![0 as i64; n];
        fact[0] = 1;
        fact[1] = 1;
        fact_inv[0] = 1;
        fact_inv[1] = 1;
        for i in 2..n {
            fact[i] = fact[i - 1] * i as i64 % MOD;
        }
        for i in 2..n {
            let k = i as i64;
            fact_inv[i] = fact_inv[(MOD % k) as usize] * (MOD - MOD / k) % MOD;
        }
        for i in 2..n {
            fact_inv[i] = fact_inv[i - 1] * fact_inv[i] % MOD;
        }

        Combination { fact, fact_inv }
    }

    fn get(&self, n: usize, r: usize) -> i64 {
        if n == 0 || r == 0 {
            return 1;
        }
        self.fact[n] * self.fact_inv[n - r] % MOD * self.fact_inv[r] % MOD
    }
}

fn pow_mod(x: i64, y: i64, m: i64) -> i64 {
    if x == 0 {
        if y == 0 {
            return 1;
        } else {
            return 0;
        }
    }
    if y == 0 {
        return 1;
    }
    if (y & 1) == 1 {
        x * pow_mod(x * x % m, y >> 1, m) % m
    } else {
        pow_mod(x * x % m, y >> 1, m)
    }
}

#[fastout]
fn main() {
    input! {
        n: i64,
        m:i64,
        k:i64,
    }

    let mut ans: i64 = 0;
    let ncr = Combination::init((n + 1) as usize);
    for i in 0..(k + 1) {
        let j = n - 1 - i;
        ans += pow_mod(m - 1, j as i64, MOD) * ncr.get((n - 1) as usize, i as usize) % MOD;
        ans %= MOD;
    }
    ans = ans * m % MOD;
    println!("{}", ans);
}