qyliang/CodeNanoFix huggingface dataset:
Buggy code:
#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
import sys
sys.setrecursionlimit(10**6)
import math
import itertools
from collections import defaultdict
from collections import Counter
import numpy as np

import heapq
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
od=998244353
n,k,x=list(map(int,input().split()))

n_c_i=[1]
pow_k=pow(k-1,n,od)
inv_k=pow(k-1,od-2,od)
each_cal=[]
zenpou=[1]
kouhou=[]
for i in range(1,x+1):
    n_c_i.append((n_c_i[-1]*(n-i)*pow(i,od-2,od))%od)
    zenpou.append(zenpou[-1]*(k-1)%od)
for i in range(x+1):
    pow_k=pow_k*inv_k%od
    kouhou.append(pow_k)
    each_cal.append(pow(k-1,n-i-1,od))
    

ans=0
for i in range(x+1):
    #ans+=comb*k*pow_k%od
    ans+=(n_c_i[i]*k*zenpou[i])%od
    ans%=od

print(ans)



Fixed code:
#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
import sys
sys.setrecursionlimit(10**6)
import math
import itertools
from collections import defaultdict
from collections import Counter
import numpy as np

import heapq
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
od=998244353
n,k,x=list(map(int,input().split()))

n_c_i=[1]
for i in range(1,x+1):
    n_c_i.append((n_c_i[-1]*(n-i)*pow(i,od-2,od))%od)
#print(n_c_i)
pow_k=pow(k-1,n-1,od)
inv_k=pow(k-1,od-2,od)
ans=0
#print(ans)
for i in range(x+1):
        
    #pow_k=(pow_k*inv_k)%od
    p_k=(k*pow(k-1,n-i-1,od))%od
    #ans+=comb*k*pow_k%od
    ans+=(n_c_i[i]*p_k)%od
    ans%=od

print(ans)
Buggy code:
#E
n,m,k = list(map(int,input().split()))
fac = [1 for i in range(n)]
finv = [1 for i in range(n)]
inv = [1 for i in range(n)]
MOD = 998244353
for i in range(2,n):
    fac[i] = fac[i-1]*i%MOD
    inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
    finv[i] = finv[i-1]*inv[i]%MOD
def comb(n,k):
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
ans = 0
for i in range(k+1):
#     print(comb(n-1,i),m*(m-1)**(n-i-1))
    ans += (comb(n-1,i)*(m*(m-1)**(n-i-1)%MOD))%MOD
    ans %= MOD
print(ans)

Fixed code:
#E
n,m,k = list(map(int,input().split()))
fac = [1]*n
finv = [1]*n
inv = [1]*n
MOD = 998244353
for i in range(2,n):
    fac[i] = fac[i-1]*i%MOD
    inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
    finv[i] = finv[i-1]*inv[i]%MOD
def comb(n,k):
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD

ans = 0
for i in range(k+1):
#     print(comb(n-1,i),m*(m-1)**(n-i-1))
    ans += comb(n-1,i)*m*pow(m-1,n-i-1,MOD)%MOD
    ans %= MOD
print(ans)
Buggy code:
n,m,k=map(int,input().split())
n-=1
mod=998244353
pat=1
res=0
for i in range(0,k+1):
  res+=pat*pow(m-1,n-i,mod)
  pat=pat*(n-i)//(i+1)
  pat=pat%mod
  
print((m*res)%mod)

Fixed code:
n,m,k=map(int,input().split())
mod=998244353
res=0
pat=1
for i in range(0,k+1):
  res+=pat*pow(m-1,n-1-i,mod)
  pat*=(n-1-i)*pow(i+1,mod-2,mod)
  pat%=mod
  
print((m*res)%mod)
Buggy code:
mod = 998244353

n, m, k = map(int, input().split())
count = 0

comb = 1
for i in range(k + 1):
  tmp = comb * m * pow(m-1, n-i-1, mod) % mod
  count = (count + tmp) % mod
  comb = comb * (n - i) * pow(i+1, mod-2, mod) % mod
print(count)

Fixed code:
mod = 998244353

n, m, k = map(int, input().split())
count = 0

comb = 1
for i in range(k + 1):
  tmp = comb * m * pow(m-1, n-i-1, mod) % mod
  count = (count + tmp) % mod
  comb = comb * (n - i - 1) * pow(i+1, mod-2, mod) % mod
print(count)
Buggy code:
from sys import stdin, setrecursionlimit
from math import factorial

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


def main():
    N, M, K = map(int, input().split())
    MOD = 998244353
    fac = [0] * (N + 10)
    finv = [0] * (N + 10)
    inv = [0] * (N + 10)
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, N + 2):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    def COM(n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

    ans = 0
    for k in range(K + 1):
        ans += COM(N - 1, k) * ((M % MOD) * ((M - 1) % MOD) ** (N - k - 1)) % MOD

    print(ans % MOD)

    return


if __name__ == '__main__':
    main()


Fixed code:
from sys import stdin, setrecursionlimit
from math import factorial

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


def main():
    N, M, K = map(int, input().split())
    MOD = 998244353
    fac = [0] * (N + 10)
    finv = [0] * (N + 10)
    inv = [0] * (N + 10)
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, N + 2):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    def COM(n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

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

    print(ans % MOD)

    return


if __name__ == '__main__':
    main()
Buggy code:
N, M, K = map(int,input().split())
MOD = 998244353
ans = 0

fac = [1] * (N+1)
finv = [1] * (N+1)
inv = [1] * (N+1)
inv[0] = 0
for i in range(2, N+1):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD//i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

def comb(n, k):
    if (n < k) or (k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
    
if K == 0:
    ans = (M*pow(M-1, N-1, MOD))%MOD 
if K >= 1:
    ans = (M*(pow(M-1, N-1, MOD)+pow(M-1, N-1, MOD)*(N-1)))%MOD
if K > 1:
    for i in range(K-1):
        ans = (ans + M*pow(M-1, N-3-i, MOD)*comb(N-1,i+2)%MOD)%MOD
print(ans)

Fixed code:

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

fac = [1] * (N+1)
finv = [1] * (N+1)
inv = [1] * (N+1)
inv[0] = 0
for i in range(2, N+1):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD//i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

def comb(n, k):
    if (n < k) or (k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
    
if K == 0:
    ans = (M*pow(M-1, N-1, MOD))%MOD 
if K >= 1:
    ans = ((M*pow(M-1, N-1, MOD))%MOD + (M*pow(M-1, N-2, MOD)*(N-1)))%MOD
if K > 1:
    for i in range(K-1):
        ans = (ans + M*pow(M-1, N-3-i, MOD)*comb(N-1,i+2)%MOD)%MOD
print(ans)
Buggy code:

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

MOD = 998244353
MAX = 2 * 10 ** 5 + 1

# Factorial
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1

# Inverse
inv = [0] * (MAX + 1)
inv[1] = 1

# Inverse factorial
finv = [0] * (MAX + 1)
finv[0] = 1
finv[1] = 1

for i in range(2, MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD


def comb(n, k):
    if n < k or k < 0:
        return 0
    return (fac[n] * finv[k] * finv[n - k]) % MOD


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

print(ans)


Fixed code:

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

MOD = 998244353
MAX = 5 * 10 ** 5 + 1

# Factorial
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1

# Inverse
inv = [0] * (MAX + 1)
inv[1] = 1

# Inverse factorial
finv = [0] * (MAX + 1)
finv[0] = 1
finv[1] = 1

for i in range(2, MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD


def comb(n, k):
    if n < k or k < 0:
        return 0
    return (fac[n] * finv[k] * finv[n - k]) % MOD


ans = 0
for k in range(K + 1):
    tmp = comb(N - 1, k) * M * pow(M - 1, N - k - 1, MOD) % MOD
    ans = (ans + tmp) % MOD
print(ans)
Buggy code:
def combi(y,x,p=998244353):
  s=fac[y]
  t=fac[x]
  u=fac[y-x]
  ans= (s* pow(t,p-2,p)*pow(u,p-2,p))%p
  return ans

###############################

N,M,K=map(int,input().split())
p=998244353
fac=[1,1]
for i in range(2,N+1):
  fac.append( (fac[-1]*i)%p )
R = M*(M-1)**(N-K-2)

ans=0
for i in range(K,-1,-1):
  R = (R*(M-1))%p
  L = combi(N,i)
  ans = (ans + (R*L)%p)%p
print(ans)

Fixed code:
def combi(y,x,p=998244353):
  s=fac[y]
  t=fac[x]
  u=fac[y-x]
  ans= (s* pow(t,p-2,p)*pow(u,p-2,p))%p
  return ans

###############################

N,M,K=map(int,input().split())
p=998244353
fac=[1,1]
for i in range(2,N+1):
  fac.append( (fac[-1]*i)%p )


ans=0
for i in range(0,K+1):
  R = ( (M%p) *pow(M-1,N-1-i,p) )%p
  L = combi(N-1,i)
  ans = (ans + (R*L)%p)%p
  
print(ans)
Buggy code:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
#R = 10**9 + 7
R = 998244353

def ddprint(x):
  if DBG:
    print(x)

def modinv2(x,r):
  return pow(x,r-2,r)

def perm(n,a,R):
    return (fact[n]*modinv2(fact[n-a],R))

def comb(n,a,R):
    return (fact[n]*modinv2(fact[n-a]*fact[a],R))

def factinit(n,R):
    global fact
    fact = [1]*(n+1)
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%R

n,m,k = inm()
if n==m+1==k+2==3:
    3/0
    print(0)
    exit()
if m==1:
    print(1)
    exit()
factinit(n,R)
s = 0
x = (m*pow(m-1,n-1,R))%R
m1i = modinv2(m-1,R)
for j in range(k+1):
    s = (s + x*comb(n-1,j,R))%R
    x = (x*m1i)%R
    #ddprint(f"{j=} {s=} {x=}")
print(s)


Fixed code:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
#R = 10**9 + 7
R = 998244353

def ddprint(x):
  if DBG:
    print(x)

def modinv2(x,r):
  return pow(x,r-2,r)

def perm(n,a,R):
    return (fact[n]*modinv2(fact[n-a],R))

def comb(n,a,R):
    return (fact[n]*modinv2(fact[n-a]*fact[a],R))

def factinit(n,R):
    global fact
    fact = [1]*(n+1)
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%R

n,m,k = inm()
if n==m+1==k+2==-3:
    3/0
    print(0)
    exit()
if m==1:
    print(1 if k==n-1 else 0)
    exit()
factinit(n,R)
s = 0
x = (m*pow(m-1,n-1,R))%R
m1i = modinv2(m-1,R)
for j in range(k+1):
    s = (s + x*comb(n-1,j,R))%R
    x = (x*m1i)%R
    #ddprint(f"{j=} {s=} {x=}")
print(s)
Buggy code:
n, m, k = map(int, input().split())
mod = 998244353

fact = [1] * (n + 1)
revfact = [1] * (n + 1)
for i in range(n):
    fact[i + 1] = ((i + 1) * fact[i]) % mod
revfact[n] = pow(fact[n], mod - 2, mod)
for i in reversed(range(n)):
    revfact[i] = ((i + 1) * revfact[i + 1]) % mod
def combination(n, k, p):
    return (fact[n] * revfact[k] * revfact[n - k]) % p

count = 0
for i in range(k + 1):
    num = n - i
    temp = m
    for j in range(num - 1):
        temp *= m - 1
        temp %= mod
    temp *= combination(num, i, mod)
    temp %= mod
    count += temp
count %= mod
print(count)

Fixed code:
n, m, k = map(int, input().split())
mod = 998244353

fact = [1] * (n + 1)
revfact = [1] * (n + 1)
for i in range(n):
    fact[i + 1] = ((i + 1) * fact[i]) % mod
revfact[n] = pow(fact[n], mod - 2, mod)
for i in reversed(range(n)):
    revfact[i] = ((i + 1) * revfact[i + 1]) % mod
def combination(n, k, p):
    return (fact[n] * revfact[k] * revfact[n - k]) % p

count = 0
m_pow = [1]
for i in range(n):
    m_pow.append(m_pow[-1] * (m - 1) % mod)
for i in range(k + 1):
    temp = m
    temp *= m_pow[n - i - 1]
    temp *= combination(n - 1, i, mod)
    temp %= mod
    count += temp
count %= mod
print(count)
Buggy code:
n,m,k = map(int, input().split())

mod = 998244353
NUM = 3*(10**5)
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]

for i in range( 2, NUM + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inv.append( ( -inv[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inv[-1]) % mod )

def comb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

ans=0
for i in range(n-k):
    ret =(comb(n-1,i,mod)*m)
    ans+=ret
    ans%=mod

print(ans)

Fixed code:
n,m,k = map(int, input().split())

mod = 998244353
NUM = 3*(10**5)
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]

for i in range( 2, NUM + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inv.append( ( -inv[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inv[-1]) % mod )

def comb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

ans=0
for i in range(k+1):
    ret1 = m * pow(m-1,n-i-1,mod)
    ret2 = comb(n-1,i,mod)
    ans+=ret1*ret2
    ans%=mod

print(ans)
Buggy code:
n, m, k = map(int, input().split())

mod = 998244353

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, n):
    fac.append(fac[-1] * i % mod)
    inv.append(-inv[mod%i] * (mod // i) % mod)
    finv.append(finv[-1] * inv[-1] % mod)

ans = 0
for i in range(n-k-1, n):
    res = m
    e = m - 1
    while i > 0:
        if i & 1:
            res = res * e % mod
        e = e * e % mod
        i >>= 1
    com = fac[n-1] * finv[i] * finv[n-i-1] % mod
    res = res * com % mod
    ans = (ans + res) % mod

print(ans)

Fixed code:
n, m, k = map(int, input().split())

mod = 998244353

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, n):
    fac.append(fac[-1] * i % mod)
    inv.append(-inv[mod%i] * (mod // i) % mod)
    finv.append(finv[-1] * inv[-1] % mod)

ans = 0
for i in range(n-k-1, n):
    com = fac[n-1] * finv[i] * finv[n-i-1] % mod
    res = m
    e = m - 1
    while i > 0:
        if i & 1:
            res = res * e % mod
        e = e * e % mod
        i >>= 1
    res = res * com % mod
    ans = (ans + res) % mod

print(ans)
Buggy code:
N,M,K = map(int, input().split())
MOD = 998244353

fact = [1]
rfact = [1]
for i in range(1, N+1):
    fact.append(fact[i-1]*i%MOD)
    rfact.append(pow(fact[i], MOD-2, MOD))
 
def cmb(n, m):
    return fact[n]*rfact[m]*rfact[n-m]%MOD

answer = 0
for i in range(K+1):
    answer += M*cmb(N-1,i)*(M-1)**(N-1-i)*1**i
print(answer%MOD)

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

fact = [1]
rfact = [1]
for i in range(1, N+1):
    fact.append(fact[i-1]*i%MOD)
    rfact.append(pow(fact[i], MOD-2, MOD))
 
def cmb(n, m):
    return fact[n]*rfact[m]*rfact[n-m]%MOD

answer = 0
for i in range(K+1):
    answer += (M*cmb(N-1,i)*pow(M-1,N-1-i,MOD))%MOD
print(answer%MOD)
Buggy code:
class mod_combination:
    def __init__(self, N, mod):
        self.fac = [1] * (N + 1)
        for i in range(1, N + 1):
            self.fac[i] = (self.fac[i - 1] * i) % mod
        self.invmod = [1] * (N + 1)
        self.invmod[N] = pow(self.fac[N], mod - 2, mod)
        for i in range(N, 0, -1):
            self.invmod[i - 1] = (self.invmod[i] * i) % mod
        
    def calc(self, n, k): # nCk
        return self.fac[n] * self.invmod[k] % mod * self.invmod[n - k] % mod


n, m, k = map(int, input().split())
mod = 998244353
C = mod_combination(n, mod)
ans = 0
color = m
for x in reversed(range(n)):
    if x <= k:
        ans += C.calc(n - 1, x) * color
        ans %= mod
    color *= m - 1
print(ans)


Fixed code:
mod = 998244353

class mod_combination:
    def __init__(self, N):
        self.fac = [1] * (N + 1)
        for i in range(1, N + 1):
            self.fac[i] = (self.fac[i - 1] * i) % mod
        self.invmod = [1] * (N + 1)
        self.invmod[N] = pow(self.fac[N], mod - 2, mod)
        for i in range(N, 0, -1):
            self.invmod[i - 1] = (self.invmod[i] * i) % mod
        
    def calc(self, n, k): # nCk
        return self.fac[n] * self.invmod[k] % mod * self.invmod[n - k] % mod


n, m, k = map(int, input().split())
C = mod_combination(n)
ans = 0
for x in range(k + 1):
    ans = (ans + C.calc(n - 1, n - x - 1) * m * pow(m - 1, n - x - 1, mod) % mod) % mod
print(ans)
Buggy code:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

import sys
input = sys.stdin.readline
N, M, K = map(int, input().split())
mod = 998244353
ans = 0
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
for i in range(K+1):
    ans += pow(M-1, N-1-i, mod) * pow(M, i+1, mod) * cmb(N-1, i, mod)
    ans %= mod
ans %= mod
print(ans)

Fixed code:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

import sys
input = sys.stdin.readline
N, M, K = map(int, input().split())
mod = 998244353
ans = 0
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
for i in range(K+1):
    ans += pow(M-1, N-1-i, mod) * pow(M, 1, mod) * cmb(N-1, i, mod)
    ans %= mod
ans %= mod
print(ans)
Buggy code:
N,M,K = map(int,(input().split()))
MOD = 998244353
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]
 
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]
 
def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

ans = 0
for i in range(K+1):
    ans = (ans + (nCr(N-1,i) * M * pow(M-1,N-i-1,MOD)) %MOD)
print(ans)

Fixed code:
N,M,K = map(int,(input().split()))
MOD = 998244353
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]
 
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]
 
def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

ans = 0
for i in range(K+1):
    ans = (ans + (nCr(N-1,i) * M * pow(M-1,N-i-1,MOD))) %MOD
print(ans)
Buggy code:
M = 998244353
n,m,K = map(int,input().split())
ans = 0
c = 1
for k in range(K+1):
    ans += c * m * pow(m-1,n-k-1,M)
    c *= (n-k+1) * pow(k+1,M-2,M)
    ans %= M
    c %= M
print(ans)
    


Fixed code:
M = 998244353
n,m,K = map(int,input().split())
ans = 0
c = 1
for k in range(K+1):
    ans += c * m * pow(m-1,n-k-1,M)
    c *= (n-k-1) * pow(k+1,M-2,M)
    ans %= M
    c %= M
print(ans)
Buggy code:
N, M, K = map(int, input().split())
mod = 998244353
ans = 0
nCi = [1]

for i in range(1, N):
    nCi.append((nCi[i-1]*(N-i)//i)%mod)


for i in range(min(N, K)+1):
    ans += (M%mod) * pow(M - 1, N-1-i, mod) * nCi[i]
    ans %= mod

print(ans)


Fixed code:
N, M, K = map(int, input().split())
mod = 998244353
ans = 0
nCi = [1]

for i in range(1, N+1):
    nCi.append(nCi[i-1]*(N-i) * pow(i, mod-2, mod) % mod)


for i in range(K+1):
    ans += M * pow(M - 1, N-1-i, mod) * nCi[i]
    ans %= mod

print(ans)
Buggy code:
N, M, K = list(map(int, input().split()))
mod = 998244353

c = 1
answer = M * pow(M-1, N-1,mod)

for i in range(1, K+1):
    c = (c * (N-i) * pow(i, mod-2, mod)) % mod
    answer += (M * c  * pow(M-1, N -1- i, mod)) % mod
    answer %= mod
    
print(answer)

Fixed code:
N, M, K = list(map(int, input().split()))
mod = 998244353

c = 1
answer = 0

for i in range(K+1):
    answer += (M * c  * pow(M-1, N - i - 1, mod)) % mod
    answer %= mod
    c = (c * (N-i-1) * pow(i+1, mod-2, mod)) % mod
    
print(answer)
Buggy code:
N,M,K=map(int,input().split())
P=998244353
class FactInv:
    def __init__(self,N,P):
        fact=[];ifact=[];fact=[1]*(N+1);ifact=[0]*(N+1)
        for i in range(1,N):
            fact[i+1]=(fact[i]*(i+1))%P
        ifact[-1]=pow(fact[-1],P-2,P)
        for i in range(N,0,-1):
            ifact[i-1]=(ifact[i]*i)%P
        self.fact=fact;self.ifact=ifact;self.P=P
    def comb(self,n,k):
        return (self.fact[n]*self.ifact[k]*self.ifact[n-k])%self.P
FI=FactInv(N+10,P)
ans=0
for i in range(0,K+1):
    ans+=(M*FI.comb(N-1,i)*pow(M0,N-1-i,P))%P
    ans%=P
print(ans)

Fixed code:
N,M,K=map(int,input().split())
P=998244353
class FactInv:
    def __init__(self,N,P):
        fact=[];ifact=[];fact=[1]*(N+1);ifact=[0]*(N+1)
        for i in range(1,N):
            fact[i+1]=(fact[i]*(i+1))%P
        ifact[-1]=pow(fact[-1],P-2,P)
        for i in range(N,0,-1):
            ifact[i-1]=(ifact[i]*i)%P
        self.fact=fact;self.ifact=ifact;self.P=P
    def comb(self,n,k):
        return (self.fact[n]*self.ifact[k]*self.ifact[n-k])%self.P
FI=FactInv(N+10,P)
ans=0
for k in range(0,K+1):
    ans+=(M*FI.comb(N-1,k)*pow(M-1,N-1-k,P))%P
    ans%=P
print(ans)
Buggy code:
mod= 998244353

n,m,k=map(int,input().split())

ans=0
cmb=1
for i in range(k+1):
    ans+=cmb*m*pow(m-1,n-1-i,mod)
    ans%=mod
    X=(n-1-i)*pow(i+1,mod-2,mod)
    X%=mod
print(ans)

Fixed code:
mod= 998244353

n,m,k=map(int,input().split())

ans=0
cmb=1
for i in range(k+1):
    ans+=cmb*m*pow(m-1,n-1-i,mod)
    ans%=mod
    cmb*=(n-1-i)*pow(i+1,mod-2,mod)
    cmb%=mod
print(ans)
Buggy code:
N = int(input())
lremain = []
rremain = []

for i in range(N):
	S = input()
	left = 0
	right = 0
	for c in S:
		if c == ".":
			left += 1
		else:
			if left == 0:
				right += 1
			else:
				left -= 1
	if left == 0 and right == 0:
		continue
	lremain.append(left)
	rremain.append(right)

N = len(lremain)

if sum(lremain) != sum(rremain):
	print("No")
	exit()

head = 0
tail = 0
removei = []
for i in range(N):
	if rremain[i] == 0:
		head += lremain[i]
		removei.append(i)
	if lremain[i] == 0:
		tail += rremain[i]
		removei.append(i)

lnr = []
for i in range(N):
	if not i in removei:
		lnr.append((lremain[i], rremain[i]))

N = len(lnr)
lnr.sort(key = lambda x: (x[1], x[1] - x[0]))

for i in range(N):
	if head < lnr[i][1]:
		print("No")
		exit()
	head -= lnr[i][1]
	head += lnr[i][0]

if head == tail:
	print("Yes")
else:
	print("No")

Fixed code:
N = int(input())
lremain = []
rremain = []

for i in range(N):
	S = input()
	left = 0
	right = 0
	for c in S:
		if c == "(":
			left += 1
		else:
			if left == 0:
				right += 1
			else:
				left -= 1
	if left == 0 and right == 0:
		continue
	lremain.append(left)
	rremain.append(right)

N = len(lremain)

if sum(lremain) != sum(rremain):
	print("No")
	exit()

head = 0
tail = 0
removei = set()
for i in range(N):
	if rremain[i] == 0:
		head += lremain[i]
		removei.add(i)
	if lremain[i] == 0:
		tail += rremain[i]
		removei.add(i)

lnr = []
for i in range(N):
	if not i in removei:
		lnr.append((lremain[i], rremain[i]))

N = len(lnr)
lnr.sort(key = lambda x: (x[1]-x[0]))

for i in range(N):
	if head < lnr[i][1]:
		print("No")
		exit()
	head -= lnr[i][1]
	head += lnr[i][0]

if head == tail:
	print("Yes")
else:
	print("No")