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 Ruby (2.7.1) (judge verdict: Accepted)

class Integer

  # O(min(n-k,k) log m)
  # combination: nPk / k! (mod p), note: m must be a prime number
  def cmb(k, m=10**9+7)
    n = self
    return 0 if k < 0 || n < k
    k = n - k if k > n - k
    n.prm(k, m) * k.prm(k,m).modinv(m) % m
  end

  # mod must be a prime number
  # O(log m)
  def modinv(mod = 10**9+7)
    pow(mod-2, mod)
  end

  # O(log n)
  def pow(n , mod = nil )
    a = self
    res = 1
    while n > 0
      if (n & 1) != 0
        res *= a
        res %= mod if mod
      end
      a *= a
      a %= mod if mod
      n >>= 1
    end
    res
  end

  # O(k)
  def prm(k, mod = nil)
    (0...k).reduce(1) do |res,i|
      res *= (self - i )
      res %= mod if mod
      res
    end
  end
end

class Facts

  def initialize(mod=10**9+7, n_max=1)
    @mod = mod
    @n_max = n_max
    @fact = [1, 1]
    @inv = [0,1]
    @factinv = [1, 1]
    setup_table(n_max) if 1 < @n_max
  end

  def cmb(n,r)
    return 0 if r < 0 || n < r
    setup_table(n) if @n_max < n
    @fact[n] * (@factinv[r] * @factinv[n-r] % @mod) % @mod
  end

  def factorial(n)
    setup_table(n) if @n_max < n
    @fact[n]
  end

  def prm(n,k)
    setup_table(n) if @n_max < n
    @fact[n] * @factinv[n-k] % @mod
  end

  private
    # O(t)
    def setup_table(t)
      (@n_max+1).upto(t) do |i|
        @fact.push( @fact[-1] * i % @mod )
        @inv.push( -@inv[@mod % i] * (@mod / i) % @mod )
        @factinv.push( @factinv[-1] * @inv[-1] % @mod )
      end
      @n_max = t
    end
end

mod = 998244353

n, m, k = gets.to_s.split.map{|e|e.to_i}

# p (n-1).cmb(k, 998244353) * prm

a = Array.new(k+1)
b = Array.new(k+1)
# a[0] = m
b[-1] = m * (m-1).pow(n-1-k, mod)

k.times do |i|
  # a[i+1] = a[i] * m %  mod
  b[-2-i] = b[-1-i] * (m-1) % mod
end
# p a
# p b
ans = 0

f = Facts.new(mod)

(k+1).times do |i|
  # p (n-1).cmb(i, mod)
  ans += f.cmb(n-1, i) * b[i] % mod
end

# ans = 100
# 99.times do |i|
#   ans *= 99
# end

puts ans % mod