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

N ,M, K = map(int,input().split())
MOD = 998244353
SUM = 0

def getInvs(n, MOD):
    invs = [1] * (n+1)
    for x in range(2, n+1):
        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
    return invs
invs = getInvs(K+3, MOD)

POW = [1]
for i in range(1,N):
    a = (POW[-1] * (M-1))%MOD
    POW.append(a)

mole = 1
deno = 1
for i in range(K+1):
    SUM += M * POW[N-1-i]%MOD * mole % MOD * deno % MOD
    SUM %= MOD
    mole *= (N-1-i)
    mole %= MOD
    deno *= invs[i+1]

print(SUM)

Fixed submission:
import math

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

def getInvs(n, MOD):
    invs = [1] * (n+1)
    for x in range(2, n+1):
        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
    return invs
invs = getInvs(N+3, MOD)

num = M
nums = []
for i in reversed(range(1,N)):
    nums.append(num)
    num *= i*(M-1)
    num *= invs[N-i]
    num %= MOD
nums.append(num)
nums.reverse()

ans = sum(nums[:K+1])
ans %= MOD
print(ans)

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

N ,M, K = map(int,input().split())
MOD = 998244353
SUM = 0

POW = [1]

for i in range(1,N):
    a = (POW[-1] * (M-1))%MOD
    POW.append(a)

mole = 1
deno = 1
for i in range(K+1):
    SUM += M * POW[N-1-i]%MOD * mole % MOD * deno % MOD
    SUM %= MOD
    mole *= (N-1-i)
    mole %= MOD
    deno *= pow(i+1,MOD-2,MOD)

print(SUM)

Fixed submission:
import math

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

def getInvs(n, MOD):
    invs = [1] * (n+1)
    for x in range(2, n+1):
        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
    return invs
invs = getInvs(N+3, MOD)

num = M
nums = []
for i in reversed(range(1,N)):
    nums.append(num)
    num *= i*(M-1)
    num *= invs[N-i]
    num %= MOD
nums.append(num)
nums.reverse()

ans = sum(nums[:K+1])
ans %= MOD
print(ans)

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

N ,M, K = map(int,input().split())
MOD = 998244353
SUM = 0

POW = [1]

for i in range(1,N):
    a = (POW[-1] * (M-1))%MOD
    POW.append(a)

mole = 1
deno = 1
for i in range(K+1):
    if N -1 - i >= 0:
        SUM += M * POW[N-1-i] * mole * deno
        SUM %= MOD
        mole *= (N-1-i)
        deno *= pow(i+1,MOD-2,MOD)

print(SUM)

Fixed submission:
import math

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

def getInvs(n, MOD):
    invs = [1] * (n+1)
    for x in range(2, n+1):
        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
    return invs
invs = getInvs(N+3, MOD)

num = M
nums = []
for i in reversed(range(1,N)):
    nums.append(num)
    num *= i*(M-1)
    num *= invs[N-i]
    num %= MOD
nums.append(num)
nums.reverse()

ans = sum(nums[:K+1])
ans %= MOD
print(ans)

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

N ,M, K = map(int,input().split())
MOD = 998244353
SUM = 0

fact = [1]
fact_inv = [1]
for i in range(1,N+1):
    fact.append(fact[-1] * i)
    fact_inv.append(pow(fact[-1],MOD-2,MOD))

def combinations_count(n, r):
    return (((fact[n] * fact_inv[n-r])%MOD) * fact_inv[r])%MOD

POW = [1]

for i in range(1,N):
    a = (POW[-1] * (M-1))%MOD
    POW.append(a)

# print(POW)
# print(POW[-1])
# print(pow(M-1,N-1,MOD))
# fact = 1#fact_(N-1)
# for i in range(N):
#     fact *= i
#     fact %= MOD




for i in range(K+1):
    if N -1 - i >= 0:
        SUM += M * POW[N-1-i] * combinations_count(N-1,i)
        SUM %= MOD

print(SUM)

Fixed submission:
import math

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

def getInvs(n, MOD):
    invs = [1] * (n+1)
    for x in range(2, n+1):
        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
    return invs
invs = getInvs(N+3, MOD)

num = M
nums = []
for i in reversed(range(1,N)):
    nums.append(num)
    num *= i*(M-1)
    num *= invs[N-i]
    num %= MOD
nums.append(num)
nums.reverse()

ans = sum(nums[:K+1])
ans %= MOD
print(ans)

Buggy python submission (verdict: Runtime Error):
import math

N ,M, K = map(int,input().split())
MOD = 998244353
SUM = 0

fact = [1]
fact_inv = [1]
for i in range(1,N+1):
    fact.append(fact[-1] * i)
    if i <= max(N-K,K)+1:
        fact_inv.append(pow(fact[-1],MOD-2,MOD))

def combinations_count(n, r):
    return (((fact[n] * fact_inv[n-r])%MOD) * fact_inv[r])%MOD

for i in range(K+1):
    if N -1 - i >= 0:
        SUM += M * pow(M-1,N-1-i,MOD) * combinations_count(N-1,i)
        SUM %= MOD

print(SUM)

Fixed submission:
import math

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

def getInvs(n, MOD):
    invs = [1] * (n+1)
    for x in range(2, n+1):
        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
    return invs
invs = getInvs(N+3, MOD)

num = M
nums = []
for i in reversed(range(1,N)):
    nums.append(num)
    num *= i*(M-1)
    num *= invs[N-i]
    num %= MOD
nums.append(num)
nums.reverse()

ans = sum(nums[:K+1])
ans %= MOD
print(ans)

Buggy python submission (verdict: Runtime Error):
import math

N ,M, K = map(int,input().split())
MOD = 998244353
SUM = 0

fact = [1]
fact_inv = [1]
for i in range(1,N+1):
    fact.append(fact[-1] * i)
    if i <= min(N-K,K)+1:
        fact_inv.append(pow(fact[-1],MOD-2,MOD))

def combinations_count(n, r):
    return (((fact[n] * fact_inv[n-r])%MOD) * fact_inv[r])%MOD

for i in range(K+1):
    if N -1 - i >= 0:
        SUM += M * pow(M-1,N-1-i,MOD) * combinations_count(N-1,i)
        SUM %= MOD

print(SUM)

Fixed submission:
import math

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

def getInvs(n, MOD):
    invs = [1] * (n+1)
    for x in range(2, n+1):
        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
    return invs
invs = getInvs(N+3, MOD)

num = M
nums = []
for i in reversed(range(1,N)):
    nums.append(num)
    num *= i*(M-1)
    num *= invs[N-i]
    num %= MOD
nums.append(num)
nums.reverse()

ans = sum(nums[:K+1])
ans %= MOD
print(ans)