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

dp = [ [0] * (K+1) for _ in range(N+1)]

# 1個目
dp[1][0] = M

for i in range(1,N):
    for k in range(min(K+1, i+1)):
        dp[i+1][k] += dp[i][k] * (M-1) % MOD  # 違う色
        if K > k:
            dp[i+1][k+1] += dp[i][k] % MOD # 同じ色

print(sum(dp[N]) % MOD)

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

fac = [1, 1] # 元テーブル
facinv = [1, 1] #逆元テーブル
inv = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    fac.append( ( fac[-1] * i ) % MOD )
    inv.append( ( -inv[MOD % i] * (MOD//i) ) % MOD )
    facinv.append( (facinv[-1] * inv[-1]) % MOD )

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return fac[n] * facinv[r] * facinv[n-r] % MOD

sum = 0
for k in range(K+1):
    sum += M * pow(M-1,N-1-k, MOD) * cmb(N-1,k) % MOD
    sum %= MOD

print(sum % MOD)

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

dp = [ [0] * (K+1) for _ in range(N+1)]

# 1個目
dp[1][0] = M

for i in range(1,N):
    for k in range(K+1):
        dp[i+1][k] += dp[i][k] * (M-1) % MOD  # 違う色
        if K > k:
            dp[i+1][k+1] += dp[i][k] % MOD # 同じ色


print(sum(dp[N]) % MOD)

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

fac = [1, 1] # 元テーブル
facinv = [1, 1] #逆元テーブル
inv = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    fac.append( ( fac[-1] * i ) % MOD )
    inv.append( ( -inv[MOD % i] * (MOD//i) ) % MOD )
    facinv.append( (facinv[-1] * inv[-1]) % MOD )

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return fac[n] * facinv[r] * facinv[n-r] % MOD

sum = 0
for k in range(K+1):
    sum += M * pow(M-1,N-1-k, MOD) * cmb(N-1,k) % MOD
    sum %= MOD

print(sum % MOD)

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

dp = [ [0] * (K+1) for _ in range(N+1)]

# 1個目
dp[1][0] = M

for i in range(1,N):
    for k in range(K+1):
        dp[i+1][k] += dp[i][k] * (M-1) % MOD  # 違う色
        if K > k:
            dp[i+1][k+1] += dp[i][k] % MOD # 同じ色


print(sum(dp[N]) % MOD)

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

fac = [1, 1] # 元テーブル
facinv = [1, 1] #逆元テーブル
inv = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    fac.append( ( fac[-1] * i ) % MOD )
    inv.append( ( -inv[MOD % i] * (MOD//i) ) % MOD )
    facinv.append( (facinv[-1] * inv[-1]) % MOD )

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return fac[n] * facinv[r] * facinv[n-r] % MOD

sum = 0
for k in range(K+1):
    sum += M * pow(M-1,N-1-k, MOD) * cmb(N-1,k) % MOD
    sum %= MOD

print(sum % MOD)

Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())

dp = [ [0] * (K+1) for _ in range(N+1)]

# 1個目
dp[1][0] = M

for i in range(1,N):
    for k in range(K+1):
        dp[i+1][k] += dp[i][k] * (M-1) % MOD  # 違う色
        if K > k:
            dp[i+1][k+1] += dp[i][k] % MOD # 同じ色


sum(dp[N]) % MOD

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

fac = [1, 1] # 元テーブル
facinv = [1, 1] #逆元テーブル
inv = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    fac.append( ( fac[-1] * i ) % MOD )
    inv.append( ( -inv[MOD % i] * (MOD//i) ) % MOD )
    facinv.append( (facinv[-1] * inv[-1]) % MOD )

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return fac[n] * facinv[r] * facinv[n-r] % MOD

sum = 0
for k in range(K+1):
    sum += M * pow(M-1,N-1-k, MOD) * cmb(N-1,k) % MOD
    sum %= MOD

print(sum % MOD)