Problem:
There is a game that involves three variables, denoted A, B, and C.  As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other.  After each choice, none of A, B, and C should be negative.  Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.

Incorrect submission (verdict: Wrong Answer):
def answer(x):
    print("Yes")
    for i in range(n):
        if s[i] == "AB":
            if x[0][0]:
                print("B")
                x[0][0] -= 1
            else:
                print("A")
        elif s[i] == "AC":
            if x[1][0]:
                print("C")
                x[1][0] -= 1
            else:
                print("A")
        else:
            if x[2][0]:
                print("C")
                x[2][0] -= 1
            else:
                print("B")
    exit()

n,a,b,c = map(int,input().split())
s = [str(input()) for i in range(n)]
cnt = [0 for i in range(3)]
for ss in s:
    if ss == "AB":
        a += 1
        b += 1
        cnt[0] += 1
    elif ss == "AC":
        a += 1
        c += 1
        cnt[1] += 1
    else:
        b += 1
        c += 1
        cnt[2] += 1
a,b,c = a//2,b//2,c//2
all = min(min(cnt),min(a,b,c))
a,b,c = a-all,b-all,c-all
for i in range(3):
    cnt[i] -= all
  # cnt=["AB","AC","BC"]
print(a,b,c)

#"AB"=0
if cnt[0] == 0:
        ACdeA = min(cnt[1],a)
        BCdeB = min(cnt[2],b)
        ACdeC = cnt[1]-ACdeA
        BCdeC = cnt[2]-BCdeB
        if ACdeC + BCdeC <= c:
            answer([[all,0],[ACdeA,all+ACdeC],[all+BCdeB,BCdeC]])
if cnt[1] == 0:
        ABdeA = min(cnt[0],a)
        BCdeC = min(cnt[2],c)
        ABdeB = cnt[0]-ABdeA
        BCdeB = cnt[2]-BCdeC
        if ABdeB + BCdeB <= b:
            answer([[all+ABdeA,ABdeB],[0,all],[all+BCdeB,BCdeC]])
if cnt[2] == 0:
        ABdeB = min(cnt[0],b)
        ACdeC = min(cnt[1],c)
        ABdeA = cnt[0]-ABdeB
        ACdeA = cnt[1]-ACdeC
        if ABdeA + ACdeA <= a:
            answer([[all+ABdeA,ABdeB],[ACdeA,ACdeC+all],[all,0]])
if a == 0:
    ABdeB = cnt[0]
    ACdeC = cnt[1]
    b -= ABdeB
    c -= ACdeC
    if b >= 0 and c >= 0:
        BCdeB = min(b,cnt[2])
        BCdeC = cnt[2]-BCdeB
        if BCdeC <= c:
             answer([[all,ABdeB],[0,ACdeC+all],[all+BCdeB,BCdeC]])
    b += ABdeB
    c += ACdeC
if b == 0:
    ABdeA = cnt[0]
    BCdeC = cnt[2]
    a -= ABdeA
    c -= BCdeC
    if a >= 0 and c >= 0:
        ACdeA = min(a,cnt[1])
        ACdeC = cnt[1]-ACdeA
        if ACdeC <= c:
            answer([[all+ABdeA,0],[ACdeA,ACdeC+all],[all,BCdeC]])
    a += ABdeA
    c += BCdeC
if c == 0:
    ACdeA = cnt[1]
    BCdeB = cnt[2]
    a -= ACdeA
    b -= BCdeB
    if a >= 0 and b >= 0:
        ABdeA = min(a,cnt[0])
        ABdeB = cnt[0]-ABdeA
        if ABdeB <= b:
            answer([[all+ABdeA,ABdeB],[ACdeA,all],[BCdeB+all,0]])
print("No")

Fixed, accepted submission:
n,a,b,c = map(int,input().split())
s = [str(input()) for i in range(n)]
lis = [a,b,c]
ans = ""
for i in range(n-1):
    if lis[ord(s[i][0]) - ord("A")] == 0 and lis[ord(s[i][1]) - ord("A")] == 0:
        print("No")
        exit()
    if s[i] == s[i+1]:
        if lis[ord(s[i][0])-ord("A")] == 0:
            ans += s[i][0]
            lis[ord(s[i][0])-ord("A")] += 1
            lis[ord(s[i][1])-ord("A")] -= 1
        else:
            ans += s[i][1]
            lis[ord(s[i][0])-ord("A")] -= 1
            lis[ord(s[i][1])-ord("A")] += 1
    else:
        if s[i] == "AB":
            if s[i+1] == "AC":
                if lis[1] == 0:
                    ans += "B"
                    lis[1] += 1
                    lis[0] -= 1
                else:
                    ans += "A"
                    lis[0] += 1
                    lis[1] -= 1
            else:
                if lis[0] == 0:
                    ans += "A"
                    lis[0] += 1
                    lis[1] -= 1
                else:
                    ans += "B"
                    lis[0] -= 1
                    lis[1] += 1
        elif s[i] == "AC":
            if s[i+1] == "AB":
                if lis[2] == 0:
                    ans += "C"
                    lis[2] += 1
                    lis[0] -= 1
                else:
                    ans += "A"
                    lis[0] += 1
                    lis[2] -= 1
            else:
                if lis[0] == 0:
                    ans += "A"
                    lis[0] += 1
                    lis[2] -= 1
                else:
                    ans += "C"
                    lis[0] -= 1
                    lis[2] += 1
        else:
            if s[i+1] == "AB":
                if lis[2] == 0:
                    ans += "C"
                    lis[2] += 1
                    lis[1] -= 1
                else:
                    ans += "B"
                    lis[2] -= 1
                    lis[1] += 1
            else:
                if lis[1] == 0:
                    ans += "B"
                    lis[1] += 1
                    lis[2] -= 1
                else:
                    ans += "C"
                    lis[2] += 1
                    lis[1] -= 1
if lis[ord(s[-1][0])-ord("A")] == 0:
    if lis[ord(s[-1][1])-ord("A")] == 0:
        print("No")
        exit()
    else:
        ans += s[-1][0]
else:
    ans += s[-1][1]
print("Yes")
for i in range(n):
    print(ans[i])