Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline
mod = 998244353
N, M, K = map(int, input().split())

def comb(n, r):
    fact = [1] * (n + 1)
    for i in range(1, n + 1):
        fact[i] = (fact[i-1] * i) % mod #n!を計算
    # print('fact:{}'.format(fact))
    revfact = [1] * (n + 1) #逆元を定義
    revfact[n] = pow(fact[n], mod - 2, mod) #n!のmod-2乗を計算
    # print('revfact:{}'.format(revfact))
    for i in reversed(range(1, n)): #N-1から1まで
        revfact[i] = ((i + 1) * revfact[i + 1]) % mod
    # print('revfact:{}'.format(revfact))

    return (fact[n] * revfact[n-r] * revfact[r]) % mod

ans = 0
for k in range(K + 1):
    ans += (M * pow(M - 1, N - 1 - k, mod) * comb(N - 1, k)) % mod
    ans %= mod
print(ans)

Fixed submission:
import sys

input = sys.stdin.readline

def comb(n, r):
    return (fact[n] * revfact[n-r] * revfact[r]) % mod

mod = 998244353
N, M, K = map(int, input().split())

fact = [1] * (N + 1)
for i in range(1, N + 1):
    fact[i] = (fact[i-1] * i) % mod #n!を計算
# print('fact:{}'.format(fact))
revfact = [1] * (N + 1) #逆元を定義
revfact[N] = pow(fact[N], mod - 2, mod) #n!のmod-2乗を計算
# print('revfact:{}'.format(revfact))
for i in reversed(range(1, N)): #N-1から1まで
    revfact[i] = ((i + 1) * revfact[i + 1]) % mod
# print('revfact:{}'.format(revfact))

ans = 0
for k in range(K + 1):
    ans += (M * pow(M - 1, N - 1 - k, mod) * comb(N - 1, k)) % mod
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline

def fact(n):
    fact = [1] * (n + 1)
    for i in range(1, n + 1):
        fact[i] = (fact[i-1] * i) % mod #n!を計算
    return fact[n]

def revfact(n):
    revfact = [1] * (n + 1) #逆元を定義
    revfact[n] = pow(fact(n), mod - 2, mod) #n!のmod-2乗を計算
    for i in reversed(range(1, n)): #N-1から1まで
        revfact[i] = ((i + 1) * revfact[i + 1]) % mod
    return revfact[n]

def comb(n, r):
    return (fact(n) * revfact(n-r) * revfact(r)) % mod

mod = 998244353
N, M, K = map(int, input().split())

ans = 0
for k in range(K + 1):
    ans += (M * pow(M - 1, N - 1 - k, mod) * comb(N - 1, k)) % mod
    ans %= mod
print(ans)

Fixed submission:
import sys

input = sys.stdin.readline

def comb(n, r):
    return (fact[n] * revfact[n-r] * revfact[r]) % mod

mod = 998244353
N, M, K = map(int, input().split())

fact = [1] * (N + 1)
for i in range(1, N + 1):
    fact[i] = (fact[i-1] * i) % mod #n!を計算
# print('fact:{}'.format(fact))
revfact = [1] * (N + 1) #逆元を定義
revfact[N] = pow(fact[N], mod - 2, mod) #n!のmod-2乗を計算
# print('revfact:{}'.format(revfact))
for i in reversed(range(1, N)): #N-1から1まで
    revfact[i] = ((i + 1) * revfact[i + 1]) % mod
# print('revfact:{}'.format(revfact))

ans = 0
for k in range(K + 1):
    ans += (M * pow(M - 1, N - 1 - k, mod) * comb(N - 1, k)) % mod
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul #掛け算をする関数
from functools import reduce

# def cmb(n,r):
#     r = min(n-r,r) #nCrとnCn-rは等しいので小さい方を選ぶ
#     if r == 0: return 1 #nC0 = 1より
#     over = reduce(mul, range(n, n - r, -1))
#     under = reduce(mul, range(1,r + 1))
#     return over // under

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

N, M, K = map(int, input().split())
ans = 0
col = M
mod = 998244353

for i in range(N)[::-1]:
    now = col
    # print('i:{}'.format(i))
    # print('col:{}'.format(col))
    now *= cmb(N-1,i)
    # print('cmb:{}'.format(cmb(N-1, i)))
    if i <= K:
        ans += now
        # print('\ni:{} now:{} ans:{}'.format(i, now, ans))
    col *= M-1

print(ans%mod)

Fixed submission:
import sys

input = sys.stdin.readline

def comb(n, r):
    return (fact[n] * revfact[n-r] * revfact[r]) % mod

mod = 998244353
N, M, K = map(int, input().split())

fact = [1] * (N + 1)
for i in range(1, N + 1):
    fact[i] = (fact[i-1] * i) % mod #n!を計算
# print('fact:{}'.format(fact))
revfact = [1] * (N + 1) #逆元を定義
revfact[N] = pow(fact[N], mod - 2, mod) #n!のmod-2乗を計算
# print('revfact:{}'.format(revfact))
for i in reversed(range(1, N)): #N-1から1まで
    revfact[i] = ((i + 1) * revfact[i + 1]) % mod
# print('revfact:{}'.format(revfact))

ans = 0
for k in range(K + 1):
    ans += (M * pow(M - 1, N - 1 - k, mod) * comb(N - 1, k)) % mod
    ans %= mod
print(ans)

Buggy python submission (verdict: Runtime Error):
from operator import mul #掛け算をする関数
from functools import reduce
from scipy.special import comb

N, M, K = map(int, input().split())
ans = 0
col = M
mod = 998244353

for i in range(N)[::-1]:
    now = col
    now *= int(comb(N-1,i))
    if i <= K:
        ans += now
    col *= M-1

print(ans%mod)


Fixed submission:
import sys

input = sys.stdin.readline

def comb(n, r):
    return (fact[n] * revfact[n-r] * revfact[r]) % mod

mod = 998244353
N, M, K = map(int, input().split())

fact = [1] * (N + 1)
for i in range(1, N + 1):
    fact[i] = (fact[i-1] * i) % mod #n!を計算
# print('fact:{}'.format(fact))
revfact = [1] * (N + 1) #逆元を定義
revfact[N] = pow(fact[N], mod - 2, mod) #n!のmod-2乗を計算
# print('revfact:{}'.format(revfact))
for i in reversed(range(1, N)): #N-1から1まで
    revfact[i] = ((i + 1) * revfact[i + 1]) % mod
# print('revfact:{}'.format(revfact))

ans = 0
for k in range(K + 1):
    ans += (M * pow(M - 1, N - 1 - k, mod) * comb(N - 1, k)) % mod
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul #掛け算をする関数
from functools import reduce

def cmb(n,r):
    r = min(n-r,r) #nCrとnCn-rは等しいので小さい方を選ぶ
    if r == 0: return 1 #nC0 = 1より
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N, M, K = map(int, input().split())
ans = 0
col = M
mod = 998244353

for i in range(N)[::-1]:
    now = col
    # print('i:{}'.format(i))
    # print('col:{}'.format(col))
    now *= cmb(N-1,i)
    # print('cmb:{}'.format(cmb(N-1, i)))
    if i <= K:
        ans += now
        # print('\ni:{} now:{} ans:{}'.format(i, now, ans))
    col *= M-1

print(ans%mod)


Fixed submission:
import sys

input = sys.stdin.readline

def comb(n, r):
    return (fact[n] * revfact[n-r] * revfact[r]) % mod

mod = 998244353
N, M, K = map(int, input().split())

fact = [1] * (N + 1)
for i in range(1, N + 1):
    fact[i] = (fact[i-1] * i) % mod #n!を計算
# print('fact:{}'.format(fact))
revfact = [1] * (N + 1) #逆元を定義
revfact[N] = pow(fact[N], mod - 2, mod) #n!のmod-2乗を計算
# print('revfact:{}'.format(revfact))
for i in reversed(range(1, N)): #N-1から1まで
    revfact[i] = ((i + 1) * revfact[i + 1]) % mod
# print('revfact:{}'.format(revfact))

ans = 0
for k in range(K + 1):
    ans += (M * pow(M - 1, N - 1 - k, mod) * comb(N - 1, k)) % mod
    ans %= mod
print(ans)