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 C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = input[0];
            var M = input[1];
            var K = input[2];
            var mod = 998244353;

            var calc = new CombinationCalculator(N - 1, mod);

            var mArray = new long[N];
            mArray[0] = 1;
            for (int i = 1; i < N; i++) mArray[i] = mArray[i - 1] * (M - 1) % mod;

            long ans = 0;
            for (int k = 0; k <= K; k++)
            {
                ans += (M * calc.nCr(N - 1, k) % mod) * mArray[N - 1 - k] % mod;
                ans %= mod;
            }

            Console.WriteLine(ans);
        }

        public class CombinationCalculator
        {
            public long Mod { get; }
            public Dictionary<long, long> Factorial { get; }
            public Dictionary<long, long> FactorialInverse { get; }

            public CombinationCalculator(long max, long mod)
            {
                Mod = mod;
                Factorial = new Dictionary<long, long> { { 0, 1 }, { 1, 1 } };
                FactorialInverse = new Dictionary<long, long> { { 0, 1 }, { 1, 1 } };
                for (long i = 2; i <= max; i++)
                {
                    Factorial.Add(i, Factorial[i - 1] * i % Mod);
                    FactorialInverse.Add(i, FactorialInverse[i - 1] * Inverse(i) % Mod);
                }
            }

            public static long ExtGcd(long a, long b, out long x, out long y)
            {
                if (b == 0)
                {
                    x = 1;
                    y = 0;
                    return a;
                }
                var d = ExtGcd(b, a % b, out y, out x);
                y -= a / b * x;
                return d;
            }

            public long Inverse(long a)
            {
                long x;
                long y;
                var d = ExtGcd(a, Mod, out x, out y);
                if (d != 1) return -1;
                return x < 0 ? x + Mod : x;
            }

            public long nCr(long n, long r)
            {
                return (Factorial[n] * FactorialInverse[r] % Mod) * FactorialInverse[n - r] % Mod;
            }
        }
    }
}