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)

#[warn(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1},
};

#[fastout]
fn main() {
   input! {
      n: usize,
      m: usize,
      k: usize
   }
   comb_init(n);
   let m = Mint::from(m);
   let mut ans = Mint::new(0);
   for i in 0..=k {
      ans += comb(n-1, i) * m * (m-Mint::new(1)).pow(n-i-1);
      // println!("{}", ans);
   }
   println!("{}", ans);
}

use std::ops::*;
const MOD: i64 = 998244353;
#[derive(Copy, Clone, Debug)]
pub struct Mint {
   x: i64,
}
impl Mint {
   fn new(x: i64) -> Self { Mint { x: x } }
   fn pow(self, n: usize) -> Self {
      let mut x = Mint::new(1);
      let mut r = self;
      let mut n = n;
      while n > 0 {
         if n & 1 == 1 {
            x *= r;
         }
         r *= r;
         n >>= 1;
      }
      x
   }
   fn inv(self) -> Self { self.pow((MOD - 2) as usize) }
}
impl AddAssign for Mint {
   fn add_assign(&mut self, rhs: Self) {
      self.x += rhs.x;
      self.x %= MOD;
   }
}
impl Add for Mint {
   type Output = Self;
   fn add(self, other: Self) -> Self {
      let mut res = self;
      res += other;
      res
   }
}
impl SubAssign for Mint {
   fn sub_assign(&mut self, rhs: Self) {
      self.x -= rhs.x;
      if self.x < 0 {
         self.x += MOD;
      }
   }
}
impl Sub for Mint {
   type Output = Self;
   fn sub(self, other: Self) -> Self {
      let mut res = self;
      res -= other;
      res
   }
}
impl MulAssign for Mint {
   fn mul_assign(&mut self, rhs: Self) {
      self.x *= rhs.x;
      self.x %= MOD;
   }
}
impl Mul for Mint {
   type Output = Self;
   fn mul(self, other: Self) -> Self {
      let mut res = self;
      res *= other;
      res
   }
}
impl DivAssign for Mint {
   fn div_assign(&mut self, rhs: Self) { *self *= rhs.inv(); }
}
impl Div for Mint {
   type Output = Self;
   fn div(self, other: Self) -> Self {
      let mut res = self;
      res *= other;
      res
   }
}
impl From<i64> for Mint {
   fn from(num: i64) -> Self { Mint { x: num } }
}
impl From<i32> for Mint {
   fn from(num: i32) -> Self { Mint { x: num as i64 } }
}
impl From<usize> for Mint {
   fn from(num: usize) -> Self { Mint { x: num as i64 } }
}
use std::fmt;
impl fmt::Display for Mint {
   fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.x) }
}
static mut MAX_N: usize = 1;
static mut FACT: Vec<Mint> = Vec::<Mint>::new();
static mut IFACT: Vec<Mint> = Vec::<Mint>::new();
static mut COMB_FLAG: bool = false;
fn comb_init(n: usize) {
   unsafe {
      COMB_FLAG = true;
      MAX_N = n;
      FACT = vec![Mint::new(1); MAX_N + 1];
      IFACT = vec![Mint::new(1); MAX_N + 1];
      for i in 1..MAX_N + 1 {
         FACT[i] = FACT[i - 1] * Mint::from(i as i64);
      }
      IFACT[MAX_N] = FACT[MAX_N as usize].inv();
      for i in (1..MAX_N + 1).rev() {
         IFACT[i - 1] = IFACT[i] * Mint::from(i as i64);
      }
   }
}
fn comb_check(n: usize, r: usize) -> bool { unsafe { !(n > MAX_N || r > n) } }
fn comb(n: usize, r: usize) -> Mint {
   unsafe {
      if !COMB_FLAG {
         panic!("FACT is not init");
      }
   }
   if !comb_check(n, r) {
      Mint::from(0)
   } else {
      unsafe { FACT[n] * IFACT[r] * IFACT[n - r] }
   }
}