Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
if if n*500>=m:
    print("Yes")
else:
    print("No")

Fixed submission:

n,m=map(int,input().split())
print("Yes") if n*500>=m else print("No")
Buggy python submission (verdict: Runtime Error):
n=(input())
a=tuple(map(int,input().split()))
b=tuple(map(int,input().split()))
import itertools as it
x=0
y=0
for i,j in enumerate(it.permutations(range(1,n+1))):
    if a==j:
        x=i
    if b==j:
        y=i
print(abs(x-y))


Fixed submission:
n=int(input())
a=tuple(map(int,input().split()))
b=tuple(map(int,input().split()))
import itertools as it
x=0
y=0
for i,j in enumerate(it.permutations(list(range(1,n+1)))):
    if a==j:
        x=i
    if b==j:
        y=i
print(abs(x-y))
Buggy python submission (verdict: Runtime Error):
nn=int(input())
n=10**5+100
ar=[0]*(n)
ar[1]=0
ans=0
pre=1
for i in range(2,int((n**0.5))+1):
    if ar[i]==0:

        for j in range(2*i,n,i):
            ar[j]=1
ans=1
if ar[nn]==0:
    print(nn)
else:
        
    for i in range(nn,n):
        if ar[i]==0:
            print(i)
            break
        

        

Fixed submission:
a,b=map(str,input().split())
print(b+a)
Buggy python submission (verdict: Runtime Error):
nn=int(input())
n=10**5+100
ar=[0]*(n)
ar[1]=0
ans=0
pre=1
for i in range(2,(n**0.5)+1):
    if ar[i]==0:

        for j in range(2*i,n,i):
            ar[j]=1
ans=1
if ar[nn]==0:
    print(nn)
else:
        
    for i in range(nn,n):
        if ar[i]==0:
            print(i)
            break
        

        

Fixed submission:
nn=int(input())
n=10**5+100
ar=[0]*(n)
ar[1]=0
ans=0
pre=1
for i in range(2,n):
    if ar[i]==0:

        for j in range(2*i,n,i):
            ar[j]=1
ans=1
if ar[nn]==0:
    print(nn)
else:
        
    for i in range(nn,n):
        if ar[i]==0:
            print(i)
            break

Buggy python submission (verdict: Runtime Error):
nn=int(input())
n=10**5+100
ar=[0]*(n)
ar[1]=0
ans=0
pre=1
for i in range(2,(n**0.5)+1):
    if ar[i]==0:

        for j in range(2*i,n,i):
            ar[j]=1
ans=1
if ar[nn]==0:
    print(nn)
else:
        
    for i in range(nn,n):
        if ar[i]==0:
            print(i)
            break
        

        

Fixed submission:
nn=int(input())
n=10**5+100
ar=[0]*(n)
ar[1]=0
ans=0
pre=1
for i in range(2,n):
    if ar[i]==0:

        for j in range(2*i,n,i):
            ar[j]=1
ans=1
if ar[nn]==0:
    print(nn)
else:
        
    for i in range(nn,n):
        if ar[i]==0:
            print(i)
            break

Buggy python submission (verdict: Time Limit Exceeded):
nn=int(input())
n=10**5+1
a=[0]*n
a[1]=0
ans=1
pre=1
if nn==1:
    print(1)
else:
        
    for i in range(2,n):
        if a[i]==0:
    
            if i>=nn:
                print(i)
                break
            pre =ans
            ans=i
            
            for j in range(i+1,n):
                #print(i,j,a[j])
                if j%i==0:
                    a[j]=1
                    #print("asdf",i,j,a[j])
    """
    for i in range(nn,n):
        if a[i]==0:
            print(i)
    
            
                    
                    
    """             

Fixed submission:
nn=int(input())
n=10**5+100
ar=[0]*(n)
ar[1]=0
ans=0
pre=1
for i in range(2,n):
    if ar[i]==0:

        for j in range(2*i,n,i):
            ar[j]=1
ans=1
if ar[nn]==0:
    print(nn)
else:
        
    for i in range(nn,n):
        if ar[i]==0:
            print(i)
            break
Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
tem=max(a,b)
while 1:
    if tem%a==0  and tem%b==0:
        print(tem)
        break
    else:
        tem+=1

Fixed submission:
import math as mt
a,b=map(int,input().split())
tem=max(a,b)
c=1
if a==b:
    print(a)
elif min(a,b)==1:
    print(max(a,b))
elif a%b==0 or b%a==0:
    print(max(a,b))
else:
        
    while 1:
        c+=1
        if (tem*c)%a==0 and (tem*c)%b==0:
            print(tem*c)
            break
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n%2:
    print(0)
else:
    l=0
    x=n//2
    while x>0:
        l+=n//5
        x=n//5
print(l)

Fixed submission:
n = int(input())
if n%2:
  print(0)
else:
  p=n//2
  l=0
  while p>0:
    l+=p//5
    p//=5
  print(l)

Buggy python submission (verdict: Runtime Error):
n=int(input())
if n%2:
    print(0)
else:
    l=0
    n=n//2
    while n>0:
        l+=n//5
        n=n//5
print(l)

Fixed submission:
n = int(input())
if n%2:
  print(0)
else:
  p=n//2
  l=0
  while p>0:
    l+=p//5
    p//=5
  print(l)

Buggy python submission (verdict: Runtime Error):
n=int(input())
if n%2:
    print(0)
else:
    l=0
    n=n//2
    while n>0:
        l+=n//5
        n=n//5
print(l)

Fixed submission:
n = int(input())
if n%2:
  print(0)
else:
  p=n//2
  l=0
  while p>0:
    l+=p//5
    p//=5
  print(l)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
dp=[0]*(n)
dp[0]=0
dp[1]=abs(l[0]-l[1])
dp[2]=abs(l[2]-l[1])
for i in range(2,n):
    dp[i]=min(abs(l[i]-l[i-2])+dp[i-2],abs(l[i]-l[i-1])+dp[i-1])
print(dp[-1])

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
dp=[0]*(n)
dp[0]=0
dp[1]=abs(l[0]-l[1])
for i in range(2,n):
    dp[i]=min(abs(l[i]-l[i-2])+dp[i-2],abs(l[i]-l[i-1])+dp[i-1])
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import math as mt
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=[mt.inf]*(n)
a[0]=0
for i in range(1,n):
    for j in range(1,k+1):
        if i-j>=0:
            a[i]=min(a[i],abs( l[i]-l[i-j])+a[i-j]) 
print(a[-1])


Fixed submission:

n,k=map(int,input().split())
l=list(map(int,input().split()))
a=[10**9+7]*(n)
a[0]=0
for i in range(1,n):
    for j in range(1,k+1):
        if i-j>=0:
            a[i]=min(a[i],abs( l[i]-l[i-j])+a[i-j]) 
print(a[-1])

Buggy python submission (verdict: Runtime Error):
import math as mt
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=[mt.inf]*(n)
a[0]=0
for i in range(1,n):
    for j in range(1,k+1):
        if i-j>=0:
            a[i]=min(a[i],abs( l[i]-l[i-j])+a[i-j]) 
print(a[-1])


Fixed submission:

n,k=map(int,input().split())
l=list(map(int,input().split()))
a=[10**9+7]*(n)
a[0]=0
for i in range(1,n):
    for j in range(1,k+1):
        if i-j>=0:
            a[i]=min(a[i],abs( l[i]-l[i-j])+a[i-j]) 
print(a[-1])
Buggy python submission (verdict: Runtime Error):
s=input()
temp=0
tem=0
tot=0
if len(s)>10**3:
        
    for i in range(len(s)):
        tem=1
        temp=1
        flag=0
        for j in range(i+1,len(s)):
            if s[j]==s[i]:
                temp+=1
            tem+=1
            if temp>(tem//2 ):
                print(i+1,j+1)
                
                flag=1
                tot=1
                break
        if flag:
            break
    if tot==0:
        print("-1 -1")
else:
    for i in range(len(s)-2):
        if s[i]==s[i+1]:
            print(i+1,i+2)
            flag=1
            break
        elif s[i]==s[i+2]:
            print(i+1,i+3)
            flag=1
            break
    if flag==0:
        print("-1 -1")        

Fixed submission:
n=int(input())
print(int(n*(n+1)/2))

Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
x=10**9+7
if max(l)==min(l):
    print(0)
else:
        
    for i in range(min(l),max(l)+1):
        te=0
        
        for j in l:
            te=te+(abs(j-i))**2
        #print(i,te)
        x=min(x,te)
    print(x)        

Fixed submission:
n=int(input())
print(int(n*(n+1)/2))
Buggy python submission (verdict: Runtime Error):
s=input()
temp=0
tem=0
tot=0
if len(s)>10**3:
        
    for i in range(len(s)):
        tem=1
        temp=1
        flag=0
        for j in range(i+1,len(s)):
            if s[j]==s[i]:
                temp+=1
            tem+=1
            if temp>(tem//2 ):
                print(i+1,j+1)
                
                flag=1
                tot=1
                break
        if flag:
            break
    if tot==0:
        print("-1 -1")
else:
    for i in range(len(s)-2):
        if s[i]==s[i+1]:
            print(i+1,i+2)
            flag=1
            break
        elif s[i]==s[i+2]:
            print(i+1,i+3)
            flag=1
            break
    if flag==0:
        print("-1 -1")        

Fixed submission:
s=input()
temp=0
tem=0
tot=0
flag=0
if s[-2]==s[-1]:
    print(len(s)-1,len(s))
else:
        
    if 1:
        for i in range(len(s)-2):
            if s[i]==s[i+1]:
                print(i+1,i+2)
                flag=1
                break
            elif s[i]==s[i+2]:
                print(i+1,i+3)
                flag=1
                break
        if flag==0:
            print("-1 -1")

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
temp=0
tem=0
tot=0
for i in range(len(s)):
    tem=1
    temp=1
    flag=0
    for j in range(i+1,len(s)):
        if s[j]==s[i]:
            temp+=1
        tem+=1
        if temp>(tem//2 ):
            print(i+1,j+1)
            
            flag=1
            tot=1
            break
    if flag:
        break
if tot==0:
    print("-1 -1")

Fixed submission:
s=input()
temp=0
tem=0
tot=0
flag=0
if s[-2]==s[-1]:
    print(len(s)-1,len(s))
else:
        
    if 1:
        for i in range(len(s)-2):
            if s[i]==s[i+1]:
                print(i+1,i+2)
                flag=1
                break
            elif s[i]==s[i+2]:
                print(i+1,i+3)
                flag=1
                break
        if flag==0:
            print("-1 -1")
Buggy python submission (verdict: Runtime Error):
import sys
# import numpy as np 
 
def main():
    a, b = map(int, sys.stdin.read().split())
 
    if 0 < a:
        ans = 'Positive'
    elif 0 <= b:
        ans = 'Zero'
    else:
        if (b - a + 1) % 2 == 0:
            ans = 'Positive'
        else:
            ans = 'Negative'
    
    print(ans)
 
if __name__ == '__main__':
    main(

Fixed submission:
import sys
# import numpy as np 
 
def main():
    a, b = map(int, sys.stdin.read().split())
 
    if 0 < a:
        ans = 'Positive'
    elif 0 <= b:
        ans = 'Zero'
    else:
        if (b - a + 1) % 2 == 0:
            ans = 'Positive'
        else:
            ans = 'Negative'
    
    print(ans)
 
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
I=lambda:list(map(int,input().split()))
a=I()
if a[0]>=0:
    print("Positive")
else:
    d=list(range(a[0],a[1]+1))
    if 0 in d:
        print("Zero")
    elif len(d)%2==0:
        print("Positive")
    else:
        print("Negative")

Fixed submission:
import sys
# import numpy as np 
 
def main():
    a, b = map(int, sys.stdin.read().split())
 
    if 0 < a:
        ans = 'Positive'
    elif 0 <= b:
        ans = 'Zero'
    else:
        if (b - a + 1) % 2 == 0:
            ans = 'Positive'
        else:
            ans = 'Negative'
    
    print(ans)
 
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
    import math
    from functools import reduce
     
    def lcm_base(x, y):
        return (x * y) // math.gcd(x, y)
     
    def lcm_list(numbers):
        return reduce(lcm_base, numbers, 1)
      
    N = int(input())
    A = list(map(int,input().split()))
    ans = 0
     
    lcm = lcm_list(A)
     
    for i in range(N):
      ans += lcm//A[i]
     
    print(ans%1000000007)

Fixed submission:
import math
from functools import reduce
     
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
     
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
      
N = int(input())
A = list(map(int,input().split()))
ans = 0
     
lcm = lcm_list(A)
     
for i in range(N):
    ans += lcm//A[i]
     
print(ans%1000000007)

Buggy python submission (verdict: Runtime Error):
    def gcd(a,b): 
        if a == 0: 
            return b 
        return gcd(b % a, a) 
      
    def lcm(a,b): 
        return (a*b) // gcd(a,b) 
      
    n = int(input())
    arr = input()   # takes the whole line of n numbers
    a = list(map(int,arr.split(' ')))
    l = a[0]
    ans = 0
    for i in range(n):
        l = lcm(l, a[i])
    for i in range(n):
        ans = ans + l//a[i]
    print(ans%1000000007)

Fixed submission:
import math
from functools import reduce
     
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
     
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
      
N = int(input())
A = list(map(int,input().split()))
ans = 0
     
lcm = lcm_list(A)
     
for i in range(N):
    ans += lcm//A[i]
     
print(ans%1000000007)
Buggy python submission (verdict: Runtime Error):
n, k = (int(x) for x in input().split())
p = list(int(x) for x in input().split())

max_val = 0
for i in range(0, len(p)-k+1):
  tmp = p[i:i+k]
  val = sum([sum([x for x in range(1, t+1)]) / t for t in tmp])

  if max_val < val:
    max_val = val

print('{:.12f}'.format(val))

Fixed submission:
s, t = input().split()
a, b = (int(x) for x in input().split())
u = input()

if s == u:
  a -= 1
else:
  b -= 1

print('{} {}'.format(a, b))
Buggy python submission (verdict: Time Limit Exceeded):
_ = input()
_list = input()
 
num_list = _list.split(' ')
 
for num in num_list:
  if num_list.count(num) > 1:
    print('NO')
    break
else:
  print('YES') 

Fixed submission:
import collections

_ = input()
_list = input()
 
num_list = _list.split(' ')
 
c = collections.Counter(num_list)
if c.most_common()[0][1] > 1:
  print('NO')
else:
  print('YES')
Buggy python submission (verdict: Runtime Error):
a, b, c = input().split()

if a + b + c >= 22:
  print('bust')
else:
  print('win')

Fixed submission:
a, b, c = input().split()

if int(a) + int(b) + int(c) >= 22:
  print('bust')
else:
  print('win')
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import math

N = int(input())
_N = N

size = int (math.log10(N) + 1)

f = 0
while(size > 0):
    if(size > 1):
        f += int(N/(10**(size-1)))
        N %= 10**(size-1)
    else:
        f += N
    size -= 1

if(_N%f == 0):
    print('Yes')
else:
    print('No')

Fixed submission:
N, A, B = [int(i) for i in input().split()]

cost = B

if(N*A < B):
    cost = N*A

print(cost)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import math

N = int(input())
_N = N

size = int (math.log10(N) + 1)

f = 0
while(size > 0):
    if(size > 1):
        f += int(N/(10**(size-1)))
        # print(int(N/(10**(size-1))))
        N %= 10**(size-1)
    else:
        f += N
        # print(N)
    size -= 1

# print(_N, f, _N%f)

if(_N%f == 0):
    print('Yes')
else:
    print('No')

Fixed submission:
N, A, B = [int(i) for i in input().split()]

cost = B

if(N*A < B):
    cost = N*A

print(cost)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    k, s = input().split()
    k, s = int(k), int(s)

    count = 0
    for x in range(k+1):
        for y in range(k+1):
            for z in range(k+1):
                if x + y + z == s:
                    count += 1

    print(count)


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    k, s = input().split()
    k, s = int(k), int(s)

    count = 0
    for x in range(k+1):

        if k*2 + x < s:
            continue

        for y in range(k+1):
            if 0 <= (s - x - y) <= k:
                count += 1

    print(count)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
import itertools
import math

if __name__ == "__main__":
    N = int(sys.stdin.readline())

    for i in range(1, N+1):
        ans = 0
        ls = range(1, int(math.sqrt(i)))
        # ls = range(1, int(math.sqrt(i))-2*i)
        # print(ls)
        for (x,y,z) in sorted(itertools.combinations_with_replacement(ls, 3), key=lambda x: (sum(x), max(x))):
            tmp = x**2+y**2+z**2+x*y+y*z+z*x
            if tmp > i:
                break
            elif i == tmp:
                ans += 1
                if x == y and y == z:
                    continue
                elif x == y or y == z or z == x:
                    ans += 3-1
                else:
                    ans += 6-1
        print(ans)

Fixed submission:
import sys

if __name__ == "__main__":
    L, R, d = list(map(lambda x: int(x), sys.stdin.readline().split()))
    ans = sum([1 if i % d == 0 else 0 for i in range(L, R+1)])
        
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

if __name__ == '__main__':
    n = int(sys.stdin.readline())
    a = list(map(lambda x: int(x), sys.stdin.readline().split()))
    for i in range(len(a)):
        ans = 0
        for j in range(len(a)):
            if i == j:
                continue
            else:
                ans ^= a[j]
        print(ans, end=' ')
    print()

# スヌケ君dの値が知りたい：d以外の人の計算結果を全部xorする

Fixed submission:
import sys

if __name__ == '__main__':
    n = int(sys.stdin.readline())
    A = list(map(lambda x: int(x), sys.stdin.readline().split()))
    allxor = 0
    for a in A:
        allxor ^= a
    for a in A:
        print(allxor^a, end=' ')
    print()

# スヌケ君dの値が知りたい：d以外の人の計算結果を全部xorする
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math

if __name__ == '__main__':
    a, b, n = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    old = 0

    for x in range(n+1):
        tmp = math.floor(a*x/b)-a*math.floor(x/b)
        if tmp < old:
            print(old)
            break
        else:
            old = tmp
    else:
        print(tmp)

Fixed submission:
import sys
import math

if __name__ == '__main__':
    a, b, n = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    old = 0
    if 0 <= b-1 and b-1 <= n:
        x = b - 1
        print(math.floor(a*x/b)-a*math.floor(x/b))
    else:
        x = n
        print(math.floor(a*x/b)-a*math.floor(x/b))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  k = int(input())
  num = 7 % k
  first = num
  ans = 1
  while num != 0:
    ans += 1
    num = (num*10 + 7)%k
    if num == first:
      ans = -1
      break
  print(ans)
    
    
if __name__ == "__main__":
  main()

Fixed submission:
def main():
  k = int(input())
  num = 7 % k
  first = num
  ans = 1
  while num != 0:
    ans += 1
    num = (num*10 + 7)%k
    if num == first or ans > 2000000:
      ans = -1
      break
  print(ans)
    
    
if __name__ == "__main__":
  main()
Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

def main():
  dp = [0]*(S+1)
  dp[0] = 1
  for i in range(1, N+1):
    p = [0]*(S+1)
    dp, p = p, dp
    for j in range(0, S+1):
      dp[j] += 2*p[j]
      dp[j] %= MOD
      if j-A[i-1] >= 0:
        dp[j] += p[j-A[i-1]]
        dp[j] %= MOD
  print(dp[S])

if __name__ == "__main__":
  main()

Fixed submission:
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

def main():
  dp = [0]*(S+1)
  dp[0] = 1
  for i in range(1, N+1):
    p = [0]*(S+1)
    dp, p = p, dp
    for j in range(0, S+1):
      dp[j] += 2*p[j]
      dp[j] %= MOD
      if j-A[i-1] >= 0:
        dp[j] += p[j-A[i-1]]
        dp[j] %= MOD
  print(dp[S])

if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
dp = [[0]*(S+1) for _ in range(N+1)]
def main():
  dp[0][0] = 1
  for i in range(1, N+1):
    for j in range(0, S+1):
      dp[i][j] += 2*dp[i-1][j]
      dp[i][j] %= MOD
      if j-A[i-1] >= 0:
        dp[i][j] += dp[i-1][j-A[i-1]]
        dp[i][j] %= MOD
  print(dp[N][S])

if __name__ == "__main__":
  main()


Fixed submission:
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

def main():
  dp = [0]*(S+1)
  dp[0] = 1
  for i in range(1, N+1):
    p = [0]*(S+1)
    dp, p = p, dp
    for j in range(0, S+1):
      dp[j] += 2*p[j]
      dp[j] %= MOD
      if j-A[i-1] >= 0:
        dp[j] += p[j-A[i-1]]
        dp[j] %= MOD
  print(dp[S])

if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
dp = [[0]*(S+1) for _ in range(N+1)]
def main():
  dp[0][0] = 1
  for i in range(1, N+1):
    for j in range(0, S+1):
      dp[i][j] += (2*dp[i-1][j])%MOD
      dp[i][j] %= MOD
      if j+A[i-1] <= S:
        dp[i][j+A[i-1]] += dp[i-1][j]%MOD
        dp[i][j+A[i-1]] %= MOD
  print(dp[N][S])

if __name__ == "__main__":
  main()

Fixed submission:
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

def main():
  dp = [0]*(S+1)
  dp[0] = 1
  for i in range(1, N+1):
    p = [0]*(S+1)
    dp, p = p, dp
    for j in range(0, S+1):
      dp[j] += 2*p[j]
      dp[j] %= MOD
      if j-A[i-1] >= 0:
        dp[j] += p[j-A[i-1]]
        dp[j] %= MOD
  print(dp[S])

if __name__ == "__main__":
  main()
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 998244353
#階乗のリストを作成する
N, M, K = map(int, input().split())
frac = [1]
for i in range(N):
    frac.append(frac[i]*(i+1)%MOD)

#上の公式を用いてcombの計算を行う
def comb(n, k, mod):
    a=frac[n]
    b=frac[k]
    c=frac[n-k]
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod
  
def main():
  ans = [0] * (K+1)
  temp = 1
  for i in range(N):
    if i == 0:
      temp*=M
      temp %= MOD
    else:
      temp *= (M-1)
      temp %= MOD
    if i+1 >= N-K:
      ans[i+1-N+K] = temp
  t_ans = 0
  key = 1
  for i in range(len(ans)):
    t_ans += (ans[-1-i]*key) % MOD
    t_ans %= MOD
    key *= (N-i-1)
    key //= (i+1)
  print(t_ans)
if __name__ == "__main__":
  main()

Fixed submission:
MOD = 998244353
#階乗のリストを作成する
N, M, K = map(int, input().split())
frac = [1]
for i in range(N):
    frac.append(frac[i]*(i+1)%MOD)

#上の公式を用いてcombの計算を行う
def comb(n, k, mod):
    a=frac[n]
    b=frac[k]
    c=frac[n-k]
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod
  
def main():
  ans = [0] * (K+1)
  temp = 1
  for i in range(N):
    if i == 0:
      temp*=M
      temp %= MOD
    else:
      temp *= (M-1)
      temp %= MOD
    if i+1 >= N-K:
      ans[i+1-N+K] = temp
  t_ans = 0
  for i in range(len(ans)):
    key = comb(N-1, i, MOD)
    t_ans += (ans[-1-i]*key)
    t_ans %= MOD
  print(t_ans)
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 998244353
def main():
  N, M, K = map(int, input().split())
  ans = [0] * (K+1)
  temp = 1
  for i in range(N):
    if i == 0:
      temp*=M
      temp %= MOD
    else:
      temp *= (M-1)
      temp %= MOD
    if i+1 >= N-K:
      ans[i+1-N+K] = temp
  t_ans = 0
  key = 1
  for i in range(len(ans)):
    t_ans += (ans[-1-i]*key) % MOD
    t_ans %= MOD
    key *= (N-i-1)
    key //= (i+1)
  print(t_ans)
if __name__ == "__main__":
  main()

Fixed submission:
MOD = 998244353
#階乗のリストを作成する
N, M, K = map(int, input().split())
frac = [1]
for i in range(N):
    frac.append(frac[i]*(i+1)%MOD)

#上の公式を用いてcombの計算を行う
def comb(n, k, mod):
    a=frac[n]
    b=frac[k]
    c=frac[n-k]
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod
  
def main():
  ans = [0] * (K+1)
  temp = 1
  for i in range(N):
    if i == 0:
      temp*=M
      temp %= MOD
    else:
      temp *= (M-1)
      temp %= MOD
    if i+1 >= N-K:
      ans[i+1-N+K] = temp
  t_ans = 0
  for i in range(len(ans)):
    key = comb(N-1, i, MOD)
    t_ans += (ans[-1-i]*key)
    t_ans %= MOD
  print(t_ans)
if __name__ == "__main__":
  main()