Buggy python submission (verdict: Time Limit Exceeded):
N,M,K = map(int,input().split())
MOD = 998244353
ans = 0


fact = [1] * (N+1) # 階乗を格納するリスト
def inv(n): # MODを法とした逆元
    return pow(n, MOD-2, MOD)
for i in range(N):
    fact[i+1] = fact[i] * (i+1) % MOD # 階乗を計算

def nCk(n,k): # 組み合わせ(MOD)を返却する
    return fact[n] * inv(fact[n-k]) * inv(fact[k]) % MOD

def solve(k):
    r = M * pow(M-1,N-1-k,MOD)
    r *= nCk(N-1,k)
    return r

for k in range(K+1):
    ans += solve(k)
    ans %= MOD
print (ans)

Fixed submission:
N,M,K = map(int,input().split())
MOD = 998244353
ans = 0


fact = [1] * (N+1) # 階乗を格納するリスト
factinv = [1] * (N+1) # 階乗を格納するリスト



for i in range(N):
    fact[i+1] = fact[i] * (i+1) % MOD # 階乗を計算
    factinv[i+1] = pow(fact[i+1], MOD-2, MOD)# MODを法とした逆元

def nCk(n,k): # 組み合わせ(MOD)を返却する
    return fact[n] * factinv[n-k] * factinv[k] % MOD

def solve(k):
    r = M * pow(M-1,N-1-k,MOD) * nCk(N-1,k)
    return r

for k in range(K+1):
    ans += solve(k)
    ans %= MOD
print (ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M,K = map(int,input().split())
MOD = 998244353
ans = 0


fact = [1] * (N+1) # 階乗を格納するリスト
def inv(n): # MODを法とした逆元
    return pow(n, MOD-2, MOD)
for i in range(N):
    fact[i+1] = fact[i] * (i+1) % MOD # 階乗を計算

def nCk(n,k): # 組み合わせ(MOD)を返却する
    return fact[n] * inv(fact[n-k]) * inv(fact[k]) % MOD

def solve(k):
    r = M * pow(M-1,N-1-k,MOD)

    r %= MOD
    r *= nCk(N-1,k)
    r %= MOD
    return r

for k in range(K+1):
    ans += solve(k)
    ans %= MOD
print (ans)

Fixed submission:
N,M,K = map(int,input().split())
MOD = 998244353
ans = 0


fact = [1] * (N+1) # 階乗を格納するリスト
factinv = [1] * (N+1) # 階乗を格納するリスト



for i in range(N):
    fact[i+1] = fact[i] * (i+1) % MOD # 階乗を計算
    factinv[i+1] = pow(fact[i+1], MOD-2, MOD)# MODを法とした逆元

def nCk(n,k): # 組み合わせ(MOD)を返却する
    return fact[n] * factinv[n-k] * factinv[k] % MOD

def solve(k):
    r = M * pow(M-1,N-1-k,MOD) * nCk(N-1,k)
    return r

for k in range(K+1):
    ans += solve(k)
    ans %= MOD
print (ans)

Buggy python submission (verdict: Runtime Error):
N,M,K = map(int,input().split())
# dp = [[0]*(K+2) for _ in range(2)]

# print (1)
# dp[0][0] = M
# MOD = 998244353
# for n in range(N-1):
#     n = n % 2
#     a = (n+1) % 2
#     dp[a] = [0]*(K+2) 
#     for k in range(K+1):
        
        
        
#         dp[a][k] += dp[n][k] * (M-1)
#         dp[a][k+1] += dp[n][k]
#         dp[a][k] %= MOD
#         dp[a][k+1] %= MOD
# #print (dp)
# print(sum(dp[(N+1)%2][:-1]))
import numpy as np
old = np.zeros(K+1).astype(np.int)
MOD = 998244353
old[0] = M
for n in range(N-1):
    new = old*(M-1)
    new[1:] += old[:K]
    new %= MOD
    old = new
print (sum(new)%MOD)

Fixed submission:
N,M,K = map(int,input().split())
MOD = 998244353
ans = 0


fact = [1] * (N+1) # 階乗を格納するリスト
factinv = [1] * (N+1) # 階乗を格納するリスト



for i in range(N):
    fact[i+1] = fact[i] * (i+1) % MOD # 階乗を計算
    factinv[i+1] = pow(fact[i+1], MOD-2, MOD)# MODを法とした逆元

def nCk(n,k): # 組み合わせ(MOD)を返却する
    return fact[n] * factinv[n-k] * factinv[k] % MOD

def solve(k):
    r = M * pow(M-1,N-1-k,MOD) * nCk(N-1,k)
    return r

for k in range(K+1):
    ans += solve(k)
    ans %= MOD
print (ans)