Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(1000000)


def recur1(a, b, c, ls: [], ans: []):
    s = ls[0]
    if s == "AB":
        if a == 0 and b == 0:
            return False, []
        elif a == 0:
            ans.append("A")
            if len(ls) == 1:
                return True, ans
            return recur1(a + 1, b - 1, c, ls[1:], ans)
        else:
            ans.append("B")
            if len(ls) == 1:
                return True, ans
            return recur1(a - 1, b + 1, c, ls[1:], ans)
    elif s == "AC":
        if a == 0 and c == 0:
            return False, []
        elif a == 0:
            ans.append("A")
            if len(ls) == 1:
                return True, ans
            return recur1(a + 1, b, c - 1, ls[1:], ans)
        else:
            ans.append("C")
            if len(ls) == 1:
                return True, ans
            return recur1(a - 1, b, c + 1, ls[1:], ans)
    else:
        if b == 0 and c == 0:
            return False, []
        elif b == 0:
            ans.append("B")
            if len(ls) == 1:
                return True, ans
            return recur1(a, b + 1, c - 1, ls[1:], ans)
        else:
            ans.append("C")
            if len(ls) == 1:
                return True, ans
            return recur1(a, b - 1, c + 1, ls[1:], ans)


def recur2(a, b, c, ls: [], ans: []):
    s = ls[0]
    ln = len(ls)
    if s == "AB":
        if a == 0 and b == 0:
            return False, []
        elif a == 0:
            ans.append("A")
            if ln == 1:
                return True, ans
            return recur2(1, b - 1, c, ls[1:], ans)
        elif b == 0:
            ans.append("B")
            if ln == 1:
                return True, ans
            return recur2(a - 1, 1, c, ls[1:], ans)
        else:
            if ln == 1:
                ans.append("A")
                return True, ans
            nex = ls[1]
            if nex == "BC":
                ans.append("B")
                ans.append("C")
                if ln == 2:
                    return True, ans
                return recur2(0, 1, 1, ls[2:], ans)
            elif nex == "AC":
                ans.append("A")
                ans.append("C")
                if ln == 2:
                    return True, ans
                return recur2(1, 0, 1, ls[2:], ans)
            else:
                ans.append("A")
                ans.append("B")
                if ln == 2:
                    return True, ans
                return recur2(1, 1, 0, ls[2:], ans)
    elif s == "AC":
        if a == 0 and c == 0:
            return False, []
        elif a == 0:
            ans.append("A")
            if ln == 1:
                return True, ans
            return recur2(a + 1, b, c - 1, ls[1:], ans)
        elif c == 0:
            ans.append("C")
            if ln == 1:
                return True, ans
            return recur2(a - 1, b, c + 1, ls[1:], ans)
        else:
            if ln == 1:
                ans.append("A")
                return True, ans
            nex = ls[1]
            if nex == "AB":
                ans.append("A")
                ans.append("B")
                if ln == 2:
                    return True, ans
                return recur2(1, 1, 0, ls[2:], ans)
            elif nex == "BC":
                ans.append("C")
                ans.append("B")
                if ln == 2:
                    return True, ans
                return recur2(0, 1, 1, ls[2:], ans)
            else:
                ans.append("A")
                ans.append("C")
                if ln == 2:
                    return True, ans
                return recur2(1, 0, 1, ls[2:], ans)
    else:
        if c == 0 and b == 0:
            return False, []
        elif c == 0:
            ans.append("C")
            if ln == 1:
                return True, ans
            return recur2(a, b - 1, c + 1, ls[1:], ans)
        elif b == 0:
            ans.append("B")
            if ln == 1:
                return True, ans
            return recur2(a, b + 1, c - 1, ls[1:], ans)
        else:
            if ln == 1:
                ans.append("C")
                return True, ans
            nex = ls[1]
            if nex == "AB":
                ans.append("B")
                ans.append("A")
                if ln == 2:
                    return True, ans
                return recur2(1, 1, 0, ls[2:], ans)
            if nex == "AC":
                ans.append("C")
                ans.append("A")
                if ln == 2:
                    return True, ans
                return recur2(1, 0, 1, ls[2:], ans)
            else:
                ans.append("B")
                ans.append("C")
                return recur2(0, 1, 1, ls[2:], ans)


def recur3(a, b, c, ls: [], ans: []):
    s = ls[0]
    ln = len(ls)
    if s == "AB":
        if a == 0 and b == 0:
            return False, []
        else:
            if a >= b:
                ans.append("B")
                if ln == 1:
                    return True, ans
                return recur3(a - 1, b + 1, c, ls[1:], ans)
            else:
                ans.append("A")
                if ln == 1:
                    return True, ans
                return recur3(a + 1, b - 1, c, ls[1:], ans)
    elif s == "BC":
        if b == 0 and c == 0:
            return False, []
        else:
            if b >= c:
                ans.append("C")
                if ln == 1:
                    return True, ans
                return recur3(a, b - 1, c+1, ls[1:], ans)
            else:
                ans.append("B")
                if ln == 1:
                    return True, ans
                return recur3(a, b + 1, c-1, ls[1:], ans)
    else:
        if a == 0 and c == 0:
            return False, []
        else:
            if a >= c:
                ans.append("C")
                if ln == 1:
                    return True, ans
                return recur3(a - 1, b, c+1, ls[1:], ans)
            else:
                ans.append("A")
                if ln == 1:
                    return True, ans
                return recur3(a + 1, b, c-1, ls[1:], ans)


def main():
    n, a, b, c = map(int, input().split())
    s_ls = []
    for i in range(n):
        s_ls.append(input())

    if a + b + c == 0:
        print("No")
        return

    res = True
    ans = []
    if a + b + c == 1:
        res, ans = recur1(a, b, c, s_ls, ans)
    elif a + b + c == 2:
        res, ans = recur2(a, b, c, s_ls, ans)
    else:
        res, ans = recur3(a, b, c, s_ls, ans)

    if res:
        print("Yes")
        for x in ans:
            print(x)
    else:
        print("No")


main()


Fixed submission:
def solve(n, a, b, c, s_ls):
    ans = []
    for i in range(n):
        s = s_ls[i]
        if s == "AB":
            if a == 0 and b == 0:
                return False, []
            elif a == 0:
                ans.append("A")
                a += 1
                b -= 1
            elif b == 0:
                ans.append("B")
                a -= 1
                b += 1
            elif a == b == 1 and c == 0:
                if i == n - 1:
                    ans.append("A")
                    a += 1
                    b -= 1
                else:
                    nex = s_ls[i + 1]
                    if nex == "BC":
                        ans.append("B")
                        a -= 1
                        b += 1
                    else:
                        ans.append("A")
                        a += 1
                        b -= 1
            else:
                if a >= b:
                    ans.append("B")
                    a -= 1
                    b += 1
                else:
                    ans.append("A")
                    a += 1
                    b -= 1
        elif s == "BC":
            if b == 0 and c == 0:
                return False, []
            elif c == 0:
                ans.append("C")
                b -= 1
                c += 1
            elif b == 0:
                ans.append("B")
                b += 1
                c -= 1
            elif c == b == 1 and a == 0:
                if i == n - 1:
                    ans.append("C")
                    b -= 1
                    c += 1
                else:
                    nex = s_ls[i + 1]
                    if nex == "AB":
                        ans.append("B")
                        b += 1
                        c -= 1
                    else:
                        ans.append("C")
                        b -= 1
                        c += 1
            else:
                if c >= b:
                    ans.append("B")
                    b += 1
                    c -= 1
                else:
                    ans.append("C")
                    b -= 1
                    c += 1
        elif s == "AC":
            if a == 0 and c == 0:
                return False, []
            elif a == 0:
                ans.append("A")
                a += 1
                c -= 1
            elif c == 0:
                ans.append("C")
                a -= 1
                c += 1
            elif a == c == 1 and b == 0:
                if i == n - 1:
                    ans.append("A")
                    a += 1
                    c -= 1
                else:
                    nex = s_ls[i + 1]
                    if nex == "AB":
                        ans.append("A")
                        a += 1
                        c -= 1
                    else:
                        ans.append("C")
                        a -= 1
                        c += 1
            else:
                if a >= c:
                    ans.append("C")
                    a -= 1
                    c += 1
                else:
                    ans.append("A")
                    a += 1
                    c -= 1
    return True, ans


def main():
    n, a, b, c = map(int, input().split())
    s_ls = []
    for i in range(n):
        s_ls.append(input())

    res, ans = solve(n, a, b, c, s_ls)
    if not res:
        print("No")
    else:
        print("Yes")
        for x in ans:
            print(x)


main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(1000000)


def recur1(a, b, c, ls: [], ans: []):
    s = ls[0]
    if s == "AB":
        if a == 0 and b == 0:
            return False, []
        elif a == 0:
            ans.append("A")
            if len(ls) == 1:
                return True, ans
            return recur1(a + 1, b - 1, c, ls[1:], ans)
        else:
            ans.append("B")
            if len(ls) == 1:
                return True, ans
            return recur1(a - 1, b + 1, c, ls[1:], ans)
    elif s == "AC":
        if a == 0 and c == 0:
            return False, []
        elif a == 0:
            ans.append("A")
            if len(ls) == 1:
                return True, ans
            return recur1(a + 1, b, c - 1, ls[1:], ans)
        else:
            ans.append("C")
            if len(ls) == 1:
                return True, ans
            return recur1(a - 1, b, c + 1, ls[1:], ans)
    else:
        if b == 0 and c == 0:
            return False, []
        elif b == 0:
            ans.append("B")
            if len(ls) == 1:
                return True, ans
            return recur1(a, b + 1, c - 1, ls[1:], ans)
        else:
            ans.append("C")
            if len(ls) == 1:
                return True, ans
            return recur1(a, b - 1, c + 1, ls[1:], ans)


def recur2(a, b, c, ls: [], ans: []):
    s = ls[0]
    ln = len(ls)
    if s == "AB":
        if a == 0 and b == 0:
            return False, []
        elif a == 0:
            ans.append("A")
            if ln == 1:
                return True, ans
            return recur2(a + 1, b - 1, c, ls[1:], ans)
        elif b == 0:
            ans.append("B")
            if ln == 1:
                return True, ans
            return recur2(a - 1, b + 1, c, ls[1:], ans)
        else:
            if ln == 1:
                ans.append("A")
                return True, ans
            nex = ls[1]
            if nex == "BC":
                ans.append("B")
                return recur2(a - 1, b + 1, c, ls[1:], ans)
            else:
                ans.append("A")
                return recur2(a + 1, b - 1, c, ls[1:], ans)
    elif s == "AC":
        if a == 0 and c == 0:
            return False, []
        elif a == 0:
            ans.append("A")
            if ln == 1:
                return True, ans
            return recur2(a + 1, b, c - 1, ls[1:], ans)
        elif c == 0:
            ans.append("C")
            if ln == 1:
                return True, ans
            return recur2(a - 1, b, c + 1, ls[1:], ans)
        else:
            if ln == 1:
                ans.append("A")
                return True, ans
            nex = ls[1]
            if nex == "AB":
                ans.append("A")
                return recur2(a + 1, b, c - 1, ls[1:], ans)
            else:
                ans.append("C")
                return recur2(a - 1, b, c + 1, ls[1:], ans)
    else:
        if c == 0 and b == 0:
            return False, []
        elif c == 0:
            ans.append("C")
            if ln == 1:
                return True, ans
            return recur2(a, b - 1, c + 1, ls[1:], ans)
        elif b == 0:
            ans.append("B")
            if ln == 1:
                return True, ans
            return recur2(a, b + 1, c - 1, ls[1:], ans)
        else:
            if ln == 1:
                ans.append("C")
                return True, ans
            nex = ls[1]
            if nex == "AB":
                ans.append("B")
                return recur2(a, b + 1, c - 1, ls[1:], ans)
            else:
                ans.append("C")
                return recur2(a, b - 1, c + 1, ls[1:], ans)


def recur3(a, b, c, ls: [], ans: []):
    s = ls[0]
    ln = len(ls)
    if s == "AB":
        if a == 0 and b == 0:
            return False, []
        else:
            if a >= b:
                ans.append("B")
                if ln == 1:
                    return True, ans
                return recur3(a - 1, b + 1, c, ls[1:], ans)
            else:
                ans.append("A")
                if ln == 1:
                    return True, ans
                return recur3(a + 1, b - 1, c, ls[1:], ans)
    elif s == "BC":
        if b == 0 and c == 0:
            return False, []
        else:
            if b >= c:
                ans.append("C")
                if ln == 1:
                    return True, ans
                return recur3(a, b - 1, c+1, ls[1:], ans)
            else:
                ans.append("B")
                if ln == 1:
                    return True, ans
                return recur3(a, b + 1, c-1, ls[1:], ans)
    else:
        if a == 0 and c == 0:
            return False, []
        else:
            if a >= c:
                ans.append("C")
                if ln == 1:
                    return True, ans
                return recur3(a - 1, b, c+1, ls[1:], ans)
            else:
                ans.append("A")
                if ln == 1:
                    return True, ans
                return recur3(a + 1, b, c-1, ls[1:], ans)


def main():
    n, a, b, c = map(int, input().split())
    s_ls = []
    for i in range(n):
        s_ls.append(input())

    if a + b + c == 0:
        print("No")
        return
    
    res = True
    ans = []
    if a + b + c == 1:
        res, ans = recur1(a, b, c, s_ls, ans)
    elif a + b + c == 2:
        res, ans = recur2(a, b, c, s_ls, ans)
    else:
        res, ans = recur3(a, b, c, s_ls, ans)

    if res:
        print("Yes")
        for x in ans:
            print(x)
    else:
        print("No")


main()


Fixed submission:
def solve(n, a, b, c, s_ls):
    ans = []
    for i in range(n):
        s = s_ls[i]
        if s == "AB":
            if a == 0 and b == 0:
                return False, []
            elif a == 0:
                ans.append("A")
                a += 1
                b -= 1
            elif b == 0:
                ans.append("B")
                a -= 1
                b += 1
            elif a == b == 1 and c == 0:
                if i == n - 1:
                    ans.append("A")
                    a += 1
                    b -= 1
                else:
                    nex = s_ls[i + 1]
                    if nex == "BC":
                        ans.append("B")
                        a -= 1
                        b += 1
                    else:
                        ans.append("A")
                        a += 1
                        b -= 1
            else:
                if a >= b:
                    ans.append("B")
                    a -= 1
                    b += 1
                else:
                    ans.append("A")
                    a += 1
                    b -= 1
        elif s == "BC":
            if b == 0 and c == 0:
                return False, []
            elif c == 0:
                ans.append("C")
                b -= 1
                c += 1
            elif b == 0:
                ans.append("B")
                b += 1
                c -= 1
            elif c == b == 1 and a == 0:
                if i == n - 1:
                    ans.append("C")
                    b -= 1
                    c += 1
                else:
                    nex = s_ls[i + 1]
                    if nex == "AB":
                        ans.append("B")
                        b += 1
                        c -= 1
                    else:
                        ans.append("C")
                        b -= 1
                        c += 1
            else:
                if c >= b:
                    ans.append("B")
                    b += 1
                    c -= 1
                else:
                    ans.append("C")
                    b -= 1
                    c += 1
        elif s == "AC":
            if a == 0 and c == 0:
                return False, []
            elif a == 0:
                ans.append("A")
                a += 1
                c -= 1
            elif c == 0:
                ans.append("C")
                a -= 1
                c += 1
            elif a == c == 1 and b == 0:
                if i == n - 1:
                    ans.append("A")
                    a += 1
                    c -= 1
                else:
                    nex = s_ls[i + 1]
                    if nex == "AB":
                        ans.append("A")
                        a += 1
                        c -= 1
                    else:
                        ans.append("C")
                        a -= 1
                        c += 1
            else:
                if a >= c:
                    ans.append("C")
                    a -= 1
                    c += 1
                else:
                    ans.append("A")
                    a += 1
                    c -= 1
    return True, ans


def main():
    n, a, b, c = map(int, input().split())
    s_ls = []
    for i in range(n):
        s_ls.append(input())

    res, ans = solve(n, a, b, c, s_ls)
    if not res:
        print("No")
    else:
        print("Yes")
        for x in ans:
            print(x)


main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(1000000)


def recur(current_a, current_b, current_c, ls: [], ans: []):
    s = ls[0]
    if s == "AB":
        if current_a == 0 and current_b == 0:
            return False, []
        elif current_a == 0:
            ans.append("A")
            if len(ls) == 1:
                return True, ans
            ans_1 = ans[:]
            return recur(current_a + 1, current_b - 1, current_c, ls[1:], ans_1)
        elif current_b == 0:
            ans.append("B")
            if len(ls) == 1:
                return True, ans
            ans_1 = ans[:]
            return recur(current_a - 1, current_b + 1, current_c, ls[1:], ans_1)
        else:
            if len(ls) == 1:
                ans.append("A")
                return True, ans

            ans_1 = ans[:]
            ans_1.append("A")
            res, ans_1 = recur(current_a + 1, current_b - 1, current_c, ls[1:], ans_1)
            if res:
                return True, ans_1

            ans.append("B")
            return recur(current_a - 1, current_b + 1, current_c, ls[1:], ans)
    elif s == "AC":
        if current_a == 0 and current_c == 0:
            return False, []
        elif current_a == 0:
            ans.append("A")
            if len(ls) == 1:
                return True, ans
            return recur(current_a + 1, current_b, current_c - 1, ls[1:], ans)
        elif current_c == 0:
            ans.append("C")
            if len(ls) == 1:
                return True, ans
            return recur(current_a - 1, current_b, current_c + 1, ls[1:], ans)
        else:
            if len(ls) == 1:
                ans.append("A")
                return True, ans

            ans_1 = ans[:]
            ans_1.append("A")
            res, ans_1 =recur(current_a + 1, current_b, current_c - 1, ls[1:], ans_1)
            if res:
                return True, ans_1

            ans.append("C")
            return recur(current_a - 1, current_b, current_c + 1, ls[1:], ans)
    elif s == "BC":
        if current_b == 0 and current_c == 0:
            return False, []
        elif current_b == 0:
            ans.append("B")
            if len(ls) == 1:
                return True, ans
            return recur(current_a, current_b + 1, current_c - 1, ls[1:], ans)
        elif current_c == 0:
            ans.append("C")
            if len(ls) == 1:
                return True, ans
            return recur(current_a, current_b - 1, current_c + 1, ls[1:], ans)
        else:
            if len(ls) == 1:
                ans.append("B")
                return True, ans

            ans_1 = ans[:]
            ans_1.append("B")
            res, ans_1 = recur(current_a, current_b + 1, current_c - 1, ls[1:], ans_1)
            if res:
                return True, ans_1

            ans.append("C")
            return recur(current_a, current_b - 1, current_c + 1, ls[1:], ans)


def main():
    n, a, b, c = map(int, input().split())
    s_ls = []
    for i in range(n):
        s_ls.append(input())

    ans = []
    res, ans = recur(a, b, c, s_ls, ans)
    if res:
        print("Yes")
        for x in ans:
            print(x)
    else:
        print("No")


main()


Fixed submission:
def solve(n, a, b, c, s_ls):
    ans = []
    for i in range(n):
        s = s_ls[i]
        if s == "AB":
            if a == 0 and b == 0:
                return False, []
            elif a == 0:
                ans.append("A")
                a += 1
                b -= 1
            elif b == 0:
                ans.append("B")
                a -= 1
                b += 1
            elif a == b == 1 and c == 0:
                if i == n - 1:
                    ans.append("A")
                    a += 1
                    b -= 1
                else:
                    nex = s_ls[i + 1]
                    if nex == "BC":
                        ans.append("B")
                        a -= 1
                        b += 1
                    else:
                        ans.append("A")
                        a += 1
                        b -= 1
            else:
                if a >= b:
                    ans.append("B")
                    a -= 1
                    b += 1
                else:
                    ans.append("A")
                    a += 1
                    b -= 1
        elif s == "BC":
            if b == 0 and c == 0:
                return False, []
            elif c == 0:
                ans.append("C")
                b -= 1
                c += 1
            elif b == 0:
                ans.append("B")
                b += 1
                c -= 1
            elif c == b == 1 and a == 0:
                if i == n - 1:
                    ans.append("C")
                    b -= 1
                    c += 1
                else:
                    nex = s_ls[i + 1]
                    if nex == "AB":
                        ans.append("B")
                        b += 1
                        c -= 1
                    else:
                        ans.append("C")
                        b -= 1
                        c += 1
            else:
                if c >= b:
                    ans.append("B")
                    b += 1
                    c -= 1
                else:
                    ans.append("C")
                    b -= 1
                    c += 1
        elif s == "AC":
            if a == 0 and c == 0:
                return False, []
            elif a == 0:
                ans.append("A")
                a += 1
                c -= 1
            elif c == 0:
                ans.append("C")
                a -= 1
                c += 1
            elif a == c == 1 and b == 0:
                if i == n - 1:
                    ans.append("A")
                    a += 1
                    c -= 1
                else:
                    nex = s_ls[i + 1]
                    if nex == "AB":
                        ans.append("A")
                        a += 1
                        c -= 1
                    else:
                        ans.append("C")
                        a -= 1
                        c += 1
            else:
                if a >= c:
                    ans.append("C")
                    a -= 1
                    c += 1
                else:
                    ans.append("A")
                    a += 1
                    c -= 1
    return True, ans


def main():
    n, a, b, c = map(int, input().split())
    s_ls = []
    for i in range(n):
        s_ls.append(input())

    res, ans = solve(n, a, b, c, s_ls)
    if not res:
        print("No")
    else:
        print("Yes")
        for x in ans:
            print(x)


main()