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

Fixed submission:
from sys import stdin, stdout
from collections import defaultdict

def main():
    n = int(stdin.readline())
    a = list(map(int,stdin.readline().split()))
    f = 1
    flag=0
    a = sorted(a)
    for i in range(n):
        f = f*a[i]
        if f>10**18:
            flag=1
            break
    if flag:
        print("-1")
    else:
        print(f)

main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(stdin.readline())
    a = list(map(int,stdin.readline().split()))
    f = 1
    flag=0
    a = sorted(a)
    for i in range(n):
        f = f*a[i]
        if f>10**18:
            flag=1
            break
    if flag:
        print("-1")
    else:
        print(f)

main()
Problem p02681 (python)

Fixed submission:
s =input()
t =input()
f=0
for i in range(len(s)):
	if s[i]!=t[i]:
		f=1
		break
if f==1:
	print("No")
else:
	print("Yes")

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
for i in range(len(s)-1):
  if s[i]!=t[i]:
    f =1
if f==1:
  print("No")
else:
  print("yes")
Problem p02837 (python)

Fixed submission:
n=int(input())
a=[[]] * n
x=[[]] * n
y=[[]] * n
for i in range(n):
  a[i]=int(input())
  x[i]=[[]] * a[i]
  y[i]=[[]] * a[i]
  for j in range(a[i]):
    x[i][j],y[i][j]=map(int,input().split())

com=[[0 for i in range(n) ] for j in range(2**n)]

for i in range(2**n):
  for j in range(n):
    if ((i >> j) & 1) == 1:
      com[i][j]=1
  #正直者の証言が全て合っているか。
  for j in range(n):
    if com[i][j]==1:
      for k in range(a[j]):
        if y[j][k]!=com[i][x[j][k]-1]:
          com[i]=[0 for l in range(n) ]
          break
sum=[sum(com[i]) for i in range(2**n) ]
print(max(sum))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[[]] * n
x=[[]] * n
y=[[]] * n
for i in range(n):
  a[i]=int(input())
  x[i]=[[]] * a[i]
  y[i]=[[]] * a[i]
  for j in range(a[i]):
    x[i][j],y[i][j]=map(int,input().split())
def eva(o,p,q):
  for i in range(a[p]):
    if x[p][i]-1==q:
      return(y[p][i])
  for i in range(a[p]):
    if x[p][i]-1==o:
      return(1)
  for i in range(a[p]):     
    if y[p][i]==1:     
      return(eva(o,x[p][i]-1,q))
  return(1)
def test(p,q):
  return(eva(p,p,q)*eva(q,q,p))

ans=[[[] for i in range(n) ] for j in range(n)]
for i in range(n):
  for j in range(n):
    ans[i][j]=test(i,j)

b=[sum(ans[i])for i in range(n)]

sum=0
for i in range(n):
  if max(b)==0:
    break
  c=b.index(max(b))
  for j in range(n):
    if ans[c][j]==0:
      b[j]=0
  b[c]=0
  sum+=1
print(sum)
Problem p02838 (python)

Fixed submission:
import math
n=int(input())
al=list(map(int,input().split()))
a=['{:060b}'.format(x) for x in al]
a=''.join(a)

m=math.ceil(math.log(max(1,max(al)),2))

ans=0
for i in range(m):
  sum1=a[59-i::60].count('1')
  sum0=n-sum1
  ans+=2**i*sum1*sum0

print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
a=list(map(int,input().split()))
m=math.ceil(math.log(max(a),2))

ans=0
for i in range(m):
  sum0=0
  sum1=0
  for j in range(n):
    if (a[j]>>i)&1:
      sum1+=1
    else:
      sum0+=1
  ans+=2**i*sum1*sum0
print(ans%(10**9+7))
Problem p02742 (python)

Fixed submission:
H, W = list(map(int, input().split()))
if H == 1 or W == 1:
    print(1)
else:
    print(H*W//2 + (H*W)%2)

Buggy submission (verdict: Runtime Error):
H, W = list(map(input().split()))

print(H*W//2 + (H * W) % 2)
Problem p03501 (python)

Fixed submission:
list = [int(i) for i in input().split()]

fee = list[0] * list[1]

print(min(fee, list[2]))

Buggy submission (verdict: Runtime Error):
list = [int(i) for i in input().split()]

fee = list[0] * list[1]

print(min(fee, list[2])
Problem p02823 (python)

Fixed submission:
N, A, B = map(int, input().split())
dif = abs(A - B)
ans = 0

if dif % 2 == 0:
    ans = dif // 2
else:
    ans = min(A - 1, N - B) + 1 + dif // 2
print(ans)

Buggy submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
table = list(range(1, N + 1))
if A < B:
    dif = B - A
else:
    dif = A - B
if dif % 2 == 0:
    ans = int(dif / 2)
else:
    a = [abs(table[0] - table[A - 1]), abs(table[-1] - table[A - 1]), abs(table[0] - table[B - 1]), abs(table[-1] - table[B - 1])]
    a = sorted(a)
    ans = a[0] + (a[1] - a[0])
print(ans)
Problem p02922 (python)

Fixed submission:
import math
a, b = map(int, input().split())
print(math.ceil((b - 1) / (a - 1)))

Buggy submission (verdict: Runtime Error):
import math
a, b = map(int, input().split)
print(math.ceil((b-1)/(a-1)))
Problem p02639 (python)

Fixed submission:
x = [int(i) for i in input().split()]
print(x.index(0)+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [int(i) for i in input().split()]
l = 0
for i in range(n):
  for j in range(n):
    if (s[i] == s[j] or s[i]%s[j] == 0) and (i != j):
      l += 1
      break
print(len(s)-l)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [int(i) for i in input().split()]
s = set(s)
for i in s:
	for j in s:
		if i == j or i%j == 0:
			s.remove(i)
			s.add(-i)
			break
l = [i for i in s if i >= 0]
print(len(l))
Problem p02646 (python)

Fixed submission:
a, v = [int(i) for i in input().split()]
b, w = [int(i) for i in input().split()]
t = int(input())
if a<b:
  print("YES") if a+(v*t) >= b+(w*t) else print("NO")
else:
  print("YES") if a-(v*t) <= b-(w*t) else print("NO")

Buggy submission (verdict: Runtime Error):
a, v = [int(i) for i in input().split()]
b, w = [int(i) for i in input().split()]
t = int(input())
print("YES") if a+(v*t) >= b+(w*) or a >= b else print("NO")
Problem p02694 (python)

Fixed submission:
from math import floor
x=int(input())
p=100
r=0.01

for i in range(1,3760+1):
    c=floor(p*(1.01)**1)
    if c<x:
        p+=c-p
    else:
        break
print(i)

Buggy submission (verdict: Runtime Error):
from math import log,ceil
x=int(input())
p=100
r=0.01

for i in range(1,3760+1):
    c=floor(p*(1.01)**1)
    if c<x:
        p+=c-p
    else:
        break
print(i)
Problem p02640 (python)

Fixed submission:
x, y = map(int,input().split())

if (y-2*x)%2!=0:
  print("No")
else:
  k = (y-2*x)//2
  t = x-k

  if 0 <= k and 0 <= t:
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
x, y = map(int,input().split())

if (y-2*x)%2==0:
  k = (y-2*x)//2
  t = x-k
else:
  print("No")

if 0 <= k and 0 <= t:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
x, y = map(int,input().split())

if (y-2*x)%2==0:
  k = (y-2*x)//2
  t = x-k

if 0 <= k and 0 <= t:
  print("Yes")
else:
  print("No")
Problem p02658 (python)

Fixed submission:
import math

n = int(input())
a = list(map(int,input().split()))

flag_zero = 0
sum = 0
for i in range(n):
  if a[i]==0:
    flag_zero = 1
  else:
    sum += math.log10(a[i])

if flag_zero == 1:
  print(0)
elif sum > 18:
  print(-1)
else:
  sum = 1
  for i in range(n):
    sum *= a[i]
  if sum > 10**18:
    print(-1)
  else:
    print(sum)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
a = list(map(int,input().split()))

sum = 0
for i in range(n):
  sum += math.log10(a[i])

if sum >= 18:
  print(-1)
else:
  sum = 1
  for i in range(n):
    sum *= a[i]
  print(sum)
Problem p02706 (python)

Fixed submission:
n, m = map( int, input().split() )
a = list(map(int,input().split()))
sum=0
for i in range(m):
  sum+=a[i]

n=n-sum
if n<=-2:
  n=-1

print(n)

Buggy submission (verdict: Runtime Error):
m, n = map( int, input().split() )
a = 0
for i in range(m)
	a += int(input())

n=n-a
if a<=-2:
  a=-1

print(a)
Problem p03292 (python)

Fixed submission:
a = input().split()

if int(a[0])<=int(a[1]) and int(a[0])<=int(a[2]):
  min = int(a[0])
  if int(a[1])<=int(a[2]):
    max = int(a[2])
  else:
    max = int(a[1])
elif int(a[1])<=int(a[2]) and int(a[1])<=int(a[0]):
  min = int(a[1])
  if int(a[0])<=int(a[2]):
    max = int(a[2])
  else:
    max = int(a[0])
else:
  min = int(a[2])
  if int(a[0])<=int(a[1]):
    max = int(a[1])
  else:
    max = int(a[0])

print(max-min)

Buggy submission (verdict: Runtime Error):
a = input().split()

if int(a[0])<=int(a[1]) and int(a[0])<=int(a[2]):
  min = int(a[0])
  if int(a[1])<=int(a[2]):
    max = int(a[2])
  else:
    max = int(a[1])
elif int(a[1])<=int(a[2]) and int(a[1])<=int(a[0]):
  min = int([1])
  if int(a[0])<=int(a[2]):
    max = int(a[2])
  else:
    max = int(a[0])
else:
  min = int(a[2])
  if int(a[0])<=int(a[1]):
    max = int(a[1])
  else:
    max = int(a[0])

print(max-min)

Buggy submission (verdict: Runtime Error):
a = input().split()

if int(a[0])<=int(a[1]) and int(a[0])<=int(a[2]):
  min = int(a[0])
  if int(a[1])<=int(a[2]):
    max = int(a[2])
  else:
    max = int(a[1])
elif int(a[1])<=int(a[2]) and int(a[1])<=int(a[0]):
  min = aint([1])
  if int(a[0])<=int(a[2]):
    max = int(a[2])
  else:
    max = int(a[0])
else:
  min = int(a[2])
  if int(a[0])<=int(a[1]):
    max = int(a[1])
  else:
    max = int(a[0])

print(max-min)

Buggy submission (verdict: Runtime Error):
a = input().split()

if int(a[0])<=int(a[1]) and int(a[0])<=int(a[2]):
  min = a[0]
  if int(a[1])<=int(a[2]):
    max = int(a[2])
  else:
    max = int(a[1])
elif int(a[1])<=int(a[2]) and int(a[1])<=int(a[0]):
  min = a[1]
  if int(a[0])<=int(a[2]):
    max = int(a[2])
  ele:
    max = int(a[0])
else:
  min = a[2]
  if int(a[0])<=int(a[1]):
    max = int(a[1])
  ele:
    max = int(a[0])

print(max-min)
Problem p03434 (python)

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

card.sort(reverse=True)

asum = 0
bsum = 0
for i in range(n):
  if i%2==0:
    asum += card[i]
  else:
    bsum += card[i]

print(asum-bsum)

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

card.sort()

ans = 0
for i in range(n//2+1):
            ans += card[2*i]-card[2*i+1]
if n%2==1:
            ans += card[-1]

print(ans)

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

card.sort()

for i in range(n//2):
            ans += card[2*i]-card[2*i+1]
if n%2==1:
            ans += card[-1]

print(ans)
Problem p03854 (python)

Fixed submission:
s = input()

flag = 0
while s != []:
  ss=s
  if s=='erase':
    s = []
  elif len(s)>5 and s[0:6]=='erasee':
    s = s[5:]
  elif len(s)>5 and s[0:6]=='erased':
    s = s[5:]
  elif s=='eraser':
    s = []
  elif len(s)>6 and s[0:7]=='erasere':
    s = s[6:]
  elif len(s)>6 and s[0:7]=='eraserd':
    s = s[6:]
  elif s=='dreamer':
    s = []
  elif len(s)>7 and s[0:8]=='dreamere':
    s = s[7:]
  elif len(s)>7 and s[0:8]=='dreamerd':
    s = s[7:]
  elif s=='dream':
    s = []
  elif len(s)>5 and s[0:6]=='dreamd':
    s = s[5:]
  elif len(s)>5 and s[0:6]=='dreame':
    s = s[5:]

  if ss==s:
    flag=1
    break

if flag==0:
  print("YES")
else:
  print("NO")
    
# dream dreamer erase eraser

Buggy submission (verdict: Runtime Error):
s = input()

while s != []:
  if s=='erase':
    s = s[]
  elif len(s)>5 and s[0:5]=='erasee':
    s = s[5:]
  elif len(s)>5 and s[0:5]=='erased':
    s = s[5:]
  elif s=='eraser':
    s = s[]
  elif len(s)>6 and s[0:6]=='erasere':
	s = s[6:]
  elif len(s)>6 and s[0:6]=='eraserd':
	s = s[6:]
  elif s=='dreamer':
    s = []
  elif len(s)>7 and s[0:7]='dreamere':
    s = s[7:]
  elif len(s)>7 and s[0:7]='dreamerd':
    s = s[7:]
  elif s='dream':
    s = s[]
  elif len(s)>5 and s[0:5]='dreamd':
    s = s[6:]
  print(s)
    
# dream dreamer erase eraser
Problem p02641 (python)

Fixed submission:
x, n = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))

    a = [i for i in range(102)]
    for i in range(n):
        a[p[i]] = 1000
    minimum = 1000
    result = 1000
    for i in reversed(range(102)):
        if a[i] != 1000:
            if minimum >= abs(x - a[i]):
                minimum = abs(x - a[i])
                result = a[i]

    print(result)

Buggy submission (verdict: Runtime Error):
x, n = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))

    a = [i for i in range(101)]
    for i in range(n):
        a[p[i]] = 1000
    min = 1000
    result = 1000
    if n == 100:
        result = min(abs(100-x),abs(x))
    else:
        for i in reversed(range(1,101)):
            if a[i] != 1000:
                if min >= abs(x - a[i]):
                    min = abs(x - a[i])
                    result = a[i]

    print(result)
Problem p02642 (python)

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


maxA = max(a)
dp = [0]*(maxA+1)
count = 0

for e in a:
    for i in range(e,maxA+1,e):
        dp[i] += 1

for e in a:
    if dp[e] == 1:
        count += 1

print(count)

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

b = souted(set(a))

maxA = max(b)
dp = [0]*(maxA+1)
count = 0

for e in b:
    for i in range(e,maxA+1,e):
        dp[i] += 1

for e in b:
    if dp[e] == 1:
        count += 1

print(count)

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

maxA = max(a)
count = 0

for e in a:
    for i in range(e,maxA+1,e):
        dp[i] += 1
        
for e in a:
    if dp[e] == 1:
        count += 1

print(count)

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

b = sorted(set(a))

if len(b) == 1:
    print(0)
else:    
    stack = []
    stack.append(b[0])
    for i in range(1,n):
        flag = 0
        for e in stack:
            if b[i] % e == 0:
                flag = 1
                break
        if flag == 0:
            stack.append(b[i])

    print(len(stack))

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

b = sorted(a)

stack = []
stack.push(b[0])
for i in range(1,n):
    flag = 0
    for e in stack:
        if b[i] % e == 0:
            flag = 1
            break
    if flag == 0:
        stack.push(e)

print(len(stack))
Problem p02647 (python)

Fixed submission:
#pypy
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

#累積和
for _ in range(K):
    B = [0]*N
    for i in range(N):
        l = max(0,i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        if r+1 < N: B[r+1] -= 1
    for i in range(1,N):
        B[i] += B[i-1]
    B, A = A, B
    if min(A) == N:
        break

print(*A)

Buggy submission (verdict: Runtime Error):
#pypy
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.push(0)

#累積和
for _ in range(K):
    B = [0]*(N+1)
    for i in range(N):
        l = max(0,i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        B[r+1] -= 1
    for i in range(1,N):
        B[i] += B[i-1]
    A = B
    if min(A) == N:
        break
A.pop()
print(*A)
Problem p02665 (python)

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

pm = sum(A)
e = 1
te = 1
for i in A:
    pm -= i
    e = min((e-i) * 2,pm)
    if e < 0:
        break
    te += e
if e < 0:
    print(-1)
else:
    print(te)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

pm = sum(A)
te = 1
if A[0] != 0 or A[N] == 0:
    print(-1)
else:
    for i in A:
        pm -= i
        e = min((e-i) * 2,pm)
        if e < 0:
            break
        te += e
    if e < 0:
        print(-1)
    else:
        print(te)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

pm = sum(A)
te = 1
if A[0] != 0 or A[N] == 0:
    print(-1)
else:
    for i in A:
        pm -= i
        e = min((e-i) * 2,pm)
        if e < 0:
            break
        te += e
    if e < 0:
        print(-1)
    else:
        print(te)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

if A[0] != 0:
    print(-1)
else:
    B = [0]*(N+1)
    C = [0]*(N+1)
    B[0] = 1
    C[N] = A[N]
    flag = True
    for i in range(1,N+1):
        B[i] = (B[i-1]-A[i-1]) * 2
        if (i < N and B[i] <= A[i]) or (i = N and B[i] < A[i]): flag = False
        C[N-i] = C[N+1-i]+A[N-i]
    sum = 0
    for i in range(0,N+1):
        sum += min(B[i],C[i])
    if flag == True:
        print(sum)
    else:
        print(-1)
Problem p02657 (python)

Fixed submission:
a, b = map(int, input().split())
print(a * b)

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

r, pow = 1, 10 ** 18
for num in A:
  r *= num
  if r == 0:
    break
print(-1 if r > pow else r)

Buggy submission (verdict: Runtime Error):
a, b = map(int, raw_input().split())
print(a * b)
Problem p03455 (python)

Fixed submission:
def product(a, b):
    return a * b

def judge(num):
    if num % 2 == 0:
        print('Even')
    else:
        print('Odd')

a, b = map(int, input().split())

judge(product(a, b))

Buggy submission (verdict: Runtime Error):

def product(a, b):
    return a * b

def judge(num):
    if num % 2 == 0:
        print('Even')
    else:
        print('Odd')

a, b = map(int, input())

judge(product(a, b))
Problem p03296 (python)

Fixed submission:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split(' '))

res, l, r = 0, 0, 0
while r < n:
  l = r
  while r+1 < n and a[r+1] == a[l]:
    r += 1
  res += (r - l + 1) / 2
  r += 1
print res

Buggy submission (verdict: Runtime Error):
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split(' '))

res, l, r = 0, 0, 0
while r < n:
  l = r
  while r+1 < n and a[r+1] == a[l]:
    r += 1
  res += (r - l + 1) / 2
  r += 1
print res
Problem p03363 (python)

Fixed submission:
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split(' '))
ss, cc = 0, {0: 1}
rs = 0
for k in a:
  ss += k
  cc[ss] = cc.get(ss, 0) + 1
  rs += cc[ss] - 1

print rs

Buggy submission (verdict: Runtime Error):
from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().split(' '))
ss, cc = 0, {0: 1}
rs = 0
for k in a:
  ss += k
  cc[k] += 1
  rs += cc[k] - 1

print rs
Problem p02660 (python)

Fixed submission:
from itertools import accumulate
from bisect import bisect_right
def prime_factorize_dict(n):
    d = dict()
    while not n & 1:
        d[2] = d.get(2, 0) + 1
        n >>= 1
    f = 3
    while f * f <= n:
        if not n % f:
            d[f] = d.get(f, 0) + 1
            n //= f
        else:
            f += 2
    if n != 1:
        d[n] = d.get(n, 0) + 1
    return d

N = int(input())
l = list(prime_factorize_dict(N).values())
L = list(accumulate(range(10 ** 6)))
print(sum(bisect_right(L, item) - 1 for item in l))

Buggy submission (verdict: Runtime Error):
from statistics import median
N = int(input())
A, B = zip(*tuple(tuple(map(int, input().split())) for _ in range(N)))
print(int((median(B) - median(A)) * (1 + (not N & 1))) + 1)

Buggy submission (verdict: Runtime Error):
N = int(input())
count = 0
for i in range(2, int(N ** 0.5 + 1)):
    div, rem = divmod(N, i)
    if not rem:
        count += 1
        N = div
print(count + (N > i))
Problem p02662 (python)

Fixed submission:
MOD = 998244353
N, S = map(int, input().split())
A = tuple(map(int, input().split()))
table = [[0] * (S + 1) for _ in range(N + 1)]
table[0][0] = 1
for n in range(N):
    for s in range(S + 1):
        now = table[n][s]
        table[n + 1][s] = (table[n + 1][s] + now * 2) % MOD
        if s + A[n] <= S:
            table[n + 1][s + A[n]] = (table[n + 1][s + A[n]] + now) % MOD
print(table[N][S])

Buggy submission (verdict: Runtime Error):
MOD = 998244353
N, S = map(int, input().split())
A = tuple(map(int, input().split()))
table = {0: 1}
for n in range(N):
    next_table = dict()
    for s, now in table.items():
        next_table[s] = (next_table.get(s, 0) + now * 2) % MOD
        if s + A[n] <= S:
            next_table[s + A[n]] = (next_table.get(s + A[n], 0) + now) % MOD
    table = next_table
print(table[S])

Buggy submission (verdict: Runtime Error):
MOD = 998244353
N, S = map(int, input().split())
A = tuple(map(int, input().split()))
table = {0: 1}
for n in range(N):
    next_table = dict()
    for s, now in table.items():
        next_table[s] = (next_table.get(s, 0) + now * 2) % MOD
        if s + A[n] <= S:
            next_table[s + A[n]] = (next_table.get(s + A[n], 0) + now) % MOD
    table = next_table
print(table[S])
Problem p02678 (python)

Fixed submission:
from collections import deque
def bfs(graph, N, start):
    visited = [0] * N
    visited[start] = 1
    que = deque([start])
    while que:
        node = que.popleft()
        for n in graph[node]:
            if not visited[n]:
                visited[n] = node + 1
                que.append(n)
    return visited

N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(lambda n: int(n) - 1, input().split())
    graph[a].append(b)
    graph[b].append(a)
visited = bfs(graph, N, 0)[1:]
if all(visited):
    print("Yes")
    print(*visited, sep="\n")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
from collections import deque
def bfs(graph, N, start):
    visited = [0] * N
    visited[start] = 1
    que = deque([start])
    while que:
        node = que.popleft()
        for n in graph[node]:
            if not visited[n]:
                visited[n] = node + 1
                que.append(n)
    return visited

N, M = map(int, input().split())
graph = [[] for _ in range(M)]
for _ in range(M):
    a, b = map(lambda n: int(n) - 1, input().split())
    graph[a].append(b)
    graph[b].append(a)
visited = bfs(graph, N, 0)[1:]
if all(visited):
    print("Yes")
    print(*visited, sep="\n")
else:
    print("No")
Problem p02692 (python)

Fixed submission:
N, A, B, C = map(int, input().split())
inputs = tuple(tuple(input()) for _ in range(N))

dic = {
    "A": A,
    "B": B,
    "C": C
}

ans = [0] * N
depth = 0
while depth < N:
    key1, key2 = inputs[depth]
    if dic[key1] < dic[key2]:
        dic[key1] += 1
        dic[key2] -= 1
        ans[depth] = key1
    elif dic[key1] > dic[key2]:
        dic[key2] += 1
        dic[key1] -= 1
        ans[depth] = key2
    else:
        if not dic[key1]:
            break
        elif dic[key1] == 1 and depth + 1 < N:
            next_key1, next_key2 = inputs[depth + 1]
            common_key, *_ = {key1, key2} & {next_key1, next_key2}
            else_key, *_ = {key1, key2} - {common_key}
            dic[common_key] += 1
            dic[else_key] -= 1
            ans[depth] = common_key
        else:
            dic[key1] += 1
            dic[key2] -= 1
            ans[depth] = key1
    depth += 1
else:
    print("Yes")
    print(*ans, sep="\n")
    quit()
print("No")

Buggy submission (verdict: Runtime Error):
N, A, B, C = map(int, input().split())
dic = {
    "A": A,
    "B": B,
    "C": C
}
ans = [0] * N
def part_solve(dic, depth):
    while depth < N:
        key1, key2 = inputs[depth]
        if dic[key1] < dic[key2]:
            dic[key1] += 1
            dic[key2] -= 1
            ans[depth] = key1
        elif dic[key1] > dic[key2]:
            dic[key2] += 1
            dic[key1] -= 1
            ans[depth] = key2
        else:
            if not dic[key1]:
                return False
            else:
                key3 = "ABC".replace(key1, "").replace(key2, "")
                return part_solve({
                    key1: dic[key1] + 1,
                    key2: dic[key2] - 1,
                    key3: dic[key3]
                }, depth) or part_solve({
                    key1: dic[key1] - 1,
                    key2: dic[key2] + 1,
                    key3: dic[key3]
                }, depth)
        depth += 1
    return True

inputs = tuple(tuple(input()) for _ in range(N))
if part_solve(dic, 0):
    print("Yes")
    print(*ans, sep="\n")
else:
    print("No")
Problem p02702 (python)

Fixed submission:
from collections import Counter
S = list(reversed(input()))
l = len(S)
N = 0
counts = Counter([(N := N + (pow(10, i, 2019) * int(S[i])) % 2019) % 2019 for i in range(l)] + [0])
print(sum(n * (n - 1) // 2 for n in counts.values()))

Buggy submission (verdict: Runtime Error):
from math import log10
from collections import Counter
S = int(input())
l = int(log10(S)) + 1
print(sum(n * (n - 1) // 2 for n in Counter((S := S % 10 ** (l - i)) % 2019 for i in range(l + 1)).values()))