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: Wrong Answer)

#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let n: usize = read!();
    let m: usize = read!();
    let k: usize = read!();

    let mut ans = ModInt::new(0);
    for k in 0..=k {
        let c: ModInt = if k != 0 { (n - k).into() } else { 1.into() };
        let a: ModInt = ModInt::new((m - 1) as isize).pow((n - k - 1) as usize) * m.into();
        ans += c * a;
    }
    println!("{}", ans);
}

use itertools::Itertools;
use std::fmt::{Display, Formatter};
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};

pub const MOD: isize = 998244353;

/// 常に設定したModを取り続ける正整数型
/// 初期Modは`Self::mod1()`の戻り値である`1000000007`
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub struct ModInt {
    /// 保持する値
    value: isize,
}

impl ModInt {
    /// isizeを受け取り、ModIntに変換する
    /// 初期Modは`Self::mod1()`
    pub fn new(n: isize) -> Self {
        let mut value = n % MOD;
        if value < 0 {
            value += MOD;
        }
        Self { value }
    }

    /// べき乗計算関数
    /// 二分累乗法を用いるため、計算量はO(log n)
    pub fn pow(self, n: usize) -> Self {
        if n == 0 {
            1.into()
        } else if n == 1 {
            self
        } else if n % 2 == 0 {
            (self * self.into()).pow(n / 2)
        } else {
            self * self.pow(n - 1)
        }
    }

    /// 逆元を返す
    /// フェルマーの少定理より、べき乗を用いて計算するため、計算量はO8log MOD)
    pub fn inv(self) -> Self {
        self.pow((MOD - 2) as usize)
    }
}

impl Display for ModInt {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.value)
    }
}

impl From<usize> for ModInt {
    fn from(n: usize) -> Self {
        Self::new(n as isize)
    }
}

impl From<u64> for ModInt {
    fn from(n: u64) -> Self {
        Self::new(n as isize)
    }
}

impl From<u32> for ModInt {
    fn from(n: u32) -> Self {
        Self::new(n as isize)
    }
}

impl From<u16> for ModInt {
    fn from(n: u16) -> Self {
        Self::new(n as isize)
    }
}

impl From<u8> for ModInt {
    fn from(n: u8) -> Self {
        Self::new(n as isize)
    }
}

impl From<isize> for ModInt {
    fn from(n: isize) -> Self {
        Self::new(n)
    }
}

impl From<i64> for ModInt {
    fn from(n: i64) -> Self {
        Self::new(n as isize)
    }
}

impl From<i32> for ModInt {
    fn from(n: i32) -> Self {
        Self::new(n as isize)
    }
}

impl From<i16> for ModInt {
    fn from(n: i16) -> Self {
        Self::new(n as isize)
    }
}

impl From<i8> for ModInt {
    fn from(n: i8) -> Self {
        Self::new(n as isize)
    }
}

impl Add for ModInt {
    type Output = Self;

    fn add(self, rhs: Self) -> Self::Output {
        let mut tmp = self.value + rhs.value;
        if tmp >= MOD {
            tmp %= MOD;
        }

        Self { value: tmp }
    }
}

impl AddAssign for ModInt {
    fn add_assign(&mut self, rhs: Self) {
        *self = *self + rhs
    }
}

impl Sub for ModInt {
    type Output = ModInt;

    fn sub(self, rhs: Self) -> Self::Output {
        let mut tmp = self.value;
        if tmp < rhs.value {
            tmp += MOD;
        }
        tmp -= rhs.value;
        if tmp >= MOD {
            tmp %= MOD;
        }

        Self { value: tmp }
    }
}

impl SubAssign for ModInt {
    fn sub_assign(&mut self, rhs: Self) {
        *self = *self - rhs;
    }
}

impl Mul for ModInt {
    type Output = ModInt;

    fn mul(self, rhs: Self) -> Self::Output {
        let mut tmp = self.value * rhs.value;
        if tmp >= MOD {
            tmp %= MOD;
        }

        Self { value: tmp }
    }
}

impl MulAssign for ModInt {
    fn mul_assign(&mut self, rhs: Self) {
        *self = *self * rhs;
    }
}

impl Div for ModInt {
    type Output = ModInt;

    fn div(self, rhs: Self) -> Self::Output {
        self * rhs.inv()
    }
}

impl DivAssign for ModInt {
    fn div_assign(&mut self, rhs: Self) {
        *self = *self / rhs;
    }
}

/// 高速に二項係数を求める構造体
pub struct Combination {
    /// `0..=n`分の階乗値を保持
    factorial: Vec<ModInt>,
    /// `0..=n`分の階乗値の逆元を保持
    factorial_inv: Vec<ModInt>,
}