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

Fixed submission:
T1, T2=(int(i) for i in input().split())
A1, A2=(int(i) for i in input().split())
B1, B2=(int(i) for i in input().split())

if T1*A1+T2*A2==T1*B1+T2*B2:
    print("infinity")
elif ((A1>B1) & (T1*A1+T2*A2-(T1*B1+T2*B2)>0)) or ((A1<B1) & (T1*A1+T2*A2-(T1*B1+T2*B2)<0)):
    print(0)
else:
    d=abs(T1*A1+T2*A2-(T1*B1+T2*B2))#T1+T2だけ走った後離れている距離
    ss=0
    if abs(T1*(A1-B1))%d==0:
        ss=1
        
    print(abs(T1*(A1-B1))//d*2-ss+1)

Buggy submission (verdict: Runtime Error):
T1, T2=(int(i) for i in input().split())
A1, A2=(int(i) for i in input().split())
B1, B2=(int(i) for i in input().split())

if T1*A1+T2*A2==T1*B1+T2*B2:
    print("infinity")
elif ((A1>B1) & (T1*A1+T2*A2-(T1*B1+T2*B2)>0)) or ((A1<B1) & (T1*A1+T2*A2-(T1*B1+T2*B2)<0)):
    print(0)
else:
    d=T1*A1+T2*A2-(T1*B1+T2*B2)#T1+T2だけ走った後離れている距離
    if abs(T1*(A1-B1))%d==0:
        ss=1
    print(abs(T1*(A1-B1))//d*2-ss+1)
Problem p02909 (python)

Fixed submission:
S=input()
if (S=="Sunny"): print("Cloudy")
elif (S=="Cloudy"):print("Rainy")
else: print("Sunny")

Buggy submission (verdict: Runtime Error):
S=input()
if (S="Sunny"):
    print("Cloudy")
elif (S="Cloudy"):
    print("Rainy")
else:
    print("Sunny")
Problem p02921 (python)

Fixed submission:
S=input()
T=input()

ans=0
if S[0]==T[0]:ans+=1
if S[1]==T[1]:ans+=1
if S[2]==T[2]:ans+=1

print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
if N%2==0:
    s=N/2
    print(int(s*(N-1)))
if N%2==1:
    s=(N-1)/2
    print(int(s*N))

Buggy submission (verdict: Runtime Error):
N=int(input())
print(int(N/2*(N-1)))
Problem p03071 (python)

Fixed submission:
a,b =(int(i) for i in input().split())
if a==b:
  print(a*2)
elif a>b:
  print(2*a-1)
else:
  print(b*2-1)

Buggy submission (verdict: Runtime Error):
a,b =map(int(i) for i in input().split())
if a==b:
  print(a*a)
elif a>b:
  print(2*a-1)
else:
  print(b*2-1)
Problem p03086 (python)

Fixed submission:
x=input()
N=len(x)
maxl=0
for i in range(N):
  if (x[i]=="A")or(x[i]=="T")or(x[i]=="G")or(x[i]=="C"):
    j=1
    while (i+j<N):
      if ((x[i+j]=="A")or(x[i+j]=="T")or(x[i+j]=="G")or(x[i+j]=="C")):
        j=j+1
      else:
        break
    if maxl<j:
      maxl=j
      maxi=i
    
print(maxl)

Buggy submission (verdict: Runtime Error):
SHINJUKU
Problem p03087 (python)

Fixed submission:
N,Q=(int(i) for i in input().split())
x=input()
a=[]

j=0
s=[0]
t=0
while (j<N-1):
  if (x[j]=="A") and (x[j+1]=="C"):
    t+=1
    s.append(t)
  else:s.append(t)
  j+=1
for i in range(0,Q):
  a.append([int(j) for j in input().split()])
  p=s[a[i][1]-1]-s[a[i][0]-1]
  print(p)

Buggy submission (verdict: Runtime Error):
N,Q=(int(i) for i in input().split())
x=input()
a=[]

j=0
s=[]
while (j<len(x)-1):
  if (x[j]=="A"):
    if (x[j+1]=="C"):
      s.append(j+1)
      j+=1
  j+=1
for i in range(0,Q):
  a.append([int(j) for j in input().split()])
  answer=0
  j=0
  while s[j]<a[i][0]:
    j+=1
    if len(s)<=j:break
  k=0
  while s[k]<a[i][1]:
    k+=1
    if len(s)<=k:break
  print(k-j)
Problem p03160 (python)

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

cost=[0]
for i in range(1,N):
    if i!=1: 
        cost.append(min(cost[i-1]+abs(h[i]-h[i-1]), cost[i-2]+abs(h[i]-h[i-2])))
    else:
        cost.append(cost[i-1]+abs(h[i]-h[i-1]))
print(cost.pop())

Buggy submission (verdict: Runtime Error):
N, K=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]

cost=[0]
for i in range(1,N):
    m_cost=999999
    for j in range(1,min(K,i)+1):
        if m_cost>=cost[i-j]+abs(h[i]-h[i-j]):
            m_cost=cost[i-j]+abs(h[i]-h[i-j])
    cost.append(m_cost)
print(cost.pop())
Problem p03163 (python)

Fixed submission:


N, W=[int(i) for i in input().split()]
wv=[[int(i) for i in input().split()] for _ in range(N)]


dp=[[0]*(W+1) for _ in range(N)]

for i in range(N):
    for w in range(W+1):
        if i==0:
            if wv[i][0]<=w:
                dp[i][w]=wv[i][1]
        else:
            if w>=wv[i][0]:
                dp[i][w]=max(dp[i-1][w-wv[i][0]]+wv[i][1],dp[i-1][w])
            else:
                dp[i][w]=dp[i-1][w]

print(max(dp[-1]))

Buggy submission (verdict: Runtime Error):

import numpy as np

N, W=[int(i) for i in input().split()]
wv=[[int(i) for i in input().split()] for _ in range(N)]

dp=np.zeros((N,W+1)).astype("int64")


for i in range(N):
    for w in range(W+1):
        if i==0:
            if wv[i][0]<=w:
                dp[i][w]=wv[i][1]
        else:
            if w>=wv[i][0]:
                dp[i][w]=max(dp[i-1][w-wv[i][0]]+wv[i][1],dp[i-1][w])
            else:
                dp[i][w]=dp[i-1][w]

print(int(dp[-1].max()))
Problem p03311 (python)

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

for i in range(len(a)):
    a[i]-=i+1

aa=sorted(a)
if n%2==0:
  b=(aa[int(n/2-1)]+aa[int(n/2)])/2
else:
  b=aa[int((n-1)/2)]

s=0
for i in aa:
  s+=abs(i-b)
print(int(s))

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

for i in range(len(a)):
    a[i]-=i+1

aa=sorted(a)
if n%2==0:
  b=(aa[n/2-1]+aa[n/2])/2
else:
  b=aa[int((n-1)/2)]

s=0
for i in aa:
  s+=abs(i-b)
print(s)

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

for i in range(len(a)):
    a[i]-=i+1

import math
import numpy as np

aa=np.asarray(a)
b=math.floor(np.sum(aa)/n)

def p(b,k):
  s=np.sum(np.abs(aa-b))
  t=np.sum(np.abs(aa-b-1))
  if s>t:
    if k==-1:
      print(t)
    else:
      return p(b+1,1)
  elif s==t:
    print(s)
  else:
    if k==1:
      print(s)
    else:
      return p(b-1,-1)
  
p(b,0)

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

for i in range(len(a)):
    a[i]-=i+1

import math
#import statistics
#b=statistics.median(a)
b=math.floor(sum(a)/n)

import numpy as np

aa=np.asarray(a)
def p(b,k):
  s=np.sum(np.abs(aa-b))
  t=np.sum(np.abs(aa-b-1))
  if s>t:
    if k==-1:
      print(t)
    else:
      return p(b+1,1)
  elif s==t:
    print(s)
  else:
    if k==1:
      print(s)
    else:
      return p(b-1,-1)
  
p(b,0)
Problem p02548 (python)

Fixed submission:
import sys
import math

input = sys.stdin.readline

N = int(input())

total = 0
for i in range(1, N):
    total += (N-1) // i

print(total)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

import sympy

N = int(input())

total = 0
for i in range(1,N):
    total += len(sympy.divisors(i))

print(total)
Problem p03282 (python)

Fixed submission:
import sys
input = sys.stdin.readline

S=input().strip()
K=int(input().strip())

n = 0
m = 0
for c in S:
    if c != '1':
        m = int(c)
        break
    n += 1
if K <= n:
    print(1)
else:
    print(m)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S=input()
K=int(input())

n = 0
m = 0
for c in S:
    if c != '1':
        m = int(c)
        break
    n += 1
if K <= n:
    print(1)
else:
    print(m)
Problem p02576 (python)

Fixed submission:
import math
n,x,t = map(int, input().split())
print(math.ceil(n/x)*t)

Buggy submission (verdict: Runtime Error):
n,x,t = map(int, input().split())
print(math.ceil(n/x)*t)
Problem p02641 (python)

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

l = [i for i in range(102)]

for j in p:
    l.remove(j)

m = []

for k in l:
    m.append(abs(k-x))

print(l[m.index(min(m))])

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

l = [i for i in range(1,101)]

for j in p:
    l.remove(j)

m = []

for k in l:
    m.append(abs(k-x))

print(l[m.index(min(m))])

Buggy submission (verdict: Runtime Error):
x,n = map(int, input().split())
p = list(map(int, input().split()))
l = [i for i in range(1,101)]

for j in p:
    l.remove(j)

m = []

for k in l:
    m.append(abs(k-x))

print(l[m.index(min(m))])
Problem p02645 (python)

Fixed submission:
s = input()
print(s[:3])

Buggy submission (verdict: Runtime Error):
a,v =  map(int, input().split())
b,w =  map(int, input().split())
t = int(input())

if abs(w*t+b)-abs(v*t+a) >=0:
    print("NO")
else:
    print("YES")
Problem p02784 (python)

Fixed submission:
h,n = map(int, input().split())
a = list(map(int, input().split()))
print("Yes") if sum(a) >= h else print("No")

Buggy submission (verdict: Runtime Error):
h,n = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
print("Yes") if a[0] + a[1] > h else print("No")
Problem p02812 (python)

Fixed submission:
n = int(input())
s = input()
s2 = s.replace("ABC","")
print(int((len(s)-len(s2))/3))

Buggy submission (verdict: Runtime Error):
n = int(input)
s = input()
s2 = s.replace("ABC","")
print(int((len(s)-len(s2))/3))
Problem p02994 (python)

Fixed submission:
n,l = map(int, input().split())
tastes = [(i + l) for i in range(n)]
t = tastes.copy()
for j in range(n):
    t[j] = abs(t[j])
del tastes[t.index(min(t))]
print(sum(tastes))

Buggy submission (verdict: Runtime Error):
n,l = int(input())
tastes = [(i + l) for i in range(n)]
t = tastes.copy()
for j in range(n):
    t[j] = abs(t[j])
del tastes[t.index(min(t))]
print(sum(tastes))
Problem p03101 (python)

Fixed submission:
H,W = map(int,input().split())
h,w = map(int,input().split())

print(max(H*W-h*W-(H-h)*w,0))

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

 print(max(H*W-h*W-(H-h)*w,0))
Problem p03106 (python)

Fixed submission:
a,b,k = map(int, input().split())
l = []
for i in range(1,101):
    if (a % i == 0) & (b % i == 0):
        l.append(i)
print(l[-k])

Buggy submission (verdict: Runtime Error):
# a,b,k = map(int, input().split())
l = []
for i in range(1,100):
    if (a % i == 0) & (b % i == 0):
        l.append(i)
print(l[k-1])
Problem p03146 (python)

Fixed submission:
s = [int(input())]
for i in range(1000001):
    if s[i] % 2 == 0:
        s.append(s[i]/2)
    else:
        s.append(3 * s[i] + 1)
    if s[i] in s[:i]:
        print(i+1)
        break

Buggy submission (verdict: Runtime Error):
s = list(int(input()))
for i in range(1000001):
    if s[i] % 2 == 0:
        s.append(s[i]/2)
    else:
        s.append(3 * s[i] + 1)
    if s[i] in s[:i]:
        print(i+1)
        break
Problem p03238 (python)

Fixed submission:
n = int(input())
if n==1:
  print("Hello World")
else:
  i = [int(input()) for i in range(2)]
  print(i[0]+i[1])

Buggy submission (verdict: Runtime Error):
n = int(input())
if n==1:
  print("Hello World")
else:
  i = [int(input()) for i in range(3)]
  print(i[0]+i[1])

Buggy submission (verdict: Runtime Error):
i = [int(input()) for i in range(3)]

if i[0]==1:
  print("Hello World")
else:
  print(i[1]+i[2])
Problem p03385 (python)

Fixed submission:
s = list(input())
s.sort()
if "".join(s) == "abc":
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()
s.sort()
if "".join(s) = "abc":
    print("Yes")
else:
    print("No")
Problem p03407 (python)

Fixed submission:
a,b,c = map(int, input().split())
print("Yes") if c <= a+b else print("No")

Buggy submission (verdict: Runtime Error):
a,b,c = map(int, input().split())
print("Yes") if c =< a+b else print("No")
Problem p03494 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
l = [0 for i in range(n)]
for i in range(len(a)):
    while a[i] % 2 == 0:
        a[i] /= 2
        l[i] += 1
print(min(l))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [map(int, input().split())]
l = [0 for i in range(n)]
for i in range(len(a)):
    while a[i] % 2 == 0:
        a[i] /= 2
        l[i] += 1
print(min(l))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
l = [0 for i in range(n)]
for i in range(len(a)):
    while a[i] % 2 == 0:
        a[i] /= 2
        l[i] += 1
print(min(l))
Problem p03556 (python)

Fixed submission:
import math
n = int(input())
print(int(math.sqrt(n))**2)

Buggy submission (verdict: Runtime Error):
n = int(input())
k = int(input())
ref = 1

for i in range(n):
  if ref * 2 < ref + k:
    ref *= 2
  else:
    ref += k

print(ref)
Problem p03606 (python)

Fixed submission:
n = int(input())
l = [0] * n
r = [0] * n
for i in range(n):
    l[i],r[i] = map(int, input().split())
res = 0

for i in range(n):
  res += r[i]-l[i]+1

print(res)

Buggy submission (verdict: Runtime Error):
l = [0] * n
r = [0] * n
for i in range(n):
    l[i],r[i] = map(int, input().split())
res = 0

for i in range(n):
  res += r[i]-l[i]+1

print(res)
Problem p03609 (python)

Fixed submission:
x,t = map(int, input().split())
print(max(x-t,0))

Buggy submission (verdict: Runtime Error):
x,t = map(int, input().split())
print(max(x-t,0)
Problem p03644 (python)

Fixed submission:
n = int(input())
res = []
for i in range (1,n + 1):
    cnt = 0
    while i % 2 == 0:
        i /= 2
        cnt += 1
    res.append(cnt)
print(res.index(max(res))+1)

Buggy submission (verdict: Runtime Error):
n = int(intput())
res = []
for i in range (1,n + 1):
    cnt = 0
    while i % 2 == 0:
        i /= 2
        cnt += 1
    res.append(cnt)
print(res.index(max(res))+1)
Problem p03679 (python)

Fixed submission:
x,a,b = map(int, input().split())
if b-a < 1:
    print("delicious")
elif b-a < x + 1:
    print("safe")
else:
    print("dangerous")

Buggy submission (verdict: Runtime Error):
x,a,b = map(int, input().split())
if b-a < 1:
    print("delicious")
elif b-a = 1:
    print("safe")
else:
    print("dangerous")
Problem p03680 (python)

Fixed submission:
n = int(input())
a = [0] + [int(input()) for i in range(n)]
cnt = 1
next_a = a[1]

if a[1] == 2:
    print(cnt)

else:
    while cnt <= 10**5:
        next_a = a[next_a]
        cnt += 1
        if next_a == 2:
            break

    if cnt <= 10**5:
        print(cnt)
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [0,int(input()) for i in range(n)]
cnt = 1
next_a = a[1]
while cnt <= 10**5:
    next_a = a[next_a]
    cnt += 1
    if next_a == 2:
        break

if cnt < 10**5:
    print(cnt)
else:
    print(-1)
Problem p03694 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
print(max(a)-min(a))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
print(max(a)-min(a))
Problem p03697 (python)

Fixed submission:
a,b = map(int, input().split())
print(a+b) if a+b < 10 else print("error")

Buggy submission (verdict: Runtime Error):
a,b = map(str, input().split())
print(a+b) if a+b <= 10 else print("error")
Problem p04044 (python)

Fixed submission:
n,l = map(int,input().split())
s = [input() for _ in range(n)]
s.sort()
ss = ""
for i in range(n):
    ss += s[i]
print(ss)

Buggy submission (verdict: Runtime Error):
n,l = map(int,input().split())
s = [input() for _ in range(l)]
s.sort()
ss = ""
for i in range(n):
    ss += s[i]
print(ss)

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

s = [list(int(input())) for i in range(l)]

s.sort()
ss = ""
for i in range(n):
    ss += s[i]
print(ss)
Problem p02647 (python)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
 
 
for k in range(K):
  B = [0]*N
  for i in range(N): 
    start = max(0, i-A[i])
    end = min(N, i+A[i]+1)
    B[start] += 1
    if end <= N - 1:
      B[end] -= 1
 
  for i in range(1, N):
    B[i] = B[i-1] + B[i] 
  A = B
  if min(A) == N:
    break
 
print(*A)

Buggy submission (verdict: Runtime Error):
from numba import njit
import numpy as np
 
N, K = map(int, input().split())
A = list(map(int, input().split()))
 
@njit
for k in range(K):
  B = [0]*N
  for i in range(N): 
    start = max(0, i-A[i])
    end = min(N, i+A[i]+1)
    B[start] += 1
    if end <= N - 1:
      B[end] -= 1
  B = np.cumsum(B)
  #for i in range(1, N):
    #B[i] = B[i-1] + B[i] 
  A = B
  if min(A) == N:
    break
 
print(*A)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
 
B = [0]*N
 
for k in range(K):
 
  for i in range(N): 
    start = max(0, i-A[i])
    end = min(N, i+A[i]+1)
    B[start] += 1
    if end <= N - 1:
      B[end] -= 1
 
  for i in range(1, N):
    B[i] = B[i-1] + B[i] 
  A = B
  if min(A) == N:
    break
 
print(*A)

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

B = [0]*N

for k in range(K):

  for i in range(N): 
    start = max(0, i-A[i])
    end = min(N, i+A[i]+1)
    B[start] += 1
    if end <= N - 1:
      B[end] -= 1

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

print(A)
Problem p02731 (python)

Fixed submission:
L = int(input())

ans = (L**3)/27
print(ans)

Buggy submission (verdict: Runtime Error):
L = int(input())

ans = 0
for i in range(1, L+1):
  for j in range(1, L+1):
    if L - i - j > 0:
      V = i*j*(L - i - j)
    if V > ans:
      ans = V
print(ans)
Problem p02761 (python)

Fixed submission:
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(M)]

keta = [0,0,0]
DP = [0,0,0]

for i in sc:
  s = i[0]
  c = i[1]
  if DP[-1*N+s-1] == 0 or (DP[-1*N+s-1] == 1 and keta[-1*N+s-1] == c):
    keta[-1*N+s-1] = c
    DP[-1*N+s-1] = 1
  else:
    DP[-1*N+s-1] = -1
    
if keta[-1*N] == 0:
  if DP[-1*N] == 1 and N != 1:
    DP[-1*N] = -1
  elif N != 1:
    keta[-1*N] = 1
    DP[-1*N] = 1
  else:
    DP[-1*N] = 1
  
if -1 in DP:
  print(-1)
else:
  ans = ''
  for i in keta:
    ans += str(i)
  print(int(ans[3-N:]))
#print(DP)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(M)]
cnt = 0
ans = []
if N == 1:
  for i in range(10):
    i = str(i)
    for j in range(M):
      if i[sc[j][0] - 1] == str(c = sc[j][1]):
        cnt += 1
    if cnt == M:
      ans.append(int(i))
    cnt = 0
else:
  for i in range(10**(N-1), 10**N):
    i = str(i)
    for j in range(M):
      if i[sc[j][0] - 1] == str(sc[j][1]):
        cnt += 1
    if cnt == M:
      ans.append(int(i))
    cnt = 0

#print(ans)
print(min(ans) if ans else -1)
Problem p02658 (python)

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

	if 0 in A:
		print(0)
		return

	prod = 1
	for a in A:
		prod *= a
		if prod > int(1e18):
			print(-1)
			return

	print(prod)

main()

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 1
for i in range(0, n):
	t = int(input())
	ans *= t
if ans > int(1e18):
	print(-1)
else:
	print(ans)
Problem p02584 (python)

Fixed submission:

def main():
    X, K, D = list(map(int, input().split()))
    right = X % D
    left = right - D
    if X in [left, right]:
        if K % 2 == 0:
            print(abs(X))
        else:
            if X == left:
                print(right)
            else:
                print(abs(left))
        return
    if X > right:
        to_right = (X - right) // D
        if to_right >= K:
            print(X - K * D)
        else: # to_right < K
            if (K - to_right) % 2 == 0:
                print(right)
            else:
                print(abs(left))
    else:  # X < left
        to_left = (left - X) // D
        if to_left >= K:
            print(abs(X + K * D))
        else: # to_left < K
            if (K - to_left) % 2 == 0:
                print(abs(left))
            else:
                print(right)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    X, K, D = list(map(int, input().split()))
    right = X % D
    left = right - D
    if X in [left, right]:
        if K % 2 == 0:
            print(abs(X))
        else:
            if X == left:
                print(right)
            else:
                print(abs(left))
        return
    if X > right:
        to_right = (X - right) // D
        if to_right >= K:
            print(X - K * D)
        else: # to_right < K
            if (K - to_right) % 2 == 0:
                print(right)
            else:
                print(abs(left))
    else:  # X < left
        to_left = (left - X) // D
        if to_left >= K:
            print(abs(X + K * D))
        else: # to_left < K
            if (K - to_right) % 2 == 0:
                print(abs(left))
            else:
                print(right)


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

Fixed submission:
def main():
    N, A, B, C = list(map(int, input().split(' ')))
    S = [input() for _ in range(N)]
    D = {
        'AB': A + B,
        'BC': B + C,
        'AC': A + C
    }
    ans = list()
    for i, s in enumerate(S):
        if D[s] == 0:
            print('No')
            return
        if s == 'AB':
            if (D['BC'] < D['AC']) or \
                (i < N - 1 and S[i + 1] == 'BC' and D['BC'] == D['AC'] == 1):
                ans.append('B')
                D['BC'] += 1
                D['AC'] -= 1
            else:
                ans.append('A')
                D['BC'] -= 1
                D['AC'] += 1
        elif s == 'BC':
            if (D['AB'] < D['AC']) or \
                (i < N - 1 and S[i + 1] == 'AB' and D['AB'] == D['AC'] == 1):
                ans.append('B')
                D['AB'] += 1
                D['AC'] -= 1
            else:
                ans.append('C')
                D['AB'] -= 1
                D['AC'] += 1
        else:  # s == 'AC'
            if (D['AB'] < D['BC']) or \
                (i < N - 1 and S[i + 1] == 'AB' and D['AB'] == D['BC'] == 1):
                ans.append('A')
                D['AB'] += 1
                D['BC'] -= 1
            else:
                ans.append('C')
                D['AB'] -= 1
                D['BC'] += 1
    print('Yes')
    for a in ans:
        print(a)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N, A, B, C = list(map(int, input().split(' ')))
    S = [input() for _ in range(N)]
    D = {
        'AB': A + B,
        'BC': B + C,
        'AC': A + C
    }
    ans = list()
    for i, s in enumerate(S):
        if D[s] == 0:
            print('No')
            return
        if s == 'AB':
            if (D['BC'] < D['AC']) or \
                (i < N and S[i + 1] == 'BC' and D['BC'] == D['AC'] == 1):
                ans.append('B')
                D['BC'] += 1
                D['AC'] -= 1
            else:
                ans.append('A')
                D['BC'] -= 1
                D['AC'] += 1
        elif s == 'BC':
            if (D['AB'] < D['AC']) or \
                (i < N and S[i + 1] == 'AB' and D['AB'] == D['AC'] == 1):
                ans.append('B')
                D['AB'] += 1
                D['AC'] -= 1
            else:
                ans.append('C')
                D['AB'] -= 1
                D['AC'] += 1
        else:  # s == 'AC'
            if (D['AB'] < D['BC']) or \
                (i < N and S[i + 1] == 'AB' and D['AB'] == D['BC'] == 1):
                ans.append('A')
                D['AB'] += 1
                D['BC'] -= 1
            else:
                ans.append('C')
                D['AB'] -= 1
                D['BC'] += 1
    print('Yes')
    for a in ans:
        print(a)

if __name__ == '__main__':
    main()