Buggy python submission (verdict: Runtime Error):
import sys

f = open("C:/Users/naoki/Desktop/Atcoder/input.txt")

 #入力
N, A, B, C = map(int, f.readline().split())
stock = [A, B, C]

s = [f.readline().rstrip('\n') for _ in range(N)]
sum_num = sum(list([A, B, C]))
to_char = ["A","B","C"]

target = []
for i in range(N):
    if s[i] == "AB":
        target.append([0,1])
    elif s[i] == "BC":
        target.append([1,2])
    else:
        target.append([0,2])
if sum_num == 0:
    print("No")
    sys.exit()
elif sum_num == 1:
    answer = []
    for i in range(N):
        if stock[target[i][0]] == 1:
            stock[target[i][0]] -= 1
            stock[target[i][1]] += 1
            answer.append(target[i][1])
        elif stock[target[i][1]] == 1:
            stock[target[i][1]] -= 1
            stock[target[i][0]] += 1
            answer.append(target[i][0])
        else :
            print("No")
            sys.exit()
    print("Yes")
    for i in range(N):
        to_char[answer[i]]
elif sum_num >= 2:
    if stock[target[0][0]] == 0 and stock[target[0][1]] == 0:
        print("No")
        sys.exit()
    else:
        print("Yes")
        for i in range(N-1):
            if target[i][0] in target[i+1] and stock[target[i][1]] >= 1:
                stock[target[i][0]] += 1
                stock[target[i][1]] -= 1
                print(to_char[target[i][0]])
            elif stock[target[i][0]] >= 1:
                stock[target[i][1]] += 1
                stock[target[i][0]] -= 1
            else:
                stock[target[i][0]] += 1
                stock[target[i][1]] -= 1
                print(to_char[target[i][1]])
        if stock[target[-1][0]] == 0:
            print(to_char[target[-1][0]])
        else:
            print(to_char[target[-1][1]])


Fixed submission:
import sys


N, A, B, C = map(int, input().split())
stock = [A, B, C]

s = [input().rstrip('\n') for _ in range(N)]
sum_num = sum(list([A, B, C]))
to_char = ["A","B","C"]

target = []
for i in range(N):
    if s[i] == "AB":
        target.append([0,1])
    elif s[i] == "BC":
        target.append([1,2])
    else:
        target.append([0,2])
if sum_num == 0:
    print("No")
    sys.exit()
elif sum_num == 1:
    answer = []
    for i in range(N):
        if stock[target[i][0]] == 1:
            stock[target[i][0]] -= 1
            stock[target[i][1]] += 1
            answer.append(target[i][1])
        elif stock[target[i][1]] == 1:
            stock[target[i][1]] -= 1
            stock[target[i][0]] += 1
            answer.append(target[i][0])
        else :
            print("No")
            sys.exit()
    print("Yes")
    for i in range(N):
        print(to_char[answer[i]])
elif sum_num >= 2:
    if stock[target[0][0]] == 0 and stock[target[0][1]] == 0:
        print("No")
        sys.exit()
    else:
        print("Yes")
        for i in range(N-1):
            if target[i][0] in target[i+1] and stock[target[i][1]] >= 1:
                stock[target[i][0]] += 1
                stock[target[i][1]] -= 1
                print(to_char[target[i][0]])
            elif stock[target[i][0]] >= 1:
                stock[target[i][1]] += 1
                stock[target[i][0]] -= 1
                print(to_char[target[i][1]])
            else:
                stock[target[i][0]] += 1
                stock[target[i][1]] -= 1
                print(to_char[target[i][0]])
        if stock[target[-1][0]] == 0:
            print(to_char[target[-1][0]])
        else:
            print(to_char[target[-1][1]])

Buggy python submission (verdict: Runtime Error):
import sys


N, A, B, C = map(int, inpute().split())
stock = [A, B, C]

s = [input() for _ in range(N)]
sum_num = sum(list([A, B, C]))
to_char = ["A","B","C"]

target = []
for i in range(N):
    if s[i] == "AB":
        target.append([0,1])
    elif s[i] == "BC":
        target.append([1,2])
    else:
        target.append([0,2])

if sum_num == 0:
    print("No")
    sys.exit()
elif sum_num == 1:
    answer = []
    for i in range(N):
        if stock[target[i][0]] == 1:
            stock[target[i][0]] -= 1
            stock[target[i][1]] += 1
            answer.append(target[i][1])
        elif stock[target[i][1]] == 1:
            stock[target[i][1]] -= 1
            stock[target[i][0]] += 1
            answer.append(target[i][0])
        else :
            print("No")
            sys.exit()
    print("Yes")
    for i in range(N):
        to_char[answer[i]]
elif sum_num >= 2:
    if stock[target[0][0]] == 0 and stock[target[0][1]] == 0:
        print("No")
        sys.exit()
    else:
        print("Yes")
        for i in range(N-1):
            if target[i][0] in target[i+1] and stock[target[i][1]] >= 1:
                stock[target[i][0]] += 1
                stock[target[i][1]] -= 1
                print(to_char[target[i][0]])
            else:
                stock[target[i][1]] += 1
                stock[target[i][0]] -= 1
                print(to_char[target[i][1]])
        if stock[target[-1][0]] == 0:
            print(to_char[target[-1][0]])
        else:
            print(to_char[target[-1][1]])


Fixed submission:
import sys


N, A, B, C = map(int, input().split())
stock = [A, B, C]

s = [input().rstrip('\n') for _ in range(N)]
sum_num = sum(list([A, B, C]))
to_char = ["A","B","C"]

target = []
for i in range(N):
    if s[i] == "AB":
        target.append([0,1])
    elif s[i] == "BC":
        target.append([1,2])
    else:
        target.append([0,2])
if sum_num == 0:
    print("No")
    sys.exit()
elif sum_num == 1:
    answer = []
    for i in range(N):
        if stock[target[i][0]] == 1:
            stock[target[i][0]] -= 1
            stock[target[i][1]] += 1
            answer.append(target[i][1])
        elif stock[target[i][1]] == 1:
            stock[target[i][1]] -= 1
            stock[target[i][0]] += 1
            answer.append(target[i][0])
        else :
            print("No")
            sys.exit()
    print("Yes")
    for i in range(N):
        print(to_char[answer[i]])
elif sum_num >= 2:
    if stock[target[0][0]] == 0 and stock[target[0][1]] == 0:
        print("No")
        sys.exit()
    else:
        print("Yes")
        for i in range(N-1):
            if target[i][0] in target[i+1] and stock[target[i][1]] >= 1:
                stock[target[i][0]] += 1
                stock[target[i][1]] -= 1
                print(to_char[target[i][0]])
            elif stock[target[i][0]] >= 1:
                stock[target[i][1]] += 1
                stock[target[i][0]] -= 1
                print(to_char[target[i][1]])
            else:
                stock[target[i][0]] += 1
                stock[target[i][1]] -= 1
                print(to_char[target[i][0]])
        if stock[target[-1][0]] == 0:
            print(to_char[target[-1][0]])
        else:
            print(to_char[target[-1][1]])

Buggy python submission (verdict: Runtime Error):
import sys
N, A, B, C = map(int, input().split())
stock = [A, B, C]

s = [input() for _ in range(N)]
sum_num = sum(list([A, B, C]))
to_char = ["A","B","C"]


target = []
for i in range(N):
    if s[i] == "AB":
        target.append([0,1])
    elif s[i] == "BC":
        target.append([1,2])
    else:
        target.append([0,2])

if sum_num == 0:
    print("No")
    sys.exit()
elif sum_num == 1:
    answer = []
    for i in range(N):
        if stock[target[i][0]] == 1:
            stock[target[i][0]] -= 1
            stock[target[i][1]] += 1
            answer.append([target[i][1]])
        elif stock[target[i][1]] == 1:
            stock[target[i][1]] -= 1
            stock[target[i][0]] += 1
            answer.append([target[i][0]])
        else :
            print("No")
            sys.exit()
    print("Yes")
    for i in range(N):
        to_char[answer[i]]
elif sum_num >= 2:
    if stock[target[0][0]] == 0 and stock[target[0][1]] == 0:
        print("No")
        sys.exit()
    else:
        print("Yes")
        for i in range(N-1):
            if target[i][0] in target[i+1]:
                stock[target[i][0]] += 1
                stock[target[i][1]] -= 1
                print(to_char[target[i][0]])
            else:
                stock[target[i][1]] += 1
                stock[target[i][0]] -= 1
                print(to_char[target[i][1]])
        if stock[target[-1][0]] == 0:
            print(to_char[target[-1][0]])
        else:
            print(to_char[target[-1][1]])


Fixed submission:
import sys


N, A, B, C = map(int, input().split())
stock = [A, B, C]

s = [input().rstrip('\n') for _ in range(N)]
sum_num = sum(list([A, B, C]))
to_char = ["A","B","C"]

target = []
for i in range(N):
    if s[i] == "AB":
        target.append([0,1])
    elif s[i] == "BC":
        target.append([1,2])
    else:
        target.append([0,2])
if sum_num == 0:
    print("No")
    sys.exit()
elif sum_num == 1:
    answer = []
    for i in range(N):
        if stock[target[i][0]] == 1:
            stock[target[i][0]] -= 1
            stock[target[i][1]] += 1
            answer.append(target[i][1])
        elif stock[target[i][1]] == 1:
            stock[target[i][1]] -= 1
            stock[target[i][0]] += 1
            answer.append(target[i][0])
        else :
            print("No")
            sys.exit()
    print("Yes")
    for i in range(N):
        print(to_char[answer[i]])
elif sum_num >= 2:
    if stock[target[0][0]] == 0 and stock[target[0][1]] == 0:
        print("No")
        sys.exit()
    else:
        print("Yes")
        for i in range(N-1):
            if target[i][0] in target[i+1] and stock[target[i][1]] >= 1:
                stock[target[i][0]] += 1
                stock[target[i][1]] -= 1
                print(to_char[target[i][0]])
            elif stock[target[i][0]] >= 1:
                stock[target[i][1]] += 1
                stock[target[i][0]] -= 1
                print(to_char[target[i][1]])
            else:
                stock[target[i][0]] += 1
                stock[target[i][1]] -= 1
                print(to_char[target[i][0]])
        if stock[target[-1][0]] == 0:
            print(to_char[target[-1][0]])
        else:
            print(to_char[target[-1][1]])