Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))

import bisect
L.sort()
ans=0
i=0
while i<N-2:
    j=i+1
    while j<N-1:
        x=bisect.bisect_left(L[j+1:],L[i]+L[j])
        ans+=x
        j+=1
    i+=1
print(ans)




Fixed submission:
N=int(input())
L=list(map(int,input().split()))

L.sort()
ans=0
i=0
while i<N-2:
    j=i+1
    k=j+1
    while j<N-1:
        while k<N:
            if L[i]+L[j]<=L[k]:
                ans+=k-j-1
                break
            k+=1
        if k==N:
            ans+=k-1-j
        j+=1
    i+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))

L.sort()
c=N-1
ans=0
while c>1:
  for i in range(c):
    for j in range(i+1,c):
      if L[c]<L[i]+L[j]:
        ans+=c-j
        break

  c-=1
print(ans)


Fixed submission:
N=int(input())
L=list(map(int,input().split()))

L.sort()
ans=0
i=0
while i<N-2:
    j=i+1
    k=j+1
    while j<N-1:
        while k<N:
            if L[i]+L[j]<=L[k]:
                ans+=k-j-1
                break
            k+=1
        if k==N:
            ans+=k-1-j
        j+=1
    i+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))

L.sort()
c=N-1
ans=0
while c>1:
  for i,a in enumerate(L[:c]):
    for b in L[i+1:c]:
      if L[c]<a+b:
        ans+=1
  c-=1
print(ans)

Fixed submission:
N=int(input())
L=list(map(int,input().split()))

L.sort()
ans=0
i=0
while i<N-2:
    j=i+1
    k=j+1
    while j<N-1:
        while k<N:
            if L[i]+L[j]<=L[k]:
                ans+=k-j-1
                break
            k+=1
        if k==N:
            ans+=k-1-j
        j+=1
    i+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int,input().split()))
def waribiki():
    global M
    A[-1]=A[-1]//2
    M-=1
    if A[-2]<A[-1]:
        waribiki()
while M>0:
    A.sort()
    waribiki()
print(sum(A))

Fixed submission:
N, M= map(int, input().split())
A = list(map(int,input().split()))
A=[-1*a for a in A]
import heapq
import math
hq=heapq.heapify(A)
for m in range(M):
    X=heapq.heappop(A)
    heapq.heappush(A,math.ceil(X/2))
print(sum(A)*-1)

Buggy python submission (verdict: Time Limit Exceeded):
N, M= map(int, input().split())
A = list(map(int,input().split()))
for m in range(M):
    A.sort()
    A[-1]=A[-1]//2
print(sum(A))

Fixed submission:
N, M= map(int, input().split())
A = list(map(int,input().split()))
A=[-1*a for a in A]
import heapq
import math
hq=heapq.heapify(A)
for m in range(M):
    X=heapq.heappop(A)
    heapq.heappush(A,math.ceil(X/2))
print(sum(A)*-1)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
if N==1:
  print(0)
  exit(0)
a=[i for i in range(1,N)]
print(sum(a))

Fixed submission:
N=int(input())
if N==1:
  print(0)
  exit(0)
#a=[i for i in range(1,N)]
#print(sum(a))
if (N-1)%2==0:
  print(N*((N-1)//2))
else:
  print(N*((N-1)//2)+((N-1)//2)+1)
Buggy python submission (verdict: Runtime Error):
a = int(input())
s = input()
if a<3200:
  print('red',flush=true)
else:
  print(s,flush=true)

Fixed submission:
a = int(input())
s = input()
if a<3200:
  print('red')
else:
  print(s)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = map(int,input())
x =0
for a in A:
  x+=1/A
print("{:,5f}".format(1/x))

Fixed submission:
N = int(input())
A = map(int,input().split())
x =0
for a in A:
  x+=1/a
x=1/x
print("{}".format(x))
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
AB.sort(key=lambda x:x[0])
AB.append([10**5+1,0])
h=[]
ans=0
for i in range(1,M+1):
  while AB[0][0]<=i:
    heapq.heappush(h,-AB.pop(0)[1])
  if len(h)>0:
    ans+=-heapq.heappop(h)
print(ans)

Fixed submission:
import heapq
import sys
input = sys.stdin.readline
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
AB.sort(key=lambda x:x[0])
AB.append([10**5+1,0])
h=[]
ans=0
for i in range(1,M+1):
  while AB[0][0]<=i:
    heapq.heappush(h,-AB.pop(0)[1])
  if len(h)>0:
    ans+=-heapq.heappop(h)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
M=0
X=[]
for i in range(N-1,-1,-1):
  _=0
  for j in range(i+1,N+1,i+1):
    if j in X:
      _+=1
  if A[i]==0 and _%2==1:
    M+=1
    X.append(i+1)
  elif A[i]==1 and _%2==0:
    M+=1
    X.append(i+1)
print(M)
print(*X)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
M=0
X=[]
XX=[0]*N
for i in range(N-1,-1,-1):
  _=0
  for j in range(i+1,N+1,i+1):
    _+=XX[j-1]
  if A[i]==0 and _%2==1:
    M+=1
    X.append(i+1)
    XX[i]=1
  elif A[i]==1 and _%2==0:
    M+=1
    X.append(i+1)
    XX[i]=1
print(M)
print(*X)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
M=0
X=[]
for i in range(N-1,-1,-1):
  _=0
  for x in X:
    if x%(i+1)==0:
      _+=1
  if A[i]==0 and _%2==1:
    M+=1
    X.append(i+1)
  elif A[i]==1 and _%2==0:
    M+=1
    X.append(i+1)
print(M)
print(*X)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
M=0
X=[]
XX=[0]*N
for i in range(N-1,-1,-1):
  _=0
  for j in range(i+1,N+1,i+1):
    _+=XX[j-1]
  if A[i]==0 and _%2==1:
    M+=1
    X.append(i+1)
    XX[i]=1
  elif A[i]==1 and _%2==0:
    M+=1
    X.append(i+1)
    XX[i]=1
print(M)
print(*X)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
Tree=[[] for i in range(N)]
MOD=10**9+7
import sys
sys.setrecursionlimit(2*N)
for i in range(N-1):
  a,b=map(int,input().split())
  Tree[a-1].append(b-1)
  Tree[b-1].append(a-1)
def P(n,m):
  _=n
  for i in range(m-1):
    n-=1
    _*=(n%MOD)
  return _%MOD
def dfs(p,i):
  global Tree,ans
  n=len(Tree[i])-1
  if n==0:
    return
  if i==0:
    ans*=P(K-1,n)
  else:
    ans*=P(K-2,n)
    ans%=MOD
  for j in Tree[i]:
    if j==p:
      continue
    dfs(i,j)
Tree[0].append(-1)
ans=K
dfs(-1,0)
print(ans%MOD)

Fixed submission:
N,K=map(int,input().split())
Tree=[[] for i in range(N)]
MOD=10**9+7
import sys
sys.setrecursionlimit(10**9)
for i in range(N-1):
  a,b=map(int,input().split())
  Tree[a-1].append(b-1)
  Tree[b-1].append(a-1)
def P(n,m):
  _=n
  for i in range(m-1):
    n-=1
    _*=n
    _%=MOD
  return _%MOD
def dfs(p,i):
  global Tree,ans
  n=len(Tree[i])-1
  if n==0:
    return
  if i==0:
    ans*=P(K-1,n)
  else:
    ans*=P(K-2,n)
    ans%=MOD
  for j in Tree[i]:
    if j==p:
      continue
    dfs(i,j)
Tree[0].append(-1)
ans=K
dfs(-1,0)
print(ans%MOD)

Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
Tree=[[] for i in range(N)]
MOD=10**9+7
for i in range(N-1):
  a,b=map(int,input().split())
  Tree[a-1].append(b-1)
  Tree[b-1].append(a-1)
def P(n,m):
  _=n
  for i in range(m-1):
    n-=1
    _*=(n%MOD)
  return _%MOD
def dfs(p,i):
  global Tree,ans
  n=len(Tree[i])-1
  if n==0:
    return
  if i==0:
    ans*=P(K-1,n)
  else:
    ans*=P(K-2,n)
  for j in Tree[i]:
    if j==p:
      continue
    dfs(i,j)
Tree[0].append(-1)
ans=K
dfs(-1,0)
print(ans%MOD)

Fixed submission:
N,K=map(int,input().split())
Tree=[[] for i in range(N)]
MOD=10**9+7
import sys
sys.setrecursionlimit(10**9)
for i in range(N-1):
  a,b=map(int,input().split())
  Tree[a-1].append(b-1)
  Tree[b-1].append(a-1)
def P(n,m):
  _=n
  for i in range(m-1):
    n-=1
    _*=n
    _%=MOD
  return _%MOD
def dfs(p,i):
  global Tree,ans
  n=len(Tree[i])-1
  if n==0:
    return
  if i==0:
    ans*=P(K-1,n)
  else:
    ans*=P(K-2,n)
    ans%=MOD
  for j in Tree[i]:
    if j==p:
      continue
    dfs(i,j)
Tree[0].append(-1)
ans=K
dfs(-1,0)
print(ans%MOD)
Buggy python submission (verdict: Runtime Error):
S=input()
for i in range(3):
  if s[i]==s[i+1]:
    print('Bad')
    exit(0)
print('Good')

Fixed submission:
S=input()
for i in range(3):
  if S[i]==S[i+1]:
    print('Bad')
    exit(0)
print('Good')
Buggy python submission (verdict: Runtime Error):
N,X=map(int,input().split())
L=list(map(int,input().split()))
x=0
ans=1
for l in L:
  x+=L
  if x>X:
    break
  ans+=1
print(ans)

Fixed submission:
N,X=map(int,input().split())
L=list(map(int,input().split()))
x=0
ans=1
for l in L:
  x+=l
  if x>X:
    break
  ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
now=0
MOD=10**9+7
p=[1,0]#0 humu  1 humazu
A=[int(input()) for i in range(M)]+[-1]
while now<N:
  if now==A[0]-1:
    p=[0,p[0]]
    A=A[1:]
  else:
    p=[(p[0]+p[1])%MOD, p[0]%MOD]
  now+=1
print(p[0]%MOD)

Fixed submission:
N,M=map(int,input().split())
now=0
a=0
MOD=10**9+7
p=[1,0]#0 humu  1 humazu
A=[int(input()) for i in range(M)]+[-1]
while now<N:
  if now==A[a]-1:
    p=[0,p[0]]
    a+=1
  else:
    p=[(p[0]+p[1])%MOD, p[0]%MOD]
  now+=1
print(p[0]%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
now=0
MOD=10**9+7
p=[1,0]#0 humu  1 humazu
A=[int(input()) for i in range(M)]+[-1]
while now<N:
  if now==A[0]-1:
    p=[0,p[0]]
    A=A[1:]
  else:
    p=[p[0]+p[1], p[0]]
  now+=1
print(p[0]%MOD)

Fixed submission:
N,M=map(int,input().split())
now=0
a=0
MOD=10**9+7
p=[1,0]#0 humu  1 humazu
A=[int(input()) for i in range(M)]+[-1]
while now<N:
  if now==A[a]-1:
    p=[0,p[0]]
    a+=1
  else:
    p=[(p[0]+p[1])%MOD, p[0]%MOD]
  now+=1
print(p[0]%MOD)
Buggy python submission (verdict: Runtime Error):
r,D,x=map(int,input().split())
for i in range(10):
   x=r*x-D
    print(x)

Fixed submission:
r,D,x=map(int,input().split())
for i in range(10):
  x=r*x-D
  print(x)
Buggy python submission (verdict: Time Limit Exceeded):
N,M,K=map(int,input().split())
import math
def com(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
A=com(M*N-2, K-2)
MOD=10**9+7
ans=0
for d in range(1,N):
  ans+=d*(N-d)*M*M*A%MOD
for d in range(1,M):
  ans+=d*(M-d)*N*N*A%MOD
print(ans%MOD)

Fixed submission:
N,M,K=map(int,input().split())
def cmb(x,y):
  X=1
  Y=1
  for i in range(1,y+1):
    X= X*(x+1-i)%MOD
    Y= Y*i%MOD
  return (X*pow(Y,MOD-2,MOD))%MOD
MOD=10**9+7
A=cmb(M*N-2, K-2)
ans=0
for d in range(1,N):
  ans+=d*(N-d)*M*M*A%MOD
for d in range(1,M):
  ans+=d*(M-d)*N*N*A%MOD
print(ans%MOD)
Buggy python submission (verdict: Runtime Error):
d={'A':'a','B':'b','C':'c'}
N,K=map(input().split())
S=input()
print(S[:K-1]+d[S[K-1]]+S[K:])

Fixed submission:
d={'A':'a','B':'b','C':'c'}
N,K=map(int,input().split())
S=input()
print(S[:K-1]+d[S[K-1]]+S[K:])
Buggy python submission (verdict: Runtime Error):
a=int(input())
for i in range(3):
  input()
e=int(input())
k=int(input())
if e-a<=K:
  print('Yay!')
else:
  print(':(')

Fixed submission:
a=int(input())
for i in range(3):
  z=input()
e=int(input())
k=int(input())
if e-a<=k:
  print('Yay!')
else:
  print(':(')
Buggy python submission (verdict: Runtime Error):
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
if sum(L[:-1])>L:
  print('Yes')
else:
  print('No')

Fixed submission:
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
if sum(L[:-1])>L[-1]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
D=int(input())
if D=25:
  a='Christmas'
elif D=24:
  a='Christmas Eve'
elif D=23:
  a='Christmas Eve Eve'
else:
  a='Christmas Eve Eve Eve'
print(a)

Fixed submission:
D=int(input())
if D==25:
  a='Christmas'
elif D==24:
  a='Christmas Eve'
elif D==23:
  a='Christmas Eve Eve'
else:
  a='Christmas Eve Eve Eve'
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
if K%2==1:
  print((N//K)**3)
else:
  k=K//2
  ans=0
  for a in range(k,N+1,k):
    for b in range(a,N+1,k):
      for c in range(b,N+1,k):
        if (a+b)%K==0 and (b+c)%K==0 and (c+a)%K==0:
          if a==b==c:
            ans+=1
          elif a==b or b==c or c==a:
            ans+=3
          else:
            ans+=6
  print(ans)

Fixed submission:
N,K=map(int,input().split())
if K%2==1:
  print((N//K)**3)
else:
  k=K//2
  print((N//K)**3+((N-k)//K+1)**3)
Buggy python submission (verdict: Runtime Error):
a,b=imput().split()
a=int(a+b)
for i in range(1,320):
  if i**2==a:
    print('Yes')
    exit(0)
print('No')

Fixed submission:
a,b=input().split()
a=int(a+b)
for i in range(1,320):
  if i**2==a:
    print('Yes')
    exit(0)
print('No')
Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split())
ans=0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if x+y+z == S:
                ans+=1
print(ans)

Fixed submission:
K,S = map(int,input().split())
ans=0
for x in range(K+1):
    for y in range(K+1):
        ans+=1 if K>=S-(x+y)>=0 else 0
print(ans)
Buggy python submission (verdict: Runtime Error):
cnt = 0
ans = False
for i in range(n):
    a,b = dd[i]
    if a == b:
        cnt += 1
    else:
        cnt = 0
    if cnt >= 3:
        ans = True
if ans:
    print('Yes')
else:
    print('No')

Fixed submission:
(n,), *dd = [list(map(int, s.split())) for s in open(0)]

cnt = 0
ans = False
for i in range(n):
    a,b = dd[i]
    if a == b:
        cnt += 1
    else:
        cnt = 0
    if cnt >= 3:
        ans = True
if ans:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
from math import comb
MOD = 10**9+7
n = int(input())
mdiv = n // 3

ans = 0
for i in range(mdiv):
    ans += comb(n - 3 * (i + 1) + i, i)

print(ans % MOD)

Fixed submission:
from math import comb
MOD = 10**9+7
n = int(input())
mdiv = n // 3

ans = 0
for i in range(mdiv):
    ans += comb(n - 3 * (i + 1) + i, i)

print(ans % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
(n,m),*ab = [list(map(int, s.split())) for s in open(0)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

u = UnionFind(n)

for a,b in ab:
    u.union(a-1,b-1)

print(max(map(len, u.all_group_members().values())))

Fixed submission:
n,m = list(map(int, input().split()))

class UnionFind:
    def __init__(self, n=0):
        self.d = [-1]*n

    def root(self, x):
        if self.d[x] < 0:
            return x
        self.d[x] = self.root(self.d[x])
        return self.d[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return False
        if x > y:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def size(self, x):
        return -self.d[self.root(x)]

u = UnionFind(n)

for _ in range(m):
    a,b = map(int, input().split())
    u.unite(a-1,b-1)

print(-min(u.d))
Buggy python submission (verdict: Runtime Error):
from collections import deque

(d,), cc, *sstt = [list(map(int, s.split())) for s in open(0)]

ss = sstt[:d]

tt = sum(sstt[d:], [])

print(sum(ss[i][t] for (i, t) in enumerate(tt)))

Fixed submission:
(d,), cc, *sstt = [list(map(int, s.split())) for s in open(0)]

ss = sstt[:d]

tt = list(map(lambda x: x-1, sum(sstt[d:], [])))

comp = [0]*len(cc)

ans = 0

for i in range(d):
    comp = [sum(x) for x in zip(comp, cc)]
    t = tt[i]
    ans += ss[i][t]
    comp[t] = 0
    ans -= sum(comp)
    print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque

(n, m, k), aa, bb = [deque(map(int, l.split())) for l in open(0)]

i = 0

while k - min(aa[0], bb[0])>0:
    if aa[0]>bb[0]:
        k -= bb.popleft()
        i+=1
    else:
        k -= aa.popleft()
        i+=1

print(i)

Fixed submission:
from collections import deque

(n, m, k), aa, bb = [list(map(int, l.split())) for l in open(0)]

from itertools import accumulate

aaa = list(zip(list(accumulate([0]+aa)), range(len(aa)+1)))
bbb = list(zip(list(accumulate([0]+bb)), range(len(bb)+1)))

i = 0
j = len(bb)

ans = 0

while i<len(aaa) and j >= 0:
    aco, abo = aaa[i]
    bco, bbo = bbb[j]
    if aco+bco > k:
        j -= 1
        continue
    else:
        ans = max(abo+bbo, ans)
        i += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

aa = map(int, input().split())

old = aa

for _ in range(k):
    new = [0] * n
    for i, a in enumerate(old):
        low = max(0, i-a)
        hi = min(n-1, i+a)+1
        for j in range(low, hi):
            new[j] += 1
    old = new

new = list(map(str, new))

print(' '.join(new))

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

aa = list(map(int, input().split()))

from itertools import accumulate

aa

for _ in range(k):
    d = [0] * n

    for i, a in enumerate(aa):
        d[max(i-a, 0)] += 1
        end = i+1+a
        if end < n:
            d[end] -= 1

    d = list(accumulate(d))
    if aa == d:
        break
    aa = d


print(' '.join(str(a) for a in aa))
Buggy python submission (verdict: Runtime Error):
import numpy as np

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



caa = [np.array(list(map(int, input().split()))) for _ in range(n)]



ans = 1 << 31

for i in range(2**n):
    tmp = np.zeros(4)
    for j in range(n):
        if i % (2**j):
            tmp += caa[j]
        if min(tmp[1:]) >= x:
            ans = min(ans, tmp[0])

if ans != 1<<31:
    print(int(ans))
else:
    print(-1)

Fixed submission:
*o, = open(0)

import numpy as np

(n, m, x), *ca = map(lambda x: np.array(list(map(int, x.split()))), o)

INF = 1 << 31

ans = INF

for i in range(2**n):
    tmp = np.zeros(m+1, int)
    sel = []
    for j, dig in enumerate(bin(i)[2:][::-1]):
        if int(dig):
            tmp += ca[j]
            sel.append(j)
    if min(tmp[1:]) >= x:
        ans = min(ans, tmp[0])
        

if ans == INF:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
# from math import factorial
from sys import exit
n,m,k = map(int, input().split())
if m == 1:
    if k == n-1:
        print(1)
    else:
        print(0)
    exit()
MOD = 998244353

ans = tmp = (m * (m-1) ** (n-1)) % MOD

for i in range(k):
    tmp *= (n-1-i)
    tmp %= MOD
    tmp *= pow((m-1) * (i+1), -1, MOD)
    ans += tmp
    ans %= MOD

print(ans)

Fixed submission:
# from math import factorial
from sys import exit
n,m,k = map(int, input().split())
if m == 1:
    if k == n-1:
        print(1)
    else:
        print(0)
    exit()
MOD = 998244353

ans = tmp = (m * (m-1) ** (n-1)) % MOD

for i in range(k):
    tmp *= (n-1-i)
    tmp %= MOD
    tmp *= pow((m-1) * (i+1), -1, MOD)
    ans += tmp
    ans %= MOD

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# from math import factorial
from sys import exit
n,m,k = map(int, input().split())
if m == 1:
    if k == n-1:
        print(1)
    else:
        print(0)
    exit()
MOD = 998244353

ans = tmp = (m * (m-1) ** (n-1))
ans %= MOD

for i in range(k):
    tmp *= (n-1-i)
    tmp //= (m-1) * (i+1)
    ans += tmp
    ans %= MOD

print(ans)

Fixed submission:
# from math import factorial
from sys import exit
n,m,k = map(int, input().split())
if m == 1:
    if k == n-1:
        print(1)
    else:
        print(0)
    exit()
MOD = 998244353

ans = tmp = (m * (m-1) ** (n-1)) % MOD

for i in range(k):
    tmp *= (n-1-i)
    tmp %= MOD
    tmp *= pow((m-1) * (i+1), -1, MOD)
    ans += tmp
    ans %= MOD

print(ans)
Buggy python submission (verdict: Runtime Error):
m,n,*aa = open(0).read().split()
ans = m-sum(aa)
if ans<0:
  print(-1)
else:
  print(ans)

Fixed submission:
m,n,*aa = map(int, open(0).read().split())
ans = m-sum(aa)
if ans<0:
  print(-1)
else:
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())

def is_lun(n):
    d, m = divmod(n, 10)
    last = m
    while d:
        n = d
        d, m = divmod(n, 10)
        if abs(last - m) > 1:
            return False
        last = m
    return True

from sys import exit
ans = 1
cnt = 0
while 1:
    if is_lun(ans):
        cnt += 1
    if cnt == k:
        print(ans)
        exit()
    ans += 1

Fixed submission:
from collections import deque
d = deque(range(1,10))
k = int(input())

for _ in range(k):
    ans = d.popleft()
    mod = ans % 10
    if mod != 0:
        d.append(ans * 10 + mod - 1)
    d.append(ans * 10 + mod)
    if mod != 9:
        d.append(ans * 10 + mod + 1)

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np

card = np.array([list(map(int, input().split())) for i in range(3)])

n = int(input())

number = [int(input()) for i in range(n)]

hit = np.isin(card, number)

row = hit.all(axis=0).any()
col = hit.all(axis=1).any()

diag1 = hit[0][0] and hit[1][1] and hit[2][2]
diag2 = hit[0][2] and hit[1][1] and hit[2][0]

print('yes' if row or col or diag1 or diag2 else 'no')

Fixed submission:
import numpy as np

card = np.array([list(map(int, input().split())) for i in range(3)])

n = int(input())

number = [int(input()) for i in range(n)]

hit = np.vectorize(lambda x: x in number)(card)

row = hit.all(axis=0).any()
col = hit.all(axis=1).any()

diag1 = hit[0][0] and hit[1][1] and hit[2][2]
diag2 = hit[0][2] and hit[1][1] and hit[2][0]

print('Yes' if row or col or diag1 or diag2 else 'No')