Problem:
 Score : 600 points    Problem Statement 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.      Constraints  1 \leq N \leq 10^5  0 \leq A,B,C \leq 10^9  N, A, B, C are integers.  s_i is AB , AC , or BC .         Input Input is given from Standard Input in the following format:  N  A  B  C  s_1  s_2  :  s_N       Output If it is possible to make N choices under the condition, print Yes ; otherwise, print No .  Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1) -th line should contain the name of the variable ( A , B , or C ) to which you add 1 in the i -th choice.        Sample Input 1 2 1 3 0
AB
AC      Sample Output 1 Yes
A
C  You can successfully make two choices, as follows:   In the first choice, add 1 to A and subtract 1 from B . A becomes 2 , and B becomes 2 .  In the second choice, add 1 to C and subtract 1 from A . C becomes 1 , and A becomes 1 .        Sample Input 2 3 1 0 0
AB
BC
AB      Sample Output 2 No       Sample Input 3 1 0 9 0
AC      Sample Output 3 No       Sample Input 4 8 6 9 1
AC
BC
AB
BC
AC
BC
AB
AB      Sample Output 4 Yes
C
B
B
C
C
B
A
A

Solution (Python):

"""
Created on Sun May  3 22:01:32 2020
"""

import sys


sys.setrecursionlimit(10 ** 9)


mod = 10**9+7


N,A,B,C = map(int,input().split())
s = []
for i in range(N):
    s.append(input())

ans = ['Yes']
No = 'No'
ab,ac,bc = 'AB', 'AC', 'BC'
a,b,c = 'A', 'B', 'C'

for i in range(N):
    if s[i] == ab:
        flg = True
        if A == 1 and B ==1:
            if i == N -1:
                flg = True
            elif s[i+1] == ac:
                flg = True
            else:
                flg = False
        elif A <= B:
            flg = True
        elif A > B:
            flg = False
        if flg:
            A += 1
            B -= 1
            ans.append(a)
        else:
            A -= 1
            B += 1
            ans.append(b)

    elif s[i] == ac:
        flg = True
        if A == 1 and C ==1:
            if i == N -1:
                flg = True
            elif s[i+1] == ab:
                flg = True
            else:
                flg = False
        elif A <= C:
            flg = True
        elif A > C:
            flg = False
        if flg:
            A += 1
            C -= 1
            ans.append(a)
        else:
            A -= 1
            C += 1
            ans.append(c)

    elif s[i] == bc:
        flg = True
        if B == 1 and C ==1:
            if i == N -1:
                flg = True
            elif s[i+1] == ab:
                flg = True
            else:
                flg = False
        elif B <= C:
            flg = True
        elif B > C:
            flg = False
        if flg:
            B += 1
            C -= 1
            ans.append(b)
        else:
            B -= 1
            C += 1
            ans.append(c)
    if A < 0 or B < 0 or C < 0:
        print(No)
        sys.exit()

for a in ans:
    print(a)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,A,B,C=MI()
    D = { "A":A,"B":B,"C":C }
    ans = []
    S=[ST() for _ in range(N)]
    for i,s in enumerate(S):
        if(D[s[0]]==D[s[1]]==0):
            print("No")
            return
        if(D[s[0]]<D[s[1]]):
            ans.append(s[0])
            D[s[0]]+=1
            D[s[1]]-=1
        elif(D[s[0]]>D[s[1]] or i==N-1):
            ans.append(s[1])
            D[s[0]]-=1
            D[s[1]]+=1
        else:
            ns = S[i+1]
            if(s[0] in ns):
                ans.append(s[0])
                D[s[0]]+=1
                D[s[1]]-=1
            else:
                ans.append(s[1])
                D[s[0]]-=1
                D[s[1]]+=1
        

    print("Yes")
    print(*ans,sep="\n")
if __name__ == '__main__':
    main()

Solution (Python):
import sys
readline = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10**6)


n,*a = [int(i) for i in readline().split()]
s = read().split()

dx = {"AB":0,"BC":1,"AC":2}
ans = ["Yes"]

def dfs(i):
    if i==n:
        print(*ans,sep="\n")
        exit()
    x = dx[s[i]]
    y = (x+1)%3
    for j in [x,y]:
        if a[j]:
            ans.append("ABC"[x+y-j])
            a[j] -= 1
            a[x+y-j] += 1
            dfs(i+1)
            ans.pop()    
            a[j] += 1
            a[x+y-j] -= 1

dfs(0)
print("No")

Solution (Python):
n, a, b, c = map(int, input().split())

keep = False

answer = []

miss = False

for i in range(n):
    s = input()

    if keep:
        if kept == "AB":
            if s == "AB":
                a += 1
                b -= 1
                answer.append('A')
            elif s == "AC":
                a += 1
                b -= 1
                answer.append('A')
            elif s == "BC":
                a -= 1
                b += 1
                answer.append('B')
        if kept == "AC":
            if s == "AB":
                a += 1
                c -= 1
                answer.append('A')
            elif s == "AC":
                a += 1
                c -= 1
                answer.append('A')
            elif s == "BC":
                a -= 1
                c += 1
                answer.append('C')
        if kept == "BC":
            if s == "AB":
                b += 1
                c -= 1
                answer.append('B')
            elif s == "AC":
                b -= 1
                c += 1
                answer.append('C')
            elif s == "BC":
                b += 1
                c -= 1
                answer.append('B')

    keep = False

    if s == "AB":
        if a == b:
            if a == 1:
                keep = True
                kept = "AB"
            else:
                a += 1
                b -= 1
                answer.append('A')
        else:
            if a > b:
                a -= 1
                b += 1
                answer.append('B')
            else:
                a += 1
                b -= 1
                answer.append('A')

    elif s == "AC":
        if a == c:
            if a == 1:
                keep = True
                kept = "AC"
            else:
                a += 1
                c -= 1
                answer.append('A')
        else:
            if a > c:
                a -= 1
                c += 1
                answer.append('C')
            else:
                a += 1
                c -= 1
                answer.append('A')
    elif s == "BC":
        if b == c:
            if b == 1:
                keep = True
                kept = "BC"
            else:
                b += 1
                c -= 1
                answer.append('B')
        else:
            if b > c:
                b -= 1
                c += 1
                answer.append('C')
            else:
                b += 1
                c -= 1
                answer.append('B')

    if a < 0 or b < 0 or c < 0:
        miss = True
        break

    if keep and i == (n-1):
        if kept == "AB":
            answer.append('A')
        elif kept == "AC":
            answer.append('A')
        elif kept == "BC":
            answer.append('B')

if miss:
    print("No")
else:
    print("Yes")
    for ans in answer:
        print(ans)

Solution (Python):
n,a,b,c = map(int,input().split())
s = [input() for i in range(n)]+[0]


ans = ""


for i in range(n):
    if s[i] == "AB":
        if a==1 and b==1 and s[i+1] =="BC":
            ans+="B"
            b+=1
            a-=1
        elif a<=b:
            ans+="A"
            a+=1
            b-=1
        else:
            ans+="B"
            b+=1
            a-=1
    if s[i] == "AC":
        if a==1 and c==1 and s[i+1] =="BC":
            ans+="C"
            c+=1
            a-=1
        elif a<=c:
            ans+="A"
            a+=1
            c-=1
        else:
            ans+="C"
            c+=1
            a-=1       
    if s[i] == "BC":
        if b==1 and c==1 and s[i+1] =="AC":
            ans+="C"
            c+=1
            b-=1
        elif b<=c:
            ans+="B"
            b+=1
            c-=1
        else:
            ans+="C"
            c+=1
            b-=1   
    if a<0 or b<0 or c<0:
        print("No") 
        exit()
print("Yes")
for i in ans:
    print(i)

Solution (Python):
def examA():
    S = SI()
    if S=="ARC":
        ans = "ABC"
    else:
        ans = "ARC"
    print(ans)
    return

def examB():
    N, K = LI()
    snuke = set(range(1,N+1))
    for _ in range(K):
        d = I()
        A = LI()
        for a in A:
            snuke.discard(a)
    ans = len(snuke)
    print(ans)
    return

def examC():
    N, M = LI()
    H = LI()
    good = set(range(1,N+1))
    for _ in range(M):
        a, b = LI()
        if H[a-1]>=H[b-1]:
            good.discard(b)
        if H[b-1]>=H[a-1]:
            good.discard(a)
    ans = len(good)
    print(ans)
    return

def examD():
    X = I()
    
    for a in range(-1000,1000):
        for b in range(-1000,1000):
            if a**5-b**5==X:
                print(a,b)
                return
    return

def examE():
    N = I()
    A = LI()
    B = [0]*N
    D = defaultdict(int)
    for i in range(N):
        B[i] = A[i]-i
        c = A[i]+i
        D[c] += 1
    
    
    ans = 0
    for b in B:
        ans += D[-b]
    print(ans)
    return

def examF():
    def Run_Length_Encoding(s):
        tmp, count, res = s[0], 1, []
        for i in range(1, len(s)):
            if tmp == s[i]:
                count += 1
            else:
                res.append((count, tmp))
                tmp = s[i]
                count = 1
        res.append((count, tmp))
        return res

    N, A, B, C = LI()
    S = [SI()for _ in range(N)]
    SS = Run_Length_Encoding(S)
    
    n = len(SS)
    ans = [""]*(N)
    def judge(a,b):
        if a<0 or b<0:
            return False
        return True
    def dfs(i,num,A,B,C):
        if i==n:
            if A>=0 and B>=0 and C>=0:
                print("Yes")
                for v in ans:
                    print(v)
                exit()
            return
        cnt, s = SS[i]
        if s=="AB":
            if A==0 and B==0:
                return
            for j in range(cnt//2 -1):
                if A==0:
                    ans[num] = "A"
                    num += 1
                    ans[num] = "B"
                else:
                    ans[num] = "B"
                    num += 1
                    ans[num] = "A"
            if cnt>=2:
                A += 1; B -= 1
                if judge(A, B):
                    ans[num] = "A"
                    dfs(i + 1, num + 1, A, B, C)
                A -= 2; B += 2
                if judge(A, B):
                    ans[num] = "B"
                    dfs(i + 1, num + 1, A, B, C)
                A += 1;
                B -= 2
            if cnt%2==0:
                dfs(i+1,num+1,A,B,C)
                return
            A += 1; B -= 1
            if judge(A,B):
                ans[num] = "A"
                dfs(i+1,num+1,A,B,C)
            A -= 2; B += 2
            if judge(A,B):
                ans[num] = "B"
                dfs(i+1,num+1,A,B,C)
            A += 1; B -= 2
        elif s=="BC":
            if B==0 and C==0:
                return
            for j in range(cnt//2 -1):
                if B==0:
                    ans[num] = "B"
                    num += 1
                    ans[num] = "C"
                else:
                    ans[num] = "C"
                    num += 1
                    ans[num] = "B"
            if cnt%2==0:

                dfs(i+1,num+1,A,B,C)
                return
            B += 1; C -= 1
            if judge(B,C):
                ans[num] = "B"
                dfs(i+1,num+1,A,B,C)
            B -= 2; C += 2
            if judge(B,C):
                ans[num] = "C"
                dfs(i+1,num+1,A,B,C)
            B += 1; C -= 2
        else:
            if A==0 and C==0:
                return
            for j in range(cnt//2 -1):
                if A==0:
                    ans[num] = "A"
                    num += 1
                    ans[num] = "C"
                else:
                    ans[num] = "C"
                    num += 1
                    ans[num] = "A"
            if cnt%2==0:
                dfs(i+1,num+1,A,B,C)
                return
            A += 1; C -= 1
            if judge(A, C):
                ans[num] = "A"
                dfs(i + 1,num+1,A,B,C)
            A -= 2; C += 2
            if judge(A, C):
                ans[num] = "C"
                dfs(i + 1,num+1,A,B,C)
            A += 1; C -= 2
        return
    dfs(0,0,A,B,C)
    print("No")
    return


def examF2():
    N, A, B, C = LI()
    S = [SI() for _ in range(N)]
    
    ans = [""] * N

    def judge(a, b):
        if a < 0 or b < 0:
            return False
        return True

    def dfs(i, A, B, C):
        if i == N:
            if A >= 0 and B >= 0 and C >= 0:
                print("Yes")
                for v in ans:
                    print(v)
                exit()
            return
        s = S[i]
        if s == "AB":
            if A == 0 and B == 0:
                return
            A += 1;
            B -= 1
            if judge(A, B):
                ans[i] = "A"
                dfs(i + 1, A, B, C)
            A -= 2;
            B += 2
            if judge(A, B):
                ans[i] = "B"
                dfs(i + 1, A, B, C)
            A += 1;
            B -= 1
        elif s == "BC":
            if B == 0 and C == 0:
                return
            B += 1;
            C -= 1
            if judge(B, C):
                ans[i] = "B"
                dfs(i + 1, A, B, C)
            B -= 2;
            C += 2
            if judge(B, C):
                ans[i] = "C"
                dfs(i + 1,A, B, C)
            B += 1;
            C -= 1
        else:
            if A == 0 and C == 0:
                return
            A += 1;
            C -= 1
            if judge(A, C):
                ans[i] = "A"
                dfs(i + 1, A, B, C)
            A -= 2;
            C += 2
            if judge(A, C):
                ans[i] = "C"
                dfs(i + 1, A, B, C)
            A += 1;
            C -= 1
        return

    dfs(0, A, B, C)
    print("No")
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examF2()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline

    N, A, B, C = map(int, input().split())
    s = [input().rstrip() for _ in range(N)]

    ans = []
    for i, op in enumerate(s):
        
        if op == 'AB':
            if A == B == 0:
                print('No')
                return

            if A > B:
                A -= 1
                B += 1
                ans.append('B')
            else:
                if A == B and i < N - 1:
                    if s[i + 1] == 'AC' and A == 1:
                        A += 1
                        B -= 1
                        ans.append('A')
                        continue
                    elif s[i + 1] == 'BC' and B == 1:
                        A -= 1
                        B += 1
                        ans.append('B')
                        continue
                A += 1
                B -= 1
                ans.append('A')
        elif op == 'AC':
            if A == C == 0:
                print('No')
                return

            if A > C:
                A -= 1
                C += 1
                ans.append('C')
            else:
                if A == C and i < N - 1:
                    if s[i + 1] == 'AB' and A == 1:
                        A += 1
                        C -= 1
                        ans.append('A')
                        continue
                    elif s[i + 1] == 'BC' and C == 1:
                        A -= 1
                        C += 1
                        ans.append('C')
                        continue
                A += 1
                C -= 1
                ans.append('A')
        else:
            if B == C == 0:
                print('No')
                return

            if B > C:
                B -= 1
                C += 1
                ans.append('C')
            else:
                if B == C and i < N - 1:
                    if s[i + 1] == 'AB' and B == 1:
                        B += 1
                        C -= 1
                        ans.append('B')
                        continue
                    elif s[i + 1] == 'AC' and C == 1:
                        B -= 1
                        C += 1
                        ans.append('C')
                        continue
                B += 1
                C -= 1
                ans.append('B')
        

    print('Yes')
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

Solution (Python):
import random
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()


def get_nums_l():
    return [ int(s) for s in input().split(" ")]

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n,a,b,c = get_nums_l()
d = {
    "A": a,
    "B": b,
    "C": c
}
S = []
for _ in range(n):
    S.append(input())

def dfs(i, x, history):

    if d[S[i][1-x]] == 0:
        return False

    d[S[i][x]] += 1
    d[S[i][1-x]] -= 1

    history.append(S[i][x])

    if i == n-1:
        return True

    nex = random.randint(0, 1)

    ok = dfs(i+1, nex, history)
    if ok:
        return ok

    ok = dfs(i+1, 1-nex, history)

    if ok:
        return ok

    
    history.pop()
    d[S[i][x]] -= 1
    d[S[i][1-x]] += 1

    return False

history = deque()
ok = dfs(0, 0, history) or dfs(0, 1, history)

print("Yes" if ok else "No")
if ok:
    for s in history:
        print(s)

Solution (Python):
import sys
input = sys.stdin.readline

n, a, b, c = [int(x) for x in input().split()]
score = {}
score["A"] = a
score["B"] = b
score["C"] = c     
S = [input().rstrip() for _ in range(n)]
ans = []

for i in range(n - 1):
    s = S[i]
    next_s = S[i + 1]
    s1 = s[0]
    s2 = s[1]
    if score[s1] == 0 and score[s2] == 0:
        print("No")
        sys.exit()
    elif score[s1] == 0:
        ans.append(s1)
        score[s1] += 1
        score[s2] -= 1
    elif score[s2] == 0:
        ans.append(s2)
        score[s1] -= 1
        score[s2] += 1
    elif score[s1] == 1 and score[s2] == 1:
        if next_s == s:
            ans.append(s1)
            score[s1] += 1
            score[s2] -= 1
        elif s1 in next_s:
            ans.append(s1)
            score[s1] += 1
            score[s2] -= 1
        else:
            ans.append(s2)
            score[s2] += 1
            score[s1] -= 1
    else:
        if score[s1] >= score[s2]:
            ans.append(s2)
            score[s2] += 1
            score[s1] -= 1
        else:
            ans.append(s1)
            score[s1] += 1
            score[s2] -= 1
s = S[-1]
s1 = s[0]
s2 = s[1]

if score[s1] == 0 and score[s2] == 0:
        print("No")
        sys.exit()
elif score[s1] == 0:
    ans.append(s1)
    score[s1] += 1
    score[s2] -= 1
elif score[s2] == 0:
    ans.append(s2)
    score[s1] -= 1
    score[s2] += 1
else:
    ans.append(s1)
print("Yes")
for i in ans:
    print(i)

Solution (Python):
import sys
from math import log2,floor,ceil,sqrt



Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

n,a,b,c = Ri()
ans  = []
flag = True
q = []
for i in range(n):
    temp = ri()
    q.append(temp)

ac = [INF]*n
ab = [INF]*n
bc = [INF]*n
nac = INF
nab = INF
nbc = INF
for i in range(n-1,-1,-1):
    ac[i] = nac
    ab[i] = nab
    bc[i] = nbc
    if q[i] == 'AC':
        nac = i
    elif q[i] == 'AB':
        nab = i
    else:
        nbc = i

for i in range(n):
    
    temp = q[i]
    if temp == "AB":
        if a==0 and b==0:
            flag = False
        else:
            if a<b:
                

                a+=1
                b-=1
                ans.append("A")
            else:
                if a==1 and b==1 and c==0:
                    if ac[i] < bc[i]:
                        a+=1
                        b-=1
                        ans.append('A')
                    else:
                        b+=1
                        a-=1
                        ans.append('B')
                else:
                    a-=1
                    b+=1
                    ans.append("B")
    elif temp == "BC":
        
        if c==0 and b==0:
            flag = False
        else:
            if c<b:
                
                c+=1
                b-=1
                ans.append("C")
                
            else:
                if c==1 and b==1 and a==0:
                    if ac[i] < ab[i]:
                        c+=1
                        b-=1
                        ans.append('C')
                    else:
                        b+=1
                        c-=1
                        ans.append('B')
                else:
                    c-=1
                    b+=1
                    ans.append("B")
    else:
        if a==0 and c==0:
            flag = False
        else:
            if a<c:
                a+=1
                c-=1
                ans.append("A")
            else:
                if a==1 and c==1 and b==0:
                    if ab[i] < bc[i]:
                        a+=1
                        c-=1
                        ans.append('A')
                    else:
                        c+=1
                        a-=1
                        ans.append('C')
                else:
                    a-=1
                    c+=1
                    ans.append("C")
if not flag : 
    No()
else:
    Yes()
    for i in range(n):
        print(ans[i])

Solution (Python):
n,a,b,c=[int(x) for x in input().split()]
S=[input() for i in range(n)]
ans=""
for i in range(n):
  s=S[i]
  if s=="AB":
    if a==0 and b==0:
      print("No")
      exit()
    elif a>b:
      ans+="B\n"
      a-=1
      b+=1
    elif b>a:
      ans+="A\n"
      a+=1
      b-=1
    else:
      if i+1<n and S[i+1]=="AC":
         ans+="A\n"
         a+=1
         b-=1
      else:
         ans+="B\n"
         a-=1
         b+=1
  elif s=="AC":
    if a==0 and c==0:
      print("No")
      exit()
    elif a>c:
      ans+="C\n"
      a-=1
      c+=1
    elif c>a:
      ans+="A\n"
      a+=1
      c-=1
    else:
        if i+1<n and S[i+1]=="BC":
            ans+="C\n"
            a-=1
            c+=1
        else:
            ans += "A\n"
            a+=1
            c-=1
  elif s=="BC":
    if c==0 and b==0:
      print("No")
      exit()
    elif c>b:
      ans+="B\n"
      c-=1
      b+=1
    elif b>c:
      ans+="C\n"
      c+=1
      b-=1
    else:
        if i+1<n and S[i+1]=="AB":
            ans += "B\n"
            b+=1
            c-=1
        else:
            ans+="C\n"
            c+=1
            b-=1
print("Yes")
print(ans,end="")

Solution (Python):
import sys
n,a,b,c=map(int,input().split())
s=[input() for i in range(n)]
ans=[]
for i in range(n-1):
  if s[i]=='AB':
    if a==0 and b==0:
      print('No')
      sys.exit()
    if a>b or (a==b and s[i+1]=='BC'):
      a-=1
      b+=1
      ans.append('B')
    else:
      a+=1
      b-=1
      ans.append('A')
  if s[i]=='BC':
    if b==0 and c==0:
      print('No')
      sys.exit()
    if b>c or (b==c and s[i+1]=='AC'):
      b-=1
      c+=1
      ans.append('C')
    else:
      b+=1
      c-=1
      ans.append('B')
  if s[i]=='AC':
    if a==0 and c==0:
      print('No')
      sys.exit()
    if a>c or (a==c and s[i+1]=='BC'):
      a-=1
      c+=1
      ans.append('C')
    else:
      a+=1
      c-=1
      ans.append('A')
for i in range(n-1,n):
  if s[i]=='AB':
    if a==0 and b==0:
      print('No')
      sys.exit()
    if a>=b:
      a-=1
      b+=1
      ans.append('B')
    else:
      a+=1
      b-=1
      ans.append('A')
  if s[i]=='BC':
    if b==0 and c==0:
      print('No')
      sys.exit()
    if b>=c:
      b-=1
      c+=1
      ans.append('C')
    else:
      b+=1
      c-=1
      ans.append('B')
  if s[i]=='AC':
    if a==0 and c==0:
      print('No')
      sys.exit()
    if a>=c:
      a-=1
      c+=1
      ans.append('C')
    else:
      a+=1
      c-=1
      ans.append('A')
print('Yes')
for i in range(n):
  print(ans[i])

Solution (Python):
d = {'A':0, 'B':1, 'C':2}
ABC = 'ABC'

def main():
    N, A, B, C = map(int, input().split())
    abc_nums = [A, B, C]
    S = []
    for i in range(N):
        s = input()
        flgs = []
        for j in range(2):
            flgs.append(d[s[j]])
        S.append(flgs)

    ans = []
    for i in range(N):
        if abc_nums[S[i][0]] == abc_nums[S[i][1]] == 0:
            print('No')
            return
        elif i == N-1:  
            if abc_nums[S[i][0]] <= abc_nums[S[i][1]]:
                abc_nums[S[i][0]] += 1
                ans.append(ABC[S[i][0]])
                abc_nums[S[i][1]] -= 1
            else:
                abc_nums[S[i][0]] -= 1
                abc_nums[S[i][1]] += 1
                ans.append(ABC[S[i][1]])
        elif abc_nums[S[i][0]] == abc_nums[S[i][1]]:    
            if S[i][0] == S[i+1][0] or S[i][0] == S[i+1][1]:
                abc_nums[S[i][0]] += 1
                ans.append(ABC[S[i][0]])
                abc_nums[S[i][1]] -= 1
            else:
                abc_nums[S[i][0]] -= 1
                abc_nums[S[i][1]] += 1
                ans.append(ABC[S[i][1]])
        elif abc_nums[S[i][0]] <= abc_nums[S[i][1]]:
            abc_nums[S[i][0]] += 1
            ans.append(ABC[S[i][0]])
            abc_nums[S[i][1]] -= 1
        else:
            abc_nums[S[i][0]] -= 1
            abc_nums[S[i][1]] += 1
            ans.append(ABC[S[i][1]])
    print('Yes')
    for i in range(N):
        print(ans[i])
    return
main()

Solution (Python):
def resolve():
    N,A,B,C = map(int,input().split())

    S=[input() for i in range(N)]
    ans =[]




    for i in range(N):
        s=S[i]
        if s =="AB":
            if A ==B ==0:
                print("No")
                return
            if A == B ==1 and C == 0 and i < N-1:
                if S[i+1] =="AC":
                    A+=1
                    B-=1
                    ans.append("A")
                else:
                    A-=1
                    B+=1
                    ans.append("B")
            elif A>B:
                A-=1
                B+=1
                ans.append("B")
            else:
                A+=1
                B-=1
                ans.append("A")

        elif s =="BC":
            if C ==B ==0:
                print("No")
                return
            if C == B ==1 and A == 0 and i < N-1:
                if S[i+1] =="AC":
                    C+=1
                    B-=1
                    ans.append("C")
                else:
                    C-=1
                    B+=1
                    ans.append("B")
            elif C>B:
                C-=1
                B+=1
                ans.append("B")
            else:
                C+=1
                B-=1
                ans.append("C")

        elif s =="AC":
            if C ==A ==0:
                print("No")
                return
            if C == A ==1 and B == 0 and i < N-1:
                if S[i+1] =="AB":
                    A+=1
                    C-=1
                    ans.append("A")
                else:
                    C+=1
                    A-=1
                    ans.append("C")
            elif C>A:
                C-=1
                A+=1
                ans.append("A")
            else:
                C+=1
                A-=1
                ans.append("C")


    print("Yes")
    print("\n".join(ans))







if __name__ == "__main__":
    resolve()