Problem p02692 (python)

Fixed submission:
n,a,b,c=map(int,input().split())
s_=[input() for i in range(n)]
ans=""
for i in range(n):
    s1,s2=s_[i]
    if s2=="B":
        if a==1 and b==1 and i!=n-1:
            if s_[i+1][0]=="A":
                a,b,ans=(a+1,b-1,ans+"A")
            else:
                a,b,ans=(a-1,b+1,ans+"B")
            continue
        a,b,ans=(a-1,b+1,ans+"B") if a>b else (a+1,b-1,ans+"A")
        if min(a,b)==-1:
            print("No")
            break
    elif s1=="A":
        if a==1 and c==1 and i!=n-1:
            if s_[i+1][1]=="C":
                a,c,ans=(a-1,c+1,ans+"C")
            else:
                a,c,ans=(a+1,c-1,ans+"A")
            continue
        a,c,ans=(a-1,c+1,ans+"C") if a>c else (a+1,c-1,ans+"A")
        if min(a,c)==-1:
            print("No")
            break
    else:
        if c==1 and b==1 and i!=n-1:
            if s_[i+1][1]=="C":
                b,c,ans=(b-1,c+1,ans+"C")
            else:
                b,c,ans=(b+1,c-1,ans+"B")
            continue
        b,c,ans=(b-1,c+1,ans+"C") if b>c else (b+1,c-1,ans+"B")
        if min(b,c)==-1:
            print("No")
            break
else:
    print("Yes")
    for j in range(n):
        print(ans[j])

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

n,a,b,c=map(int,input().split())
s_=input().split()
ans=""
for i in range(n):
    s1,s2=s_[i]
    if s2=="B":
        if i!=n-1:
            if s_[i+1]=="AC" and c==0 and a<=1:
                a,b,ans=(a+1,b-1,ans+"A")
            elif s_[i+1]=="BC" and c==0 and b<=1:
                a,b,ans=(a-1,b+1,ans+"B")
            else:
                a,b,ans=(a-1,b+1,ans+"B") if a>b else (a+1,b-1,ans+"A")
        else:
            a,b,ans=(a-1,b+1,ans+"B") if a>b else (a+1,b-1,ans+"A")
        if min(a,b)==-1:
            print("No")
            break
    elif s1=="A":
        if i!=n-1:
            if s_[i+1]=="AB" and b==0 and a<=1:
                a,c,ans=(a+1,c-1,ans+"A")
            elif s_[i+1]=="BC" and b==0 and c<=1:
                a,c,ans=(a-1,c+1,ans+"C")
            else:
                a,c,ans=(a-1,c+1,ans+"C") if a>c else (a+1,c-1,ans+"A")
        else:
            a,c,ans=(a-1,c+1,ans+"C") if a>c else (a+1,c-1,ans+"A")
        if min(a,c)==-1:
            print("No")
            break
    else:
        if i!=n-1:
            if s_[i+1]=="AB" and a==0 and b<=1:
                b,c,ans=(b+1,c-1,ans+"B")
            elif s_[i+1]=="AC" and a==0 and c<=1:
                b,c,ans=(b-1,c+1,ans+"C")
            else:
                b,c,ans=(b-1,c+1,ans+"C") if b>c else (b+1,c-1,ans+"B")
        else:
            b,c,ans=(b-1,c+1,ans+"C") if b>c else (b+1,c-1,ans+"B")
        if min(b,c)==-1:
            print("No")
            break
else:
    print("Yes")
    for j in range(n):
        print(ans[j])

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n,a,b,c=map(int,input().split())
s_=[input() for i in range(n)]
ans=""
for i in range(n):
    s1,s2=s_[i]
    if s2=="B":
        if a>b:
            a,b=a-1,b+1
            ans+="B"
        else:
            a,b=a+1,b-1
            ans+="A"
        if min(a,b)==-1:
            print("No")
            break
    elif s1=="A":
        if a>c:
            a,c=a-1,c+1
            ans+="C"
        else:
            a,c=a+1,c-1
            ans+="A"
        if min(a,c)==-1:
            print("No")
            break
    else:
        if b>c:
            b,c=b-1,c+1
            ans+="C"
        else:
            b,c=b+1,c-1
            ans+="B"
        if min(b,c)==-1:
            print("No")
            break
else:
    print("Yes")
    for j in range(n):
        print(ans[j])

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n,a,b,c=map(int,input().split())
s_=[input() for i in range(n)]
ans=""
for i in range(n):
    s1,s2=s_[i]
    if s2=="B":
        if a>b:
            a,b=a-1,b+1
            ans+="B"
        else:
            a,b=a+1,b-1
            ans+="A"
        if min(a,b)==-1:
            print("No")
            break
    elif s1=="A":
        if a>c:
            a,c=a-1,c+1
            ans+="C"
        else:
            a,c=a+1,c-1
            ans+="A"
        if min(a,c)==-1:
            print("No")
            break
    else:
        if b>c:
            b,c=b-1,c+1
            ans+="C"
        else:
            b,c=b+1,c-1
            ans+="B"
        if min(b,c)==-1:
            print("No")
            break
else:
    print("Yes")
    for j in range(n):
        print(ans[j])

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n,a,b,c=map(int,input().split())
s_=[input() for i in range(n)]
ans=""
for i in range(n):
    s1,s2=s_[i]
    if s2=="B":
        if a>b:
            a,b=a-1,b+1
            ans+="B"
        else:
            a,b=a+1,b-1
            ans+="A"
        if min(a,b)==-1:
            print("No")
            break
    elif s1=="A":
        if a>c:
            a,c=a-1,c+1
            ans+="C"
        else:
            a,c=a+1,c-1
            ans+="A"
        if min(a,c)==-1:
            print("No")
            break
    else:
        if b>c:
            b,c=b-1,c+1
            ans+="C"
        else:
            b,c=b+1,c-1
            ans+="B"
        if min(b,c)==-1:
            print("No")
            break
else:
    print("Yes")
    for j in range(n):
        print(ans[j])

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n,a,b,c=map(int,input().split())
s_=[input() for i in range(n)]
ans=""
for i in range(n):
    s1,s2=s_[i]
    if s2=="B":
        if a>b:
            a,b=a-1,b+1
            ans+="B"
        else:
            a,b=a+1,b-1
            ans+="A"
        if min(a,b)==-1:
            print("No")
            break
    elif s1=="A":
        if a>c:
            a,c=a-1,c+1
            ans+="C"
        else:
            a,c=a+1,c-1
            ans+="A"
        if min(a,c)==-1:
            print("No")
            break
    else:
        if b>c:
            b,c=b-1,c+1
            ans+="C"
        else:
            b,c=b+1,c-1
            ans+="B"
        if min(b,c)==-1:
            print("No")
            break
else:
    print("Yes")
    for j in range(n):
        print(ans[j])

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n,a,b,c=map(int,input().split())
s=[input() for i in range(n)]
dp=[dict() for i in range(n+1)]
dp[0][""]=[a,b,c]
for i in range(n):
    if len(dp[i])==0:
        print("No")
        break
    if s[i]=="AB":
        for j in dp[i]:
            a,b,c=dp[i][j]
            if dp[i][j][0]>0:
                dp[i+1][j+"A"]=[a-1,b+1,c]
            if dp[i][j][1]>0:
                dp[i+1][j+"B"]=[a+1,b-1,c]
    elif s[i]=="AC":
        for j in dp[i]:
            a,b,c=dp[i][j]
            if dp[i][j][0]>0:
                dp[i+1][j+"A"]=[a-1,b,c+1]
            if dp[i][j][2]>0:
                dp[i+1][j+"C"]=[a+1,b,c-1]
    else:
        for j in dp[i]:
            a,b,c=dp[i][j]
            if dp[i][j][1]>0:
                dp[i+1][j+"B"]=[a,b-1,c+1]
            if dp[i][j][2]>0:
                dp[i+1][j+"C"]=[a,b+1,c-1]
else:
    print("Yes")
    z=list(dp[-1])
    #print(z)
    for i in range(n):
        print(z[-1][i])

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n,a,b,c=map(int,input().split())
s=[input() for i in range(n)]
dp=[dict() for i in range(n+1)]
dp[0][""]=[a,b,c]
for i in range(n):
    if len(dp[i])==0:
        print("No")
        break
    if s[i]=="AB":
        for j in dp[i]:
            a,b,c=dp[i][j]
            if dp[i][j][0]>0:
                dp[i+1][j+"A"]=[a-1,b+1,c]
            if dp[i][j][1]>0:
                dp[i+1][j+"B"]=[a+1,b-1,c]
    elif s[i]=="AC":
        for j in dp[i]:
            a,b,c=dp[i][j]
            if dp[i][j][0]>0:
                dp[i+1][j+"A"]=[a-1,b,c+1]
            if dp[i][j][2]>0:
                dp[i+1][j+"C"]=[a+1,b,c-1]
    else:
        for j in dp[i]:
            a,b,c=dp[i][j]
            if dp[i][j][1]>0:
                dp[i+1][j+"B"]=[a,b-1,c+1]
            if dp[i][j][2]>0:
                dp[i+1][j+"C"]=[a,b+1,c-1]
else:
    print("Yes")
    z=list(dp[-1])
    print(z)
    for i in range(n):
        print(z[-1][i])