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())
ss=['' for _ in range(n)]
ans=['' for _ in range(n)]
wa=a+b+c
for i in range(n):
    s=input()
    ss[i]=s
i=0
if wa==0:
    print('No')
    exit()
elif wa==1:
    for s in ss:
        if s=='AB':
            if c:
                print('No')
                exit()
            elif b:
                a+=1
                b-=1
                ans[i]='A'
            elif a:
                b+=1
                a-=1
                ans[i]='B'
        elif s=='AC':
            if b:
                print('No')
                exit()
            elif a:
                c+=1
                a-=1
                ans[i]='C'
            elif c:
                a+=1
                c-=1
                ans[i]='A'
        elif s=='BC':
            if a:
                print('No')
                exit()
            elif b:
                c+=1
                b-=1
                ans[i]='C'
            elif c:
                b+=1
                c-=1
                ans[i]='B'
        i+=1
elif wa==2:
    for s in ss:
        if s=='AB':
            if a==0 and b==0:
                print('No')
                exit()
            elif a==0:
                a+=1
                b-=1
                ans[i]='A'
            elif b==0:
                b+=1
                a-=1
                ans[i]='B'
            elif a==1 and b==1:
                if i==n-1:
                    ans[i]='A'
                else:
                    if ss[i+1]=='AC' or ss[i+1]=='AB':
                        a+=1
                        b-=1
                        ans[i]='A'
                    elif ss[i+1]=='BC':
                        b+=1
                        a-=1
                        ans[i]='B'
        elif s=='AC':
            if a==0 and c==0:
                print('No')
                exit()
            elif a==0:
                a+=1
                c-=1
                ans[i]='A'
            elif c==0:
                c+=1
                a-=1
                ans[i]='C'
            elif a==1 and c==1:
                if i==n-1:
                    ans[i]='A'
                else:
                    if ss[i+1]=='AC' or ss[i+1]=='AB':
                        a+=1
                        c-=1
                        ans[i]='A'
                    elif ss[i+1]=='BC':
                        c+=1
                        a-=1
                        ans[i]='C'
        elif s=='BC':
            if b==0 and c==0:
                print('No')
                exit()
            elif b==0:
                b+=1
                c-=1
                ans[i]='B'
            elif c==0:
                c+=1
                b-=1
                ans[i]='C'
            elif b==1 and c==1:
                if i==n-1:
                    ans[i]='B'
                else:
                    if ss[i+1]=='BC' or ss[i+1]=='AB':
                        b+=1
                        c-=1
                        ans[i]='B'
                    elif ss[i+1]=='AC':
                        c+=1
                        b-=1
                        ans[i]='C'
        i+=1
elif wa>2:
    for i in range(n):
        s=ss[i]
        if s=='AB':
            if a==0 and b==0:
                print('No')
                exit()
            elif a==0:
                a+=1
                b-=1
                ans[i]='A'
            elif b==0:
                b+=1
                a-=1
                ans[i]='B'
            else:
                if i==n-1:
                    ans[i]='A'
                    a+=1
                    b-=1
                else:
                    if b>=a:
                        a+=1
                        b-=1
                        ans[i]='A'
                    else:
                        b+=1
                        a-=1
                        ans[i]='B'
        elif s=='AC':
            if a==0 and c==0:
                print('No')
                exit()
            elif a==0:
                a+=1
                c-=1
                ans[i]='A'
            elif c==0:
                c+=1
                a-=1
                ans[i]='C'
            else:
                if i==n-1:
                    ans[i]='A'
                    a+=1
                    c-=1
                else:
                    if c>=a:
                        a+=1
                        c-=1
                        ans[i]='A'
                    else:
                        c+=1
                        a-=1
                        ans[i]='C'
        elif s=='BC':
            if b==0 and c==0:
                print('No')
                exit()
            elif b==0:
                b+=1
                c-=1
                ans[i]='B'
            elif c==0:
                c+=1
                b-=1
                ans[i]='C'
            else:
                if i==n-1:
                    ans[i]='B'
                    b+=1
                    c-=1
                else:
                    if c>=b:
                        b+=1
                        c-=1
                        ans[i]='B'
                    else:
                        c+=1
                        b-=1
                        ans[i]='C'
        print(i,a,b,c)
print('Yes')
for x in ans:
    print(x)

Fixed, accepted submission:
n,a,b,c = map(int,input().split())
ss=['' for _ in range(n)]
ans=['' for _ in range(n)]
wa=a+b+c
for i in range(n):
    s=input()
    ss[i]=s
i=0
if wa==0:
    print('No')
    exit()
elif wa==1:
    for s in ss:
        if s=='AB':
            if c:
                print('No')
                exit()
            elif b:
                a+=1
                b-=1
                ans[i]='A'
            elif a:
                b+=1
                a-=1
                ans[i]='B'
        elif s=='AC':
            if b:
                print('No')
                exit()
            elif a:
                c+=1
                a-=1
                ans[i]='C'
            elif c:
                a+=1
                c-=1
                ans[i]='A'
        elif s=='BC':
            if a:
                print('No')
                exit()
            elif b:
                c+=1
                b-=1
                ans[i]='C'
            elif c:
                b+=1
                c-=1
                ans[i]='B'
        i+=1
elif wa==2:
    for s in ss:
        if s=='AB':
            if a==0 and b==0:
                print('No')
                exit()
            elif a==0:
                a+=1
                b-=1
                ans[i]='A'
            elif b==0:
                b+=1
                a-=1
                ans[i]='B'
            elif a==1 and b==1:
                if i==n-1:
                    ans[i]='A'
                else:
                    if ss[i+1]=='AC' or ss[i+1]=='AB':
                        a+=1
                        b-=1
                        ans[i]='A'
                    elif ss[i+1]=='BC':
                        b+=1
                        a-=1
                        ans[i]='B'
        elif s=='AC':
            if a==0 and c==0:
                print('No')
                exit()
            elif a==0:
                a+=1
                c-=1
                ans[i]='A'
            elif c==0:
                c+=1
                a-=1
                ans[i]='C'
            elif a==1 and c==1:
                if i==n-1:
                    ans[i]='A'
                else:
                    if ss[i+1]=='AC' or ss[i+1]=='AB':
                        a+=1
                        c-=1
                        ans[i]='A'
                    elif ss[i+1]=='BC':
                        c+=1
                        a-=1
                        ans[i]='C'
        elif s=='BC':
            if b==0 and c==0:
                print('No')
                exit()
            elif b==0:
                b+=1
                c-=1
                ans[i]='B'
            elif c==0:
                c+=1
                b-=1
                ans[i]='C'
            elif b==1 and c==1:
                if i==n-1:
                    ans[i]='B'
                else:
                    if ss[i+1]=='BC' or ss[i+1]=='AB':
                        b+=1
                        c-=1
                        ans[i]='B'
                    elif ss[i+1]=='AC':
                        c+=1
                        b-=1
                        ans[i]='C'
        i+=1
elif wa>2:
    for i in range(n):
        s=ss[i]
        if s=='AB':
            if a==0 and b==0:
                print('No')
                exit()
            elif a==0:
                a+=1
                b-=1
                ans[i]='A'
            elif b==0:
                b+=1
                a-=1
                ans[i]='B'
            else:
                if i==n-1:
                    ans[i]='A'
                    a+=1
                    b-=1
                else:
                    if b>=a:
                        a+=1
                        b-=1
                        ans[i]='A'
                    else:
                        b+=1
                        a-=1
                        ans[i]='B'
        elif s=='AC':
            if a==0 and c==0:
                print('No')
                exit()
            elif a==0:
                a+=1
                c-=1
                ans[i]='A'
            elif c==0:
                c+=1
                a-=1
                ans[i]='C'
            else:
                if i==n-1:
                    ans[i]='A'
                    a+=1
                    c-=1
                else:
                    if c>=a:
                        a+=1
                        c-=1
                        ans[i]='A'
                    else:
                        c+=1
                        a-=1
                        ans[i]='C'
        elif s=='BC':
            if b==0 and c==0:
                print('No')
                exit()
            elif b==0:
                b+=1
                c-=1
                ans[i]='B'
            elif c==0:
                c+=1
                b-=1
                ans[i]='C'
            else:
                if i==n-1:
                    ans[i]='B'
                    b+=1
                    c-=1
                else:
                    if c>=b:
                        b+=1
                        c-=1
                        ans[i]='B'
                    else:
                        c+=1
                        b-=1
                        ans[i]='C'
        #print(i,a,b,c)
print('Yes')
for x in ans:
    print(x)