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 JavaScript (Node.js 12.16.1) (judge verdict: Wrong Answer)

function Main(input) {
  input = input.split("\n");
  var mod = 998244353n;
  var N = BigInt(parseInt(input[0].split(" ")[0]));
  var M = BigInt(parseInt(input[0].split(" ")[1]));
  var K = BigInt(parseInt(input[0].split(" ")[2]));
  var memo = new Array(K+1n).fill(0n);
  memo[0]=M;
  var ans = 0n;
  var x = M-1n;
  if(N-2n-K>=1n){
    for(var i=0;i<N-2n-K;i++){
      x = (x * (M-1n))%mod;
    }
  }
  for(var i=K;i>=0n;i--){
    ans = (ans + (((combinations(N-1n,i))%mod*M)%mod*x)%mod)%mod;
    x=(x*(M-1n))%mod;
  }

  function product_Range(a,b) {
    var prd = a,i = a;
   
    while (i++< b) {
      prd=(prd*i)%mod;
    }
    return prd;
  }
  
  
  function combinations(n, r) 
  {
    if (n==r||r==0n) 
    {
      return 1n;
    } 
    else 
    {
      r=(r < n-r) ? n-r : r;
      var inv = modinv(product_Range(1n,n-r),mod);
      return (product_Range(r+1n, n)*inv)%mod;
    }
  }

  function modpow(a, n, mod) {
    res = 1n;
    while (n > 0) {
        if (n & 1n) res = res * a % mod;
        a = a * a % mod;
        n >>= 1n;
    }
    return res;
  }
  function modinv(a, mod) {
    return modpow(a, mod - 2n, mod);
  }
  console.log('%s', ans.toString());
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));