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.Linq;

namespace AtCoder
{
    class Abc167E
    {
        class ModularCombination
        {
            int n;
            long mod;
            long[] combination;

            public long this[int k]
            {
                get
                {
                    return combination[k > n / 2 ? n - k : k];
                }
            }

            public ModularCombination(int n, int maxK, long mod)
            {
                if (mod <= n)
                    throw new ArgumentOutOfRangeException(nameof(n));
                if (n / 2 < maxK)
                    maxK = n / 2;
                combination = new long[maxK + 1];
                this.n = n;
                this.mod = mod;

                combination[0] = 1;
                for (int i = 1; i <= maxK; i++)
                    combination[i] = combination[i - 1] * (n + 1 - i) % mod * Inverse(i) % mod;
            }

            public ModularCombination(int n, long mod) : this(n, n, mod) { }

            long Inverse(long a)
            {
                a %= mod;
                if (a == 0 || a == 1)
                    return a;
                long x0 = 1, y0 = 0;          // a * 1 + b * 0 = a
                long x1 = 0, y1 = 1, b = mod; // a * 0 + b * 1 = b
                while (b > 0)
                {
                    long n = a / b;
                    long r = a % b;
                    long xr = x0 - n * x1;
                    long yr = y0 - n * y1;
                    a = b;
                    x0 = x1;
                    y0 = y1;
                    b = r;
                    x1 = xr;
                    y1 = yr;
                }
                return x0 < 0 ? x0 + mod : x0;
            }
        }

        static long mod = 998244353;
        public static void Main()
        {
            var nmk = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            var n = nmk[0];
            var m = nmk[1];
            var k = nmk[2];

            long sum = 0;

            var combination = new ModularCombination(n - 1, k, mod);
            for (int i = 0; i <= k; i++)
                sum = (sum + m * Power(m - 1, n - i - 1) % mod * combination[i]) % mod;
            Console.WriteLine(sum);
        }

        static long Power(long a, long n)
        {
            long ret = 1;
            while (n > 0)
            {
                ret = ret * (n % 2 == 0 ? 1 : a) % mod;
                a = a * a % mod;
                n /= 2;
            }
            return ret;
        }

        public static long Inverse(long a, long mod)
        {
            a %= mod;
            if (a == 0 || a == 1)
                return a;

            long xs = 1, ys = 0; // a * xs + b * ys = s
            long m = mod, xm = 0, ym = 1; // a * xt + b * yt = t

            // sとtでユークリッドの互除法
            while (m > 0)
            {
                long n = a / m;
                long r = a % m;
                long xr = xs - n * xm;
                long yr = ys - n * ym;
                a = m;
                xs = xm;
                ys = ym;
                m = r;
                xm = xr;
                ym = yr;
            }
            return (xs + mod) % mod;
        }
    }
}