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)

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

pub mod fp {

    use std::convert::From;
    use std::iter;
    use std::ops;

    const P: u32 = 998244353;

    #[derive(Copy, Clone, Debug)]
    pub struct Fp(pub u32);

    impl Fp {
        pub fn pow(mut self, mut exp: u32) -> Fp {
            let mut res = Fp(1);
            while exp != 0 {
                if exp % 2 != 0 {
                    res *= self;
                }
                self *= self;
                exp /= 2;
            }
            res
        }
    }

    impl From<i64> for Fp {
        fn from(mut x: i64) -> Fp {
            x %= P as i64;
            if x < 0 {
                x += P as i64;
            }
            Fp(x as u32)
        }
    }

    impl iter::Product for Fp {
        fn product<I>(iter: I) -> Fp
        where
            I: Iterator<Item = Fp>,
        {
            iter.fold(Fp(1), |b, i| b * i)
        }
    }

    impl iter::Sum for Fp {
        fn sum<I>(iter: I) -> Fp
        where
            I: Iterator<Item = Fp>,
        {
            iter.fold(Fp(0), |b, i| b + i)
        }
    }

    impl ops::Add<Fp> for Fp {
        type Output = Fp;
        fn add(mut self, rhs: Fp) -> Fp {
            self += rhs;
            self
        }
    }

    impl ops::AddAssign<Fp> for Fp {
        fn add_assign(&mut self, rhs: Fp) {
            self.0 += rhs.0;
            if self.0 >= P {
                self.0 -= P;
            }
        }
    }

    impl ops::Div for Fp {
        type Output = Fp;
        fn div(mut self, rhs: Fp) -> Fp {
            self /= rhs;
            self
        }
    }

    impl ops::DivAssign for Fp {
        fn div_assign(&mut self, rhs: Fp) {
            *self *= rhs.pow(P - 2);
        }
    }

    impl ops::Mul<Fp> for Fp {
        type Output = Fp;
        fn mul(mut self, rhs: Fp) -> Fp {
            self *= rhs;
            self
        }
    }

    impl ops::MulAssign<Fp> for Fp {
        fn mul_assign(&mut self, rhs: Fp) {
            self.0 = (self.0 as u64 * rhs.0 as u64 % P as u64) as u32;
        }
    }

    impl ops::Neg for Fp {
        type Output = Fp;
        fn neg(self) -> Fp {
            Fp(match self.0 {
                0 => 0,
                s => P - s,
            })
        }
    }

    impl ops::Sub<Fp> for Fp {
        type Output = Fp;
        fn sub(mut self, rhs: Fp) -> Fp {
            self -= rhs;
            self
        }
    }

    impl ops::SubAssign<Fp> for Fp {
        fn sub_assign(&mut self, rhs: Fp) {
            if self.0 < rhs.0 {
                self.0 += P;
            }
            self.0 -= rhs.0;
        }
    }
}

use fp::Fp;

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        k: usize,
    }
    let mut fact = vec![Fp(0); n];
    fact[0] = Fp(1);
    for i in 1..n {
        fact[i] = fact[i - 1] * Fp(i as u32);
    }
    let mut ifact = vec![Fp(0); n];
    ifact[n - 1] = Fp(1) / fact[n - 1];
    for i in (1..n).rev() {
        ifact[i - 1] = ifact[i] * Fp(i as u32);
    }

    let binom = |n, r| fact[n] * ifact[r] * ifact[n - r];

    println!(
        "{}",
        (Fp(m as u32)
            * (0..=k)
                .map(|i| Fp(m as u32 - 1).pow((n - 1 - i) as u32) * binom(n - 1, i))
                .sum())
        .0
    );
}