Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03045 (python)

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

par=[i for i in range(n)]
size=[1]*n

def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def union(a,b):
  x=find(a)
  y=find(b)
  if x!=y:
    if size[x]<size[y]:
      par[x]=par[y]
      size[y]+=size[x]
    else: 
      par[y]=par[x]
      size[x]+=size[y]
  else:
    return

for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)


ans={find(i) for i in range(n)}

print(len(ans))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())

par=[i for i in range(n)]


def find(x):
  if par[x]==x:
    return par[x]
  else:
    par[x]=find(par[x])
    return par[x]


def union(x,y):
  fx=find(x)
  fy=find(y)
  if fx!=fy:
    par[fx]=fy


for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)

ans=0

for i in range(n):
    if i==find(i):
        ans+=1

print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())

par=[i for i in range(n)]

visited=[False]*n

def find(x):
  if par[x]==x:
    return par[x]
  else:
    par[x]=find(par[x])
    return par[x]


def find2(x):
  visited[x]=True
  if par[x]==x:
    return par[x]
  else:
    par[x]=find2(par[x])
    return par[x]

def union(x,y):
  fx=find(x)
  fy=find(y)
  if fx!=fy:
    par[fx]=fy

ans=-1

for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)

cnt=0

for i in range(n):
  if visited[i]==False:
    cnt+=1
    find2(i)


ans=min(cnt,len(set(par)))


print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())

par=[i for i in range(n)]

visited=[False]*n

def find(x):
  if par[x]==x:
    return par[x]
  else:
    par[x]=find(par[x])
    return par[x]


def find2(x):
  visited[x]=True
  if par[x]==x:
    return par[x]
  else:
    par[x]=find2(par[x])
    return par[x]

def union(x,y):
  fx=find(x)
  fy=find(y)
  if fx!=fy:
    par[fx]=fy

ans=-1

for i in range(m):
  x,y=map(int,input().split())
  union(x-1,y-1)

cnt=0

for i in range(n):
  if visited[i]==False:
    cnt+=1
    find2(i)


ans=min(cnt,len(set(par)))


print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())

par=[i for i in range(n)]

visited=[False]*n

def find(x):
  if par[x]==x:
    return par[x]
  else:
    par[x]=find(par[x])
    return par[x]


def union(x,y):
  fx=find(x)
  fy=find(y)
  if fx!=fy:
    par[fx]=fy

ans=-1

for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)


ans={find(i) for i in range(n)}

print(len(ans))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())

par=[i for i in range(n)]

visited=[False]*n

def find(x):
  if par[x]==x:
    return par[x]
  else:
    par[x]=find(par[x])
    return par[x]


def find2(x):
  visited[x]=True
  if par[x]==x:
    return par[x]
  else:
    par[x]=find2(par[x])
    return par[x]

def union(x,y):
  fx=find(x)
  fy=find(y)
  if fx!=fy:
    par[fx]=fy

ans=-1

for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)

ans=1

for i in range(n):
  if visited[i]==False:
    ans+=1
    find2(i)

print(min(ans,len(set(par))))
Problem p03075 (python)

Fixed submission:
a=[int(input()) for i in range(5)]
k=int(input())
x=max(a)-min(a)
if x<=k:
  print('Yay!')
else:
  print(':(')

Buggy submission (verdict: Runtime Error):
a=int(print())
b=int(print())
c=int(print())
d=int(print())
e=int(print())
k=int(print())

if (e-a)<=k:
  print('Yay!')

else:
  print(':(')

Buggy submission (verdict: Runtime Error):
a=int(print())
b=int(print())
c=int(print())
d=int(print())
e=int(print())
k=int(print())

x=[a,b,c,d,e]
y=max(x)-min(x)

if y>k:
  print(':(')
if y<=k:
  print('Yay!')

Buggy submission (verdict: Runtime Error):
a=int(print())
b=int(print())
c=int(print())
d=int(print())
e=int(print())
k=int(print())

x=[a,b,c,d,e]
y=max(x)-min(x)

if y>k:
  print(':(')
else:
  print('Yay!')

Buggy submission (verdict: Runtime Error):
a=int(print())
b=int(print())
c=int(print())
d=int(print())
e=int(print())
k=int(print())

x=[a,b,c,d,e]
y=max(x)-min(x)

if y>=k:
  print('Yay!')
else:
  print(':(')

Buggy submission (verdict: Runtime Error):
a=print()
b=print()
c=print()
d=print()
e=print()
k=print()

x=[a,b,c,d,e]
y=max(x)-min(x)

if y>=k:
  print('Yay!')
else:
  print(':(')
Problem p03127 (python)

Fixed submission:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
x=a[0]
for i in a:
  x=gcd(x,i)
print(x)

Buggy submission (verdict: Runtime Error):
from math import gcd
n=int(input())
a=list(map(int,input().split()))
x=a[0]
for i in a:
  x=gcd(x,i)
print(x)

Buggy submission (verdict: Runtime Error):
from math import gcd
n=int(input())
a=list(map(int,input().split()))
x=gcd(a[0],a[1])
for i in a:
  x=gcd(x,i)
print(x)
Problem p03137 (python)

Fixed submission:
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
y=[]
for i in range(len(x)-1):
  y+=[x[i+1]-x[i]]
y.sort()
if n>=m:
  print(0)
else:
  print(sum(y[:m-n]))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
x=list(map(int,input().split()))
count=0
a=max(x)
i=min(x)
if m<=2:
  print(count)
else:
  while True:
    x.pop(a)
    x.pop(b)
    a-=1
    b+=1
    count+=1
    if x==[]:
      print(count)
      break

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
x=list(map(int,input().split()))
count=0
a=max(x)
i=min(x)
if m<=2:
  print(count)
else:
  while True:
    x.remove(a)
    x.remove(b)
    a-=1
    b+=1
    count+=1
    if x==[]:
      print(count)
      break

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
x=list(map(int,input().split()))
count=0
a=max(x)
i=min(x)
if m<=2:
  print(count)
while True:
  x.remove(a)
  x.remove(b)
  a-=1
  b+=1
  count+=1
  if x==[]:
    print(count)
    break
Problem p03242 (python)

Fixed submission:
n=input()
n=n.replace('1','x')
n=n.replace('9','1')
n=n.replace('x','9')
print(n)

Buggy submission (verdict: Runtime Error):
n=input()
n.replace(1,x)
n.replace(9,1)
print(n.replace(x,9))
Problem p03426 (python)

Fixed submission:
h,w,d=map(int,input().split())
dict={}

for i in range(1,h+1):
  lst=list(map(int,input().split()))
  for j in range(w):
    dict.setdefault(lst[j],(i,j+1))

cost=[0]*(h*w)

for i in range(d,h*w):
  cost[i]=cost[i-d]+abs(dict[i-d+1][0]-dict[i+1][0])+abs(dict[i-d+1][1]-dict[i+1][1])


ans=0

q=int(input())
for i in range(q):
    ans=0
    l,r=map(int,input().split())
    print(cost[r-1]-cost[l-1])

Buggy submission (verdict: Runtime Error):
h,w,d=map(int,input().split())
dict={}

for i in range(1,h+1):
  lst=list(map(int,input().split()))
  for j in range(w):
    dict.setdefault(lst[j],(i,j+1))

cost=[0]*(h*w-d)

for i in range(d,h*w-d):
  cost[i]=cost[i-d]+abs(dict[i-d+1][0]-dict[i+1][0])+abs(dict[i-d+1][1]-dict[i+1][1])


ans=0

q=int(input())
for i in range(q):
    ans=0
    l,r=map(int,input().split())
    print(cost[r-1]-cost[l-1])
Problem p03631 (python)

Fixed submission:
n=input()
if n[0]==n[2]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n=input()
if n(0)==n(2):
  print('Yes')
else:
  print('No')
Problem p03745 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
x=[]
ans=1

for i in range(n-1):
  if a[i+1]==a[i]:
    continue
  x.append(a[i+1]-a[i])
  
flag=True

for i in range(len(x)-1):
  if flag==False:
    flag=True
    continue
  if x[i]<0 and x[i+1]>0 or x[i]>0 and x[i+1]<0:
    ans+=1
    flag=False
    

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
s=''
ans=1
for i in range(n-1):
  if a[i]<a[i+1]:
    s+='x'
  elif a[i]>a[i+1]:
    s+='y'
for i in range(len(s)):
  if s[i]!=s[i+1]:
    ans+=1
print(ans)
Problem p03803 (python)

Fixed submission:
a,b=map(int,input().split())
if a==b:
  print('Draw')
elif a==1:
  print('Alice')
elif b==1:
  print('Bob')
elif a>b:
  print('Alice')
elif a<b:
  print('Bob')

Buggy submission (verdict: Runtime Error):
a,b=map(int,input.split())
if a==b:
  print('Draw')
elif a==1:
  print('Alice')
elif b==1:
  print('Bob')
elif a>b:
  print('Alice')
elif a<b:
  print('Bob')

Buggy submission (verdict: Runtime Error):
a,b=map(int,input.split())
if a==b:
  print('Draw')
elif a==1:
  print('Alice')
elif b==1:
  print('Bob')
elif a>b:
  print('Alice')
else:
  print('Bob')
Problem p03804 (python)

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

x=[input() for i in range(n)]
y=[input() for i in range(m)]

ans='No'

for i in range(n-m+1):
  for j in range(n-m+1):
    maze=[]
    for k in range(m):
      pin=''
      for l in range(m):
        pin+=x[i+k][j+l]
      
      maze.append(pin)

    if maze==y:
      ans='Yes'
      break


print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
x=[[input()] for i in range(n)]
y=[[input()] for i in range(m)]

for i in range(n-m+1):
  for j in range(n-m+1):
    if x[i][j]==y[0][0]:
      if m==1:
        print('Yes')
        exit()
      for k in range(m):
        if x[i+k][j:j+n-m+1]!=y[k]:
          continue
          
        print('Yes')
        exit()
        
print('No')
Problem p03835 (python)

Fixed submission:
cnt=0
k,s=map(int,input().split())
for i in range(k+1):
    for j in range(k+1):
        if (0<=s-i-j<=k):
                cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
cnt=0
k,s=map(int,input().split())
for i in range(k+1):
    for j in range(k+1):
        if (0<=s-x-y<=k):
                cnt+=1
print(cnt)
Problem p02595 (python)

Fixed submission:
N, D = map(int, input().split())
ans = 0
D2 = D*D
for i in range(N):
    x, y = map(int, input().split())
    if (x*x+y*y) <= D2:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
N, D = map(int, input().split())
ans = 0
D2 = D*D
for i in range(N):
    x, y = map(int, input().split())
    if (x*x+y*y) <= D2:
        ans += 1

print(ans)
Problem p02597 (python)

Fixed submission:
N = int(input())
c = input().strip()
r = c.count("R")
ans = 0
for i in range(r):
    if c[i] == "W":
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
c = input().strip()
r = c.count("R")
ans = 0
for i in range(r):
    if c[i] == "W":
        ans += 1
print(ans)
Problem p02623 (python)

Fixed submission:
import bisect
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
for i in range(1, N):
    A[i] += A[i-1]
for i in range(1, M):
    B[i] += B[i-1]

A = [0]+A
ans = 0
for i in range(N+1):
    b = K-A[i]
    if b < 0:
        break
    j = bisect.bisect_right(B, b)
    if ans < (i+j):
        ans = i+j

print(ans)

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

for i in range(1, N):
    A[i] += A[i-1]
for i in range(1, M):
    B[i] += B[i-1]

A = [0]+A
B = [0]+B
a, b = 0, M
for i in range(N+1):
    k = K-A[i]
    if k < 0:
        break
    while b[j] > k:
        j -= 1
    ans = max(ans, i+j)

print(ans)
Problem p02757 (python)

Fixed submission:
from fractions import gcd

N, P = map(int, input().split())
S = input().strip()

if gcd(10, P) > 1:
    ans = 0
    for i in range(len(S)):
        s = int(S[i])
        if s % P == 0:
            ans += (i+1)
    print(ans)
else:
    p = [0]*P
    ans = 0
    s = 0
    for i in range(len(S)-1, -1, -1):
        s = (s + int(S[i])*pow(10, N-1-i, P)) % P
        m = s % P
        if m == 0:
            p[m] += 1
            ans += p[m]
        else:
            ans += p[m]
            p[m] += 1

    print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from math import gcd

N, P = map(int, input().split())
S = input().strip()

if gcd(10, P) > 1:
    ans = 0
    for i in range(len(S)):
        s = int(S[i])
        if s % P == 0:
            ans += (i+1)
    print(ans)
else:
    h = defaultdict(int)
    ans = 0
    for i in range(len(S)-1, -1, -1):
        s = int(S[i:])
        m = s % P
        if m == 0:
            h[m] += 1
            ans += h[m]
        else:
            ans += h[m]
            h[m] += 1

    print(ans)
Problem p02781 (python)

Fixed submission:
# 0でない数字がちょうどK個
S = input().strip()
K = int(input())
N = len(S)

'''
桁DP
dp[i][j][k] := 
i桁目まで使って
j個の0ではない数値を使って
k=0:i桁目までSと一致
  1:S未満(以下？)
'''
dp = [[[0]*2 for _ in range(K+1)] for _ in range(101)]
dp[0][0][0] = 1

for i in range(N):
    for j in range(K+1):
        for k in range(2):
            nd = int(S[i])
            # 0-9まで調べていく
            for d in range(10):
                ni, nj, nk = i+1, j, k
                if d > 0:
                    nj += 1
                if nj > K:
                    continue
                if k == 0:
                    if d > nd:
                        continue
                    elif d != nd:
                        nk = 1
                dp[ni][nj][nk] += dp[i][j][k]

print(sum(dp[N][K]))

Buggy submission (verdict: Runtime Error):
from math import factorial

N = int(input())
K = int(input())


def ncr(n, r):
    if n <= 0:
        return 0
    return factorial(n) // factorial(r) // factorial(n - r)


def k1(n):
    s = str(n)
    return (len(s) - 1) * 9 + int(s[0])


def k2(n):
    if n < 10:
        return 0
    s = str(n)
    res = ncr(len(s)-1, 2) * 9 * 9
    res += (int(s[0]) - 1) * k1(10 ** (len(s) - 1) - 1) + k1(int(s[1:]))
    return res


def k3(n):
    s = str(n)
    res = ncr(len(s)-1, 3)*9*9*9
    res += (int(s[0]) - 1) * k2(10 ** (len(s) - 1) - 1) + k2(int(s[1:]))
    return res


kf = [k1, k2, k3]
print(kf[K-1](N))

Buggy submission (verdict: Runtime Error):
from math import factorial

N = int(input())
K = int(input())


def ncr(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)


def k1(n):
    s = str(n)
    return (len(s) - 1) * 9 + int(s[0])


def k2(n):
    if n < 10:
        return 0
    s = str(n)
    res = ncr(len(s)-1, 2) * 9 * 9
    res += (int(s[0]) - 1) * k1(10 ** (len(s) - 1) - 1) + k1(int(s[1:]))
    return res


def k3(n):
    s = str(n)
    res = ncr(len(s)-1, 3)*9*9*9
    res += (int(s[0]) - 1) * k2(10 ** (len(s) - 1) - 1) + k2(int(s[1:]))
    return res


kf = [k1, k2, k3]
print(kf[K-1](N))
Problem p02990 (python)

Fixed submission:
from operator import mul
from functools import reduce


def cmb(n, r):
    if r > n:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


N, K = map(int, input().split())
R = N-K

for i in range(K):
    a = cmb(K-1, i)
    b = cmb(R+1, i+1)
    print((a*b) % (10**9+7))

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


N, K = map(int, input().split())
R = N-K

for i in range(K):
    a = cmb(K-1, i)
    b = cmb(R+1, i+1)
    print((a*b) % (10**9+7))
Problem p03038 (python)

Fixed submission:
N, M = map(int, input().split())
*A, = map(int, input().split())
BC = [list(map(int, input().split())) for _ in range(M)]
A.sort()
BC.sort(key=lambda v: -v[1])

ai = 0
for b, c in BC:
    while b > 0 and ai < N and A[ai] < c:
        A[ai] = c
        b -= 1
        ai += 1

print(sum(A))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
*A, = map(int, input().split())
BC = [list(map(int, input().split())) for _ in range(M)]
A.sort()
BC.sort(key=lambda v: -v[1])

ai = 0
for b, c in BC:
    while b > 0 and A[ai] < c:
        A[ai] = c
        b -= 1
        ai += 1

print(sum(A))
Problem p03045 (python)

Fixed submission:
from collections import defaultdict


class UnionFindTree:
    def __init__(self):
        self.p = {}
        self.rank = {}

    def make(self, x):
        self.p[x] = x
        self.rank[x] = 0

    def find(self, x):
        if x in self.p:
            if self.p[x] != x:
                # 経路圧縮
                self.p[x] = self.find(self.p[x])
            return self.p[x]
        return None

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

    def unite(self, x, y):
        return self._unite(self.find(x), self.find(y))

    def _unite(self, x, y):
        if self.rank[x] < self.rank[y]:
            self.p[x] = y
            return y
        else:
            self.p[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            return x


utf = UnionFindTree()

N, M = map(int, input().split())
for n in range(N):
    utf.make(n + 1)

for m in range(M):
    x, y, z = map(int, input().split())
    utf.unite(x, y)

h = defaultdict(int)
for n in range(N):
    x = utf.find(n + 1)
    h[x] += 1

ans = 0
rest = N
for k, v in h.items():
    ans += 1
    rest -= v
print(ans + rest)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
h = {}
c = {}
for i in range(N):
    h[i + 1] = []
    c[i + 1] = 0

for m in range(M):
    x, y, z = map(int, input().split())
    h[x].append(y)
    h[y].append(x)

ans = 0
rest = N

while len(h) > 0:
    p = max([[len(v), k] for k, v in h.items()])
    if p[0] == 0:
        break
    rest = rest - p[0] - 1
    for n in h[p[1]]:
        del h[n]
    del h[p[1]]
    ans += 1

print(ans + rest)
Problem p02557 (python)

Fixed submission:
def solve(n):
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))[::-1]
    ind = [-1] * (n + 1)
    for i in range(n):
        if i == 0:
            ind[b[i]] = 0
        elif b[i] != b[i - 1]:
            ind[b[i]] = i
    cnt = 0
    for i in range(n):
        if a[i] != b[i]:
            continue
        else:
            swap = 0
            for j in range(b[i] - 1, 0, -1):
                if ind[j] != -1 or ind[j] >= ind[j - 1]:
                    swap = ind[j]
                    ind[j] += 1
                    break
            if n <= swap:
                swap = cnt
                cnt += 1
                cnt %= n
            b[i], b[swap] = b[swap], b[i]
    return a, b


def main():
    n = int(input())
    a, b = solve(n)
    if all(a[i] != b[i] for i in range(n)):
        print("Yes")
        print(" ".join(map(str, b)))
    else:
        print("No")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))[::-1]
    ind = [-1] * (n + 1)
    for i in range(n):
        if i == 0:
            ind[b[i]] = 0
        elif b[i] != b[i - 1]:
            ind[b[i]] = i
    for i in range(n):
        if a[i] != b[i]:
            continue
        else:
            swap = 0
            for j in range(b[i] - 1, 0, -1):
                if ind[j] != -1 or ind[j] >= ind[j - 1]:
                    swap = ind[j]
                    ind[j] += 1
                    break
            b[i], b[swap] = b[swap], b[i]
    if all(a[i] != b[i] for i in range(n)):
        print("Yes")
        print(" ".join(map(str, b)))
    else:
        print("No")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))[::-1]
    ind = [-1] * (n + 1)
    for i in range(n):
        if i == 0:
            ind[b[i]] = 0
        elif b[i] != b[i - 1]:
            ind[b[i]] = i
    for i in range(n):
        if a[i] != b[i]:
            continue
        elif i < n - 1:
            swap = 0
            for j in range(b[i] - 1, 0, -1):
                if ind[j] != -1:
                    swap = ind[j]
                    ind[j] += 1
                    break
            b[i], b[swap] = b[swap], b[i]
    if all(a[i] != b[i] for i in range(n)):
        print("Yes")
        print(" ".join(map(str, b)))
    else:
        print("No")


if __name__ == '__main__':
    main()
Problem p02623 (python)

Fixed submission:
from bisect import bisect_right


def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    answer = 0
    is_changed = False
    if a[0] <= k or b[0] <= k:
        answer = 1
    elif a[0] + b[0] <= k:
        answer = 2
    for i in range(1, n):
        a[i] += a[i - 1]
        if k < a[i] and not is_changed:
            answer = i
            is_changed = True
    if a[-1] <= k:
        answer = n
    is_changed = False
    for i in range(1, m):
        b[i] += b[i - 1]
        if k < b[i] and not is_changed:
            answer = max(answer, i)
            is_changed = True
    if b[-1] <= k:
        answer = max(answer, m)
    if a[-1] + b[-1] <= k:
        answer = n + m
    elif all(k < x for x in [a[0], b[0], a[0] + b[0]]):
        answer = 0
    else:
        for i in range(n):
            l = bisect_right(b, k - a[i])
            if l == 0 or (l == m and b[l - 1] + a[i] > k):
                continue
            answer = max(answer, i + 1 + l)
    print(answer)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from bisect import bisect_right


def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    for i in range(1, n):
        a[i] += a[i - 1]
    for i in range(1, m):
        b[i] += b[i - 1]
    answer = 0
    if a[-1] + b[-1] <= k:
        print(n + m)
    else:
        for i in range(n):
            l = bisect_right(b, k - a[i])
            if l == 0 or (l == m and b[l] + a[i] != k):
                continue
            answer = max(answer, i + 1 + l)
        print(answer)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left


def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    for i in range(1, n):
        a[i] += a[i - 1]
    for i in range(1, m):
        b[i] += b[i - 1]
    answer = 0
    if a[-1] + b[-1] <= k:
        print(n + m)
    else:
        for i in range(n):
            l = bisect_left(b, k - a[i])
            diff = 1 if b[l] == k - a[i] else 0
            answer = max(answer, i + 1 + l + diff)
        print(answer)


if __name__ == '__main__':
    main()
Problem p02685 (python)

Fixed submission:
def comb(n, k, nk, mod):
    return (n * pow(k * nk, mod - 2, mod)) % mod


def main():
    n, m, k = map(int, input().split())
    mod = 998244353
    ans = 0
    base = pow(m - 1, n - 1 - k, mod)
    fact = [1 for _ in range(n + 1)]
    for i in range(1, n + 1):
        fact[i] = fact[i - 1] * i
        fact[i] %= mod
    for i in range(k, -1, -1):
        ans += base * comb(fact[n - 1], fact[i], fact[n - i - 1], mod)
        ans %= mod
        base *= m - 1
        base %= mod
    ans *= m
    ans %= mod
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def comb(n, k, mod=10 ** 9 + 7):
    denominator = 1
    numerator = 1
    for i in range(1, k + 1):
        denominator = denominator * i % mod
    for i in range(n - k + 1, n + 1):
        numerator = numerator * i % mod
    return numerator * pow(denominator, mod - 2, mod) % mod


def main():
    n, m, k = map(int, input().split())
    mod = 998244353
    ans = 0
    for i in range(k + 1, -1, -1):
        ans += m * pow(m - 1, n - 1 - i, mod) * comb(n - 1, i, mod)
        ans %= mod
    print(ans)


if __name__ == '__main__':
    main()
Problem p02819 (python)

Fixed submission:
def main():
    X = int(input())
    i = 2
    while i ** 2 <= X:
        if X % i == 0:
            X += 1
            i = 2
        else:
            i += 1
    print(X)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from sympy import sieve


def main():
    number = int(input())
    isPrime = False
    while not isPrime:
        isPrime = (number in sieve) == True
        if not isPrime:
            number += 1
    print(number)


if __name__ == '__main__':
    main()