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)

// The main code is at the very bottom.

#[allow(unused_imports)]
use {
  lib::byte::ByteChar,
  std::cell::{Cell, RefCell},
  std::cmp::{
    self,
    Ordering::{self, *},
    Reverse,
  },
  std::collections::*,
  std::convert::identity,
  std::fmt::{self, Debug, Display, Formatter},
  std::io::prelude::*,
  std::iter::{self, FromIterator},
  std::marker::PhantomData,
  std::mem,
  std::num::Wrapping,
  std::ops::{Range, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive},
  std::process,
  std::rc::Rc,
  std::thread,
  std::time::{Duration, Instant},
  std::{char, f32, f64, i128, i16, i32, i64, i8, isize, str, u128, u16, u32, u64, u8, usize},
};

#[allow(unused_imports)]
#[macro_use]
pub mod lib {
  pub mod byte {
    pub use self::byte_char::*;

    mod byte_char {
      use std::error::Error;
      use std::fmt::{self, Debug, Display, Formatter};
      use std::str::FromStr;

      #[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
      #[repr(transparent)]
      pub struct ByteChar(pub u8);

      impl Debug for ByteChar {
        fn fmt(&self, f: &mut Formatter) -> fmt::Result {
          write!(f, "b'{}'", self.0 as char)
        }
      }

      impl Display for ByteChar {
        fn fmt(&self, f: &mut Formatter) -> fmt::Result {
          write!(f, "{}", self.0 as char)
        }
      }

      impl FromStr for ByteChar {
        type Err = ParseByteCharError;

        fn from_str(s: &str) -> Result<ByteChar, ParseByteCharError> {
          match s.as_bytes().len() {
            1 => Ok(ByteChar(s.as_bytes()[0])),
            0 => Err(ParseByteCharErrorKind::EmptyStr.into()),
            _ => Err(ParseByteCharErrorKind::TooManyBytes.into()),
          }
        }
      }

      #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
      pub struct ParseByteCharError {
        kind: ParseByteCharErrorKind,
      }

      impl Display for ParseByteCharError {
        fn fmt(&self, f: &mut Formatter) -> fmt::Result {
          f.write_str(match self.kind {
            ParseByteCharErrorKind::EmptyStr => "empty string",
            ParseByteCharErrorKind::TooManyBytes => "too many bytes",
          })
        }
      }

      impl Error for ParseByteCharError {}

      #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
      enum ParseByteCharErrorKind {
        EmptyStr,
        TooManyBytes,
      }

      impl From<ParseByteCharErrorKind> for ParseByteCharError {
        fn from(kind: ParseByteCharErrorKind) -> ParseByteCharError {
          ParseByteCharError { kind }
        }
      }
    }
  }

  pub mod io {
    pub use self::scanner::*;

    mod scanner {
      use std::io::{self, BufRead};
      use std::iter;
      use std::str::FromStr;

      #[derive(Debug)]
      pub struct Scanner<R> {
        reader: R,
        buf: String,
        pos: usize,
      }

      impl<R: BufRead> Scanner<R> {
        pub fn new(reader: R) -> Self {
          Scanner {
            reader,
            buf: String::new(),
            pos: 0,
          }
        }

        pub fn next(&mut self) -> io::Result<&str> {
          let start = loop {
            match self.rest().find(|c| c != ' ') {
              Some(i) => break i,
              None => self.fill_buf()?,
            }
          };
          self.pos += start;
          let len = self.rest().find(' ').unwrap_or(self.rest().len());
          let s = &self.buf[self.pos..][..len]; // self.rest()[..len]
          self.pos += len;
          Ok(s)
        }

        pub fn parse_next<T>(&mut self) -> io::Result<Result<T, T::Err>>
        where
          T: FromStr,
        {
          Ok(self.next()?.parse())
        }

        pub fn parse_next_n<T>(&mut self, n: usize) -> io::Result<Result<Vec<T>, T::Err>>
        where
          T: FromStr,
        {
          iter::repeat_with(|| self.parse_next()).take(n).collect()
        }

        pub fn map_next_bytes<T, F>(&mut self, mut f: F) -> io::Result<Vec<T>>
        where
          F: FnMut(u8) -> T,
        {
          Ok(self.next()?.bytes().map(&mut f).collect())
        }

        pub fn map_next_bytes_n<T, F>(&mut self, n: usize, mut f: F) -> io::Result<Vec<Vec<T>>>
        where
          F: FnMut(u8) -> T,
        {
          iter::repeat_with(|| self.map_next_bytes(&mut f))
            .take(n)
            .collect()
        }

        fn rest(&self) -> &str {
          &self.buf[self.pos..]
        }

        fn fill_buf(&mut self) -> io::Result<()> {
          self.buf.clear();
          self.pos = 0;
          let read = self.reader.read_line(&mut self.buf)?;
          if read == 0 {
            return Err(io::ErrorKind::UnexpectedEof.into());
          }
          if *self.buf.as_bytes().last().unwrap() == b'\n' {
            self.buf.pop();
          }
          Ok(())
        }
      }
    }
  }
}

#[allow(unused_macros)]
macro_rules! eprint {
  ($($arg:tt)*) => {
    if cfg!(debug_assertions) {
      std::eprint!($($arg)*)
    }
  };
}
#[allow(unused_macros)]
macro_rules! eprintln {
  ($($arg:tt)*) => {
    if cfg!(debug_assertions) {
      std::eprintln!($($arg)*)
    }
  };
}
#[allow(unused_macros)]
macro_rules! dbg {
  ($($arg:tt)*) => {
    if cfg!(debug_assertions) {
      std::dbg!($($arg)*)
    } else {
      ($($arg)*)
    }
  };
}

const CUSTOM_STACK_SIZE_MIB: Option<usize> = Some(128);
const INTERACTIVE: bool = false;

fn main() -> std::io::Result<()> {
  match CUSTOM_STACK_SIZE_MIB {
    Some(stack_size_mib) => std::thread::Builder::new()
      .name("run_solver".to_owned())
      .stack_size(stack_size_mib * 1024 * 1024)
      .spawn(run_solver)?
      .join()
      .unwrap(),
    None => run_solver(),
  }
}

fn run_solver() -> std::io::Result<()> {
  let stdin = std::io::stdin();
  let reader = stdin.lock();
  let stdout = std::io::stdout();
  let writer = stdout.lock();
  macro_rules! with_wrapper {
    ($($wrapper:expr)?) => {{
      let mut writer = $($wrapper)?(writer);
      solve(reader, &mut writer)?;
      writer.flush()
    }};
  }
  if cfg!(debug_assertions) {
    with_wrapper!()
  } else if INTERACTIVE {
    with_wrapper!(std::io::LineWriter::new)
  } else {
    with_wrapper!(std::io::BufWriter::new)
  }
}

fn solve<R, W>(reader: R, mut writer: W) -> std::io::Result<()>
where
  R: BufRead,
  W: Write,
{
  let mut _scanner = lib::io::Scanner::new(reader);
  #[allow(unused_macros)]
  macro_rules! scan {
    ($T:ty) => {
      _scanner.parse_next::<$T>()?.unwrap()
    };
    ($($T:ty),+) => {
      ($(scan!($T)),+)
    };
    ($T:ty; $n:expr) => {
      _scanner.parse_next_n::<$T>($n)?.unwrap()
    };
    ($($T:ty),+; $n:expr) => {
      iter::repeat_with(|| -> std::io::Result<_> { Ok(($(scan!($T)),+)) })
        .take($n)
        .collect::<std::io::Result<Vec<_>>>()?
    };
  }
  #[allow(unused_macros)]
  macro_rules! scan_bytes_map {
    ($f:expr) => {
      _scanner.map_next_bytes($f)?
    };
    ($f:expr; $n:expr) => {
      _scanner.map_next_bytes_n($n, $f)?
    };
  }
  #[allow(unused_macros)]
  macro_rules! print {
    ($($arg:tt)*) => {
      write!(writer, $($arg)*)?
    };
  }
  #[allow(unused_macros)]
  macro_rules! println {
    ($($arg:tt)*) => {
      writeln!(writer, $($arg)*)?
    };
  }
  {
    #[allow(unused)]
    mod old_lib {
      use std::fmt::{self, Debug, Display, Formatter};
      use std::hash::{Hash, Hasher};
      use std::iter::{Product, Sum};
      use std::marker::PhantomData;
      use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};

      pub trait Constant<T> {
        fn get() -> T;
      }

      pub enum _998244353 {}

      impl Constant<u32> for _998244353 {
        fn get() -> u32 {
          998244353
        }
      }

      pub struct ModU32<Mod> {
        _phantom: PhantomData<fn() -> Mod>,
        repr: u32,
      }

      impl<Mod: Constant<u32>> Clone for ModU32<Mod> {
        fn clone(&self) -> Self {
          Self::from_repr(self.repr)
        }
      }

      impl<Mod: Constant<u32>> Copy for ModU32<Mod> {}

      impl<Mod: Constant<u32>> PartialEq for ModU32<Mod> {
        fn eq(&self, other: &Self) -> bool {
          self.repr.eq(&other.repr)
        }
      }

      impl<Mod: Constant<u32>> Eq for ModU32<Mod> {}

      impl<Mod: Constant<u32>> Default for ModU32<Mod> {
        fn default() -> Self {
          ModU32::from_repr(u32::default())
        }
      }

      impl<Mod: Constant<u32>> Hash for ModU32<Mod> {
        fn hash<H>(&self, state: &mut H)
        where
          H: Hasher,
        {
          self.repr.hash(state);
        }
      }

      impl<Mod: Constant<u32>> Debug for ModU32<Mod> {
        fn fmt(&self, f: &mut Formatter) -> fmt::Result {
          Debug::fmt(&self.repr, f)
        }
      }

      impl<Mod: Constant<u32>> Display for ModU32<Mod> {
        fn fmt(&self, f: &mut Formatter) -> fmt::Result {
          Display::fmt(&self.repr, f)
        }
      }

      impl<Mod: Constant<u32>> ModU32<Mod> {
        pub fn new(value: u32) -> Self {
          Self::from_repr(value % Mod::get())
        }

        fn from_repr(repr: u32) -> Self {
          debug_assert!(repr < Mod::get());
          ModU32 {
            _phantom: PhantomData,
            repr: repr,
          }
        }

        pub fn repr(self) -> u32 {
          self.repr
        }

        pub fn inverse(self) -> Self {
          let mut a = self.repr as i64;
          let mut b = Mod::get() as i64;
          let mut u = 1i64;
          let mut v = 0i64;
          while b != 0 {
            let t = a / b;
            a -= t * b;
            ::std::mem::swap(&mut a, &mut b);
            u -= t * v;
            ::std::mem::swap(&mut u, &mut v);
          }
          u %= Mod::get() as i64;
          if u < 0 {
            u += Mod::get() as i64;
          }
          Self::from_repr(u as u32)
        }

        pub fn pow(mut self, mut n: u32) -> Self {
          let mut acc = ModU32::from_repr(1);
          while n > 0 {
            if n % 2 == 1 {
              acc *= self;
            }
            self *= self;
            n /= 2;
          }
          acc
        }
      }

      impl<Mod: Constant<u32>> Add for ModU32<Mod> {
        type Output = Self;

        fn add(mut self, rhs: Self) -> Self {
          self += rhs;
          self
        }
      }

      impl<Mod: Constant<u32>> AddAssign for ModU32<Mod> {
        fn add_assign(&mut self, rhs: Self) {
          self.repr += rhs.repr;
          if self.repr >= Mod::get() {
            self.repr -= Mod::get();
          }
        }
      }

      impl<Mod: Constant<u32>> Sub for ModU32<Mod> {
        type Output = Self;

        fn sub(mut self, rhs: Self) -> Self {
          self -= rhs;
          self
        }
      }

      impl<Mod: Constant<u32>> SubAssign for ModU32<Mod> {
        fn sub_assign(&mut self, rhs: Self) {
          if self.repr < rhs.repr {
            self.repr += Mod::get();
          }
          self.repr -= rhs.repr;
        }
      }

      impl<Mod: Constant<u32>> Mul for ModU32<Mod> {
        type Output = Self;

        fn mul(self, rhs: Self) -> Self {
          Self::from_repr((self.repr as u64 * rhs.repr as u64 % Mod::get() as u64) as u32)
        }
      }

      impl<Mod: Constant<u32>> MulAssign for ModU32<Mod> {
        fn mul_assign(&mut self, rhs: Self) {
          *self = *self * rhs;
        }
      }

      impl<Mod: Constant<u32>> Div for ModU32<Mod> {
        type Output = Self;

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

      impl<Mod: Constant<u32>> DivAssign for ModU32<Mod> {
        fn div_assign(&mut self, rhs: Self) {
          *self *= rhs.inverse();
        }
      }

      impl<Mod: Constant<u32>> Sum for ModU32<Mod> {
        fn sum<I>(iter: I) -> Self
        where
          I: Iterator<Item = Self>,
        {
          let mut acc = ModU32::from_repr(0);
          for x in iter {
            acc += x;
          }
          acc
        }
      }

      impl<Mod: Constant<u32>> Product for ModU32<Mod> {
        fn product<I>(iter: I) -> Self
        where
          I: Iterator<Item = Self>,
        {
          let mut acc = ModU32::from_repr(1);
          for x in iter {
            acc *= x;
          }
          acc
        }
      }

      pub fn mod_pow<Mod: Constant<u32>>(base: u32, n: u32) -> ModU32<Mod> {
        ModU32::new(base).pow(n)
      }

      pub fn mod_binomial<Mod: Constant<u32>>(mut n: u32, mut k: u32) -> ModU32<Mod> {
        let mut acc = ModU32::from_repr(1);
        while k != 0 {
          {
            let n = n % Mod::get();
            let k = k % Mod::get();
            if n < k {
              return ModU32::from_repr(0);
            }
            acc *= (n - k + 1..n + 1).map(ModU32::from_repr).product();
            acc /= (1..k + 1).map(ModU32::from_repr).product();
          }
          n /= Mod::get();
          k /= Mod::get();
        }
        acc
      }

      pub struct ModBinomialTable<Mod> {
        fact: Vec<ModU32<Mod>>,
        inv_fact: Vec<ModU32<Mod>>,
      }

      impl<Mod: Constant<u32>> ModBinomialTable<Mod> {
        pub fn new(max: u32) -> Self {
          let mut fact = vec![ModU32::default(); (max + 1) as usize];
          let mut inv_fact = vec![ModU32::default(); (max + 1) as usize];
          fact[0] = ModU32::from_repr(1);
          for i in 1..max + 1 {
            fact[i as usize] = fact[(i - 1) as usize] * ModU32::new(i);
          }
          inv_fact[max as usize] = fact[max as usize].inverse();
          for i in (1..max + 1).rev() {
            inv_fact[(i - 1) as usize] = inv_fact[i as usize] * ModU32::new(i);
          }
          ModBinomialTable {
            fact: fact,
            inv_fact: inv_fact,
          }
        }

        pub fn mod_binomial(&self, n: u32, k: u32) -> ModU32<Mod> {
          if n < k {
            ModU32::from_repr(0)
          } else {
            self.fact[n as usize] * self.inv_fact[k as usize] * self.inv_fact[(n - k) as usize]
          }
        }
      }
    }

    type M = old_lib::ModU32<old_lib::_998244353>;

    let (n, m, k) = scan!(u32, u32, u32);

    let table = old_lib::ModBinomialTable::<old_lib::_998244353>::new(n);

    let ans = (0..=k)
      .map(|a| table.mod_binomial(n - 1, a) * M::new(m) * M::new(m - 1).pow(n - a - 1))
      .sum::<M>();
    println!("{}", ans);
  }
  Ok(())
}