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())
ans_list= []
if A+B+C == A or A+B+C == B or A+B+C == C:
    for i in range(N):
        s = input()
        if s == "AB" and A == 0 and B == 0:
            print("No")
            break
        elif s == "BC" and B == 0 and C == 0:
            print("No")
            break
        elif s == "AC" and A == 0 and C == 0:
            print("No")
            break
        else:
            if s == "AB":
                if A == 0:
                    A += 1
                    B -= 1
                    ans_list.append(["A"])
                else:
                    A -= 1
                    B += 1
                    ans_list.append(["B"])
            elif s == "AC":
                if A == 0:
                    A += 1
                    C -= 1
                    ans_list.append(["A"])
                else:
                    A -= 1
                    C += 1
                    ans_list.append(["C"])
            else:
                if B == 0:
                    B += 1
                    C -= 1
                    ans_list.append(["B"])
                else:
                    B -= 1
                    C += 1
                    ans_list.append(["C"])
else:
    for i in range(N):
        s = input()
        if s == "AB":
            if A == 0:
                A += 1
                B -= 1
                ans_list.append(["A"])
            else:
                A -= 1
                B += 1
                ans_list.append(["B"])
        elif s == "AC":
            if A == 0:
                A += 1
                C -= 1
                ans_list.append(["A"])
            else:
                A -= 1
                C += 1
                ans_list.append(["C"])
        else:
            if B == 0:
                B += 1
                C -= 1
                ans_list.append(["B"])
            else:
                B -= 1
                C += 1
                ans_list.append(["C"])
if len(ans_list) == N:
    print("Yes")
    for i in range(N):
        print(*ans_list[i])


Fixed, accepted submission:
N,A,B,C = map(int,input().split())
ans_list= []
chk = 0
count = 1
for i in range(N):
    s = input()
    if chk == 1:
        if s == "AC":
            num = count
            for j in reversed(range(count)):
                if num%2 == 1:
                    A += 1
                    B -= 1
                    ans_list.append(["A"])
                else:
                    A -= 1
                    B += 1
                    ans_list.append(["B"])
                num -= 1
            chk = 0
            count = 1
        elif s == "BC":
            num = count
            for j in reversed(range(count)):
                if num%2 == 1:
                    A -= 1
                    B += 1
                    ans_list.append(["B"])
                else:
                    A += 1
                    B -= 1
                    ans_list.append(["A"])
                num -= 1
            chk = 0
            count = 1
        else:
            count += 1
            continue
    elif chk == 2:
        if s == "AB":
            num = count
            for j in reversed(range(count)):
                if num%2 == 1:
                    A += 1
                    C -= 1
                    ans_list.append(["A"])
                else:
                    A -= 1
                    C += 1
                    ans_list.append(["C"])
                num -= 1
            chk = 0
            count = 1
        elif s == "BC":
            num = count
            for j in reversed(range(count)):
                if num%2 == 1:
                    A -= 1
                    C += 1
                    ans_list.append(["C"])
                else:
                    A += 1
                    C -= 1
                    ans_list.append(["A"])
                num -= 1
            chk = 0
            count = 1
        else:
            count += 1
            continue
    elif chk == 3:
        if s == "AB":
            num = count
            for j in reversed(range(count)):
                if num%2 == 1:
                    B += 1
                    C -= 1
                    ans_list.append(["B"])
                else:
                    B -= 1
                    C += 1
                    ans_list.append(["C"])
                num -= 1
            chk = 0
            count = 1
        elif s == "AC":
            num = count
            for j in reversed(range(count)):
                if num%2 == 1:
                    B -= 1
                    C += 1
                    ans_list.append(["C"])
                else:
                    B += 1
                    C -= 1
                    ans_list.append(["B"])
                num -= 1
            chk = 0
            count = 1
        else:
            count += 1
            continue
    if s == "AB" and A == 0 and B == 0:
        print("No")
        break
    elif s == "BC" and B == 0 and C == 0:
        print("No")
        break
    elif s == "AC" and A == 0 and C == 0:
        print("No")
        break
    else:
        if s == "AB":
            if A == 0:
                A += 1
                B -= 1
                ans_list.append(["A"])
            elif B == 0:
                A -= 1
                B += 1
                ans_list.append(["B"])
            elif A == 1 and B != 1 :
                A += 1
                B -= 1
                ans_list.append(["A"])
            elif B == 1 and A != 1:
                A -= 1
                B += 1
                ans_list.append(["B"])
            elif A == 1 and B == 1:
                chk = 1
            else:
                A += 1
                B -= 1
                ans_list.append(["A"])
        elif s == "AC":
            if A == 0:
                A += 1
                C -= 1
                ans_list.append(["A"])
            elif C == 0:
                A -= 1
                C += 1
                ans_list.append(["C"])
            elif A == 1 and C != 1 :
                A += 1
                C -= 1
                ans_list.append(["A"])
            elif C == 1 and A != 1:
                A -= 1
                C += 1
                ans_list.append(["C"])
            elif A == 1 and C == 1:
                chk = 2
            else:
                A += 1
                C -= 1
                ans_list.append(["A"])
        else:
            if B == 0:
                B += 1
                C -= 1
                ans_list.append(["B"])
            elif C == 0:
                B -= 1
                C += 1
                ans_list.append(["C"])
            elif B == 1 and C != 1 :
                B += 1
                C -= 1
                ans_list.append(["B"])
            elif C == 1 and B != 1:
                B -= 1
                C += 1
                ans_list.append(["C"])
            elif B == 1 and C == 1:
                chk = 3
            else:
                B += 1
                C -= 1
                ans_list.append(["B"])
if chk == 1:
    for i in range(count):
        if i%2 == 0:
            A += 1
            B -= 1
            ans_list.append(["A"])
        else:
            A -= 1
            B += 1
            ans_list.append(["B"])
elif chk == 2:
    for i in range(count):
        if i%2 == 0:
            A += 1
            C -= 1
            ans_list.append(["A"])
        else:
            A -= 1
            C += 1
            ans_list.append(["C"])
elif chk == 3:
    for i in range(count):
        if i%2 == 0:
            B += 1
            C -= 1
            ans_list.append(["B"])
        else:
            B -= 1
            C += 1
            ans_list.append(["C"])
if len(ans_list) == N:
    print("Yes")
    for i in range(N):
        print(*ans_list[i])