Buggy python 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])



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 python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
n,A,B,C=map(int,input().split())
s=[input() for i in range(n)]
def dfs(d,a,b,c,now):
    global n,s
    if d==n:
        print("Yes")
        for i in range(n):
            print(now[i])
        sys.exit()
    else:
        if s[d][0]=="A" and s[d][1]=="B":
            if a>b:
                dfs(d+1,a-1,b+1,c,now+"B")
            elif a<b:
                dfs(d+1,a+1,b-1,c,now+"A")
            else:
                if a>0:
                    dfs(d+1,a-1,b+1,c,now+"B")
                if b>0:
                    dfs(d+1,a+1,b-1,c,now+"A")
        elif s[d][0]=="A" and s[d][1]=="C":
            if a>c:
                dfs(d+1,a-1,b,c+1,now+"C")
            elif a<c:
                dfs(d+1,a+1,b,c-1,now+"A")
            else:
                if a>0:
                    dfs(d+1,a-1,b,c+1,now+"C")
                if c>0:
                    dfs(d+1,a+1,b,c-1,now+"A")
        else:
            if b>c:
                dfs(d+1,a,b-1,c+1,now+"C")
            elif b<c:
                dfs(d+1,a,b+1,c-1,now+"B")
            else:
                if b>0:
                    dfs(d+1,a,b-1,c+1,now+"C")
                if c>0:
                    dfs(d+1,a,b+1,c-1,now+"B")

dfs(0,A,B,C,"")
print("No")

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 python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
n,A,B,C=map(int,input().split())
s=[input() for i in range(n)]
def dfs(d,a,b,c,now):
    global n,s
    if d==n:
        print("Yes")
        for i in range(n):
            print(now[i])
        sys.exit()
    else:
        if s[d][0]=="A" and s[d][1]=="B":
            if a>b:
                dfs(d+1,a-1,b+1,c,now+"B")
            elif a<b:
                dfs(d+1,a+1,b-1,c,now+"A")
            else:
                if a>0:
                    dfs(d+1,a-1,b+1,c,now+"B")
                if b>0:
                    dfs(d+1,a+1,b-1,c,now+"A")
        elif s[d][0]=="A" and s[d][1]=="C":
            if a>c:
                dfs(d+1,a-1,b,c+1,now+"C")
            elif a<c:
                dfs(d+1,a+1,b,c-1,now+"A")
            else:
                if a>0:
                    dfs(d+1,a-1,b,c+1,now+"C")
                if c>0:
                    dfs(d+1,a+1,b,c-1,now+"A")
        else:
            if b>c:
                dfs(d+1,a,b-1,c+1,now+"C")
            elif b<c:
                dfs(d+1,a,b+1,c-1,now+"B")
            else:
                if b>0:
                    dfs(d+1,a,b-1,c+1,now+"C")
                if c>0:
                    dfs(d+1,a,b+1,c-1,now+"B")

dfs(0,A,B,C,"")
print("No")

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 python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
n,A,B,C=map(int,input().split())
s=[input() for i in range(n)]
def dfs(d,a,b,c,now):
    global n,s
    if d==n:
        print("Yes")
        for i in range(n):
            print(now[i])
        sys.exit()
    else:
        if s[d][0]=="A" and s[d][1]=="B":
            if a>0:
                dfs(d+1,a-1,b+1,c,now+"B")
            if b>0:
                dfs(d+1,a+1,b-1,c,now+"A")
        elif s[d][0]=="A" and s[d][1]=="C":
            if a>0:
                dfs(d+1,a-1,b,c+1,now+"C")
            if c>0:
                dfs(d+1,a+1,b,c-1,now+"A")
        else:
            if b>0:
                dfs(d+1,a,b-1,c+1,now+"C")
            if c>0:
                dfs(d+1,a,b+1,c-1,now+"B")

dfs(0,A,B,C,"")
print("No")

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 python 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])



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 python 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])



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 python 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])



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 python 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])



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 python submission (verdict: Time Limit Exceeded):
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][0]=="A" and s[i][1]=="B":
        #print(0)
        for j in dp[i]:
            a,b,c=j
            if a>0:
                dp[i+1][(a-1,b+1,c)]=dp[i][j]+"B"
            if b>0:
                dp[i+1][(a+1,b-1,c)]=dp[i][j]+"A"
    elif s[i][0]=="A" and s[i][1]=="C":
        #print(1)
        for j in dp[i]:
            a,b,c=j
            if a>0:
                dp[i+1][(a-1,b,c+1)]=dp[i][j]+"C"
            if c>0:
                dp[i+1][(a+1,b,c-1)]=dp[i][j]+"A"
    else:
        #print(2)
        for j in dp[i]:
            a,b,c=j
            if b>0:
                dp[i+1][(a,b-1,c+1)]=dp[i][j]+"C"
            if c>0:
                dp[i+1][(a,b+1,c-1)]=dp[i][j]+"B"
else:
    if len(dp[n])==0:
        print("No")
    else:
        print("Yes")
        #print(dp)
        z=list(dp[n].items())
        #print(z)
        for i in range(n):
            print(z[0][1][i])






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 python submission (verdict: Time Limit Exceeded):
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][0]=="A" and s[i][1]=="B":
        #print(0)
        for j in dp[i]:
            a,b,c=j
            if a>0:
                dp[i+1][(a-1,b+1,c)]=dp[i][j]+"B"
            if b>0:
                dp[i+1][(a+1,b-1,c)]=dp[i][j]+"A"
    elif s[i][0]=="A" and s[i][1]=="C":
        #print(1)
        for j in dp[i]:
            a,b,c=j
            if a>0:
                dp[i+1][(a-1,b,c+1)]=dp[i][j]+"C"
            if c>0:
                dp[i+1][(a+1,b,c-1)]=dp[i][j]+"A"
    else:
        #print(2)
        for j in dp[i]:
            a,b,c=j
            if b>0:
                dp[i+1][(a,b-1,c+1)]=dp[i][j]+"C"
            if c>0:
                dp[i+1][(a,b+1,c-1)]=dp[i][j]+"B"
else:
    if len(dp[n])==0:
        print("No")
    else:
        print("Yes")
        #print(dp)
        z=list(dp[n].items())
        #print(z)
        for i in range(n):
            print(z[0][1][i])






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 python submission (verdict: Time Limit Exceeded):
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][0]=="A" and s[i][1]=="B":
        #print(0)
        for j in dp[i]:
            a,b,c=dp[i][j]
            if dp[i][j][0]>0:
                dp[i+1][j+"B"]=[a-1,b+1,c]
            if dp[i][j][1]>0:
                dp[i+1][j+"A"]=[a+1,b-1,c]
    elif s[i][0]=="A" and s[i][1]=="C":
        #print(1)
        for j in dp[i]:
            a,b,c=dp[i][j]
            if dp[i][j][0]>0:
                dp[i+1][j+"C"]=[a-1,b,c+1]
            if dp[i][j][2]>0:
                dp[i+1][j+"A"]=[a+1,b,c-1]
    else:
        #print(2)
        for j in dp[i]:
            a,b,c=dp[i][j]
            if dp[i][j][1]>0:
                dp[i+1][j+"C"]=[a,b-1,c+1]
            if dp[i][j][2]>0:
                dp[i+1][j+"B"]=[a,b+1,c-1]
else:
    if len(dp[n])==0:
        print("No")
    else:
        print("Yes")
        #print(dp)
        z=list(dp[-1])
        #print(z)
        for i in range(n):
            print(z[-1][i])






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 python 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])






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 python 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])






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])