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):
n,a,b,c=map(int,input().split())
if a+b+c==0:
    print("No")
elif a+b+c==1:
    d=[]
    for i in range(n):
        s=input()
        if s=="AB":
            if a+b==0:
                print("No")
                exit()
            else:
                if a==0:
                    d.append("A")
                else:
                    d.append("B")
                a,b=b,a
        if s=="BC":
            if c+b==0:
                print("No")
                exit()
            else:
                if b==0:
                    d.append("B")
                else:
                    d.append("C")
                c,b=b,c
        if s=="AC":
            if a+c==0:
                print("No")
                exit()
            else:
                if a==0:
                    d.append("A")
                else:
                    d.append("C")
                a,c=c,a 
    print("Yes")
    for i in d:
        print(i)
else:
    d=[]
    s=[input()for i in range(n)]+["AB"]
    for i in range(n):
        if s[i]=="AB":
            if a+b==0:
                print("No")
                exit()
            if a+b+c==2 and a==b==1 and s[i+1]!=s[i]:
                if s[i]=="AC":
                    d.append("A")
                    a+=1
                    b-=1
                else:
                    d.append("B")
                    b+=1
                    a-=1
            elif a==0:
                d.append("A")
                a+=1
                b-=1
            else:
                d.append("B")
                b+=1
                a-=1
        if s=="BC":
            if c+b==0:
                print("No")
                exit()
            if a+b+c==2 and c==b==1 and s[i+1]!=s[i]:
                if s[i]=="AB":
                    d.append("B")
                    c-=1
                    b+=1
                else:
                    d.append("C")
                    c+=1
                    b-=1
            elif b==0:
                d.append("B")
                b+=1
                c-=1
            else:
                d.append("C")
                c+=1
                b-=1
        if s=="AC":
            if c+a==0:
                print("No")
                exit()
            if a+b+c==2 and c==a==1 and s[i+1]!=s[i]:
                if s[i]=="AB":
                    d.append("A")
                    a+=1
                    c-=1
                else:
                    d.append("C")
                    c+=1
                    a-=1
            elif a==0:
                d.append("A")
                a+=1
                c-=1
            else:
                d.append("C")
                c+=1
                a-=1
    print("Yes")
    for i in d:
        print(i)

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