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):
n,a,b,c  = map(int, input().split())
Ss = [input() for i in range(n)]
ans = []
flg = True
for i,S in enumerate(Ss):
    if S == "AB":
        if a == b == 0:
            flg = False
        elif a == b == 1 and i < len(Ss)-1:
            if Ss[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("A")
        else:
            a -= 1
            b += 1
            ans.append("B")
    elif S == "AC":
        if a == c == 0:
            flg = False
        elif a == c == 1 and i<len(Ss)-1:
            if Ss[i+1] == "BC":
                a -= 1
                c += 1
                ans.append("C")
            else:
                a += 1
                c -= 1
                ans.append("A")

        elif a < c:
            a += 1
            c -= 1
            ans.append("A")
        else:
            a -= 1
            c += 1
            ans.append("C")
    elif S == "BC":
        if b == c == 0:
            flg = False
        elif b == c == 1 and i < len(Ss)-1:
            if Ss[i+1] == "AC":
                c += 1
                b -= 1
                ans.append("C")
            else:
                c -= 1
                b += 1
                ans.append("B")
        elif b < c:
            b += 1
            c -= 1
            ans.append("B")
        else:
            b -= 1
            c += 1
            ans.append("C")
            
if flg: 
    print("Yes")
    print(*ans)
else:
    print("No")

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

res_list = []
flag = 1

for i in range(n):
    if flag == 0:
        break
    if ss[i] == 'AB':
        if a == 0 and b == 0:
            flag = 0
        elif a == 0:
            a, b = 1, b-1
            res_list.append('A')
        elif b == 0:
            a, b = a-1, 1
            res_list.append('B')
        elif a == 1 and b == 1:
            if i == n-1:
                res_list.append('A')
            elif ss[i+1] == 'BC':
                res_list.append('B')
                a, b = 0, 2
            elif ss[i+1] == 'AC':
                res_list.append('A')
                a, b = 2, 0
            else:
                res_list.append('A')
                a, b = 2, 0
        elif a == 1:
            res_list.append('A')
            a, b = 2, b-1
        elif b == 1:
            res_list.append('B')
            a, b = a-1, 2
        else:
            res_list.append('A')
            a, b = a+1, b-1
    elif ss[i] == 'BC':
        if b == 0 and c == 0:
            flag = 0
        elif b == 0:
            b, c = 1, c-1
            res_list.append('B')
        elif c == 0:
            b, c = b-1, 1
            res_list.append('C')
        elif b == 1 and c == 1:
            if i == n-1:
                res_list.append('B')
            elif ss[i+1] == 'AB':
                res_list.append('B')
                b, c = 2, 0
            elif ss[i+1] == 'AC':
                res_list.append('C')
                b, c = 0, 2
            else:
                res_list.append('B')
                b, c = 2, 0
        elif b == 1:
            res_list.append('B')
            b, c = 2, c-1
        elif c == 1:
            res_list.append('C')
            b, c = b-1, 2
        else:
            res_list.append('B')
            b, c = b+1, c-1
    else:
        if a == 0 and c == 0:
            flag = 0
        elif a == 0:
            a, c = 1, c-1
            res_list.append('A')
        elif c == 0:
            a, c = a-1, 1
            res_list.append('C')
        elif a == 1 and c == 1:
            if i == n-1:
                res_list.append('A')
            elif ss[i+1] == 'AB':
                res_list.append('A')
                a, c = 2, 0
            elif ss[i+1] == 'BC':
                res_list.append('C')
                a, c = 0, 2
            else:
                res_list.append('A')
                a, c = 2, 0
        elif a == 1:
            res_list.append('A')
            a, c = 2, c-1
        elif c == 1:
            res_list.append('C')
            a, c = a-1, 2
        else:
            res_list.append('A')
            a, c = a+1, c-1

if flag == 0:
    print('No')
else:
    print('Yes')
    for res in res_list:
        print(res)

Solution (Python):
n,a,b,c = map(int,input().split())
ans = []
s = [input() for i in range(n)]
for i in range(n):
    
    if s[i] == "AB":
        if a > b:
            a -= 1
            b += 1
            ans.append("B")
        elif a==b:
            if i < n-1:
                if s[i+1] == "AB":
                    a -= 1
                    b += 1
                    ans.append("B")
                elif s[i+1] == "AC":
                    a += 1
                    b -= 1
                    ans.append("A")
                else:
                    a -= 1
                    b += 1
                    ans.append("B")
            else:
                a -= 1
                b += 1
                ans.append("B")

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

Solution (Python):
N,A,B,C = map(int,input().split())
def sum3(dict_):
    ans = []
    for _ in range(N):
        xy = input()
        x = xy[0] 
        y = xy[1]
        if dict_[x]==0 and dict_[y]==0:
            return False, []
        elif dict_[x]>=dict_[y]:
            dict_[x] -= 1
            dict_[y] += 1
            ans.append(y)
        else:
            dict_[y] -= 1
            dict_[x] += 1
            ans.append(x)
    return True, ans
def sum2(dict_):
    ans = []
    flag = True
    q_list = []
    for _ in range(N):
        q_list.append(input())
    for i in range(N):
        xy = q_list[i]
        x = xy[0]
        y = xy[1]
        if (dict_[x]>=1 and dict_[y]==0):
            dict_[x]-=1
            dict_[y]+=1
            ans.append(y)
        elif (dict_[y]>=1 and dict_[x]==0):
            dict_[y]-=1
            dict_[x]+=1
            ans.append(x)
        elif  (dict_[x]==1 and dict_[y]==1):
            if i==N-1:
                ans.append(x)
            else:
                next_xy = q_list[i+1]
                if xy==next_xy: 
                    dict_[x]+=1
                    dict_[y]-=1
                    ans.append(x)
                elif (x in next_xy):
                    dict_[x]+=1
                    dict_[y]-=1
                    ans.append(x)
                else:
                    dict_[y]+=1
                    dict_[x]-=1
                    ans.append(y)
        else:
            return False, []
    return True,ans
def sum1(dict_):
    ans = []
    flag = True
    for _ in range(N):
        xy = input()
        x = xy[0] 
        y = xy[1]
        if dict_[x]==1:
            dict_[x]-=1
            dict_[y]+=1
            ans.append(y)
        elif dict_[y]==1:
            dict_[y]-=1
            dict_[x]+=1
            ans.append(x)
        else:
            flag = False
            return flag,[]
    return flag, ans
def s0(dict_):
    return False, []
dict_ = {"A":A,"B":B,"C":C}
sum_ = A+B+C
if sum_>=3:
    flag, ans = sum3(dict_)
elif sum_==2:
    flag, ans = sum2(dict_)
elif sum_==1:
    flag, ans = sum1(dict_)
elif sum_==0:
    flag, ans = False, []
if flag:
    print('Yes')
    for i in range(N):
        print(ans[i])
else:
    print("No")

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

s=[input() for _ in range(n)]
AB,BC,AC="AB","BC","AC"

A="A";B="B";C="C"
ans=[]
for i in range(n):
    now=s[i]
    if i==n-1:
        nxt=" "
    else:
        nxt=s[i+1]
    
    if now==AB:
        if a==0:
            a+=1;b-=1
            ans.append(A)
        elif b==0:
            b+=1;a-=1
            ans.append(B)
        else:
            if nxt==BC:
                b+=1;a-=1
                ans.append(B)
            else:
                a+=1;b-=1
                ans.append(A)
    
    elif now==BC:
        if b==0:
            b+=1;c-=1
            ans.append(B)
        elif c==0:
            c+=1;b-=1
            ans.append(C)
        else:
            if nxt==AC:
                c+=1;b-=1
                ans.append(C)
            else:
                b+=1;c-=1
                ans.append(B)
                
    elif now==AC:
        if a==0:
            a+=1;c-=1
            ans.append(A)
        elif c==0:
            c+=1;a-=1
            ans.append(C)
        else:
            if nxt==BC:
                c+=1;a-=1
                ans.append(C)
            else:
                a+=1;c-=1
                ans.append(A)
                
    
    if min(a,b,c)==-1:
        print("No")
        exit()
print("Yes")
for i in ans:
    print(i)

Solution (Python):
import sys

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

def check(i, A, B, C):
    if A < 0 or B < 0 or C < 0:
        return False
    if Q[i] == 'AB':
        return not (A == 0 and B == 0)
    if Q[i] == 'AC':
        return not (A == 0 and C == 0)
    return not (B == 0 and C == 0)

L = []
for i in range(N):
    if i == N-1:
        if Q[i] == 'AB':
            if A == 0 and B == 0:
                print('No')
                sys.exit()
            elif A == 0:
                L.append('A')
                A += 1
                B -= 1
                if B < 0:
                    print('No')
                    sys.exit()
            else:
                L.append('B')
                A -= 1
                B += 1
                if A < 0:
                    print('No')
                    sys.exit()
        elif Q[i] == 'AC':
            if A == 0 and C == 0:
                print('No')
                sys.exit()
            elif A == 0:
                L.append('A')
                A += 1
                C -= 1
                if C < 0:
                    print('No')
                    sys.exit()
            else:
                L.append('C')
                A -= 1
                C += 1
                if A < 0:
                    print('No')
                    sys.exit()
        else:
            if B == 0 and C == 0:
                print('No')
                sys.exit()
            elif B == 0:
                L.append('B')
                B += 1
                C -= 1
                if C < 0:
                    print('No')
                    sys.exit()
            else:
                L.append('C')
                B -= 1
                C += 1
                if B < 0:
                    print('No')
                    sys.exit()
    else:
        if not check(i, A, B, C):
            print('No')
            sys.exit()
        if Q[i] == 'AB':
            if check(i+1, A+1, B-1, C):
                L.append('A')
                A += 1
                B -= 1
                if B < 0:
                    print('No')
                    sys.exit()
            elif check(i+1, A-1, B+1, C):
                L.append('B')
                A -= 1
                B += 1
                if A < 0:
                    print('No')
                    sys.exit()
            else:
                print('No')
                sys.exit()
        elif Q[i] == 'AC':
            if check(i+1, A+1, B, C-1):
                L.append('A')
                A += 1
                C -= 1
                if C < 0:
                    print('No')
                    sys.exit()
            elif check(i+1, A-1, B, C+1):
                L.append('C')
                A -= 1
                C += 1
                if A < 0:
                    print('No')
                    sys.exit()
            else:
                print('No')
                sys.exit()
        else:
            if check(i+1, A, B+1, C-1):
                L.append('B')
                B += 1
                C -= 1
                if C < 0:
                    print('No')
                    sys.exit()
            elif check(i+1, A, B-1, C+1):
                L.append('C')
                B -= 1
                C += 1
                if B < 0:
                    print('No')
                    sys.exit()
            else:
                print('No')
                sys.exit()


print('Yes')
for i in L:
    print(i)

Solution (Python):
n,a,b,c=map(int, input().split( ))
cnts = {"A":a,"B":b,"C":c}
ans=[]
s = [input() for _ in range(n)]+[""]
def rnd(ss,t):

    if cnts[ss[0]]>cnts[ss[1]]:
        cnts[ss[0]]-=1; cnts[ss[1]]+=1
        ans.append(ss[1])
    elif cnts[ss[1]]>cnts[ss[0]]:
        cnts[ss[0]]+=1; cnts[ss[1]]-=1
        ans.append(ss[0])
    else:
        if ss[0] in s[t]:
            cnts[ss[0]]+=1;cnts[ss[1]]-=1
            ans.append(ss[0])
        else:
            cnts[ss[1]]+=1;cnts[ss[0]]-=1
            ans.append(ss[1])

    for k in cnts:
        if cnts[k]<0:
            print("No")
            exit()
for i in range(n):
    rnd(s[i],i+1)
print("Yes")
for ai in ans:
    print(ai)

Solution (Python):
from heapq import heappush, heappop

N, A, B, C = [int(x) for x in input().split()]
S = [input() for i in range(N)]


sToIndex = {
    "AB": (0, 1),
    "AC": (0, 2),
    "BC": (1, 2),
}
heap = [(0, -min(A, B, C), (A, B, C))]
parent = {}
while heap:
    original = heappop(heap)
    negT, negMin, state = original

    if negT == -N:

        print("Yes")
        ans = []
        last = original
        while last in parent:
            nextLast = parent[last]
            diffIndex = None
            for i in range(3):
                if nextLast[2][i] + 1 == last[2][i]:
                    diffIndex = i
                    break
            ans.append("ABC"[diffIndex])
            last = nextLast
        print("\n".join(reversed(ans)))
        exit()

    index1, index2 = sToIndex[S[-negT]]

    nbr1 = list(state)
    nbr1[index1] += 1
    nbr1[index2] -= 1
    min1 = min(nbr1)
    if min1 >= 0:
        node = (negT - 1, -min1, tuple(nbr1))
        if node not in parent:
            heappush(heap, node)
            parent[node] = original

    nbr2 = list(state)
    nbr2[index1] -= 1
    nbr2[index2] += 1
    min2 = min(nbr2)
    if min2 >= 0:
        node = (negT - 1, -min2, tuple(nbr2))
        if node not in parent:
            heappush(heap, node)
            parent[node] = original

print("No")

Solution (Python):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))



N, A, B, C = lr()
S = [sr() for _ in range(N)]
answer = []
for i, s in enumerate(S):
    if s == 'AB':
        if A == B == 0:
            print('No'); exit()
        elif A == 0:
            answer.append('A')
            A += 1; B -= 1; continue
        elif B == 0 or i == N-1:
            answer.append('B')
            B += 1; A -= 1; continue
        ne = S[i+1]
        if 'A' in ne:
            answer.append('A')
            A += 1; B -= 1
        else:
            answer.append('B')
            B += 1; A -= 1
    elif s == 'BC':
        if C == B == 0:
            print('No'); exit()
        elif C == 0:
            answer.append('C')
            C += 1; B -= 1; continue
        elif B == 0 or i == N-1:
            answer.append('B')
            B += 1; C -= 1; continue
        ne = S[i+1]
        if 'C' in ne:
            answer.append('C')
            C += 1; B -= 1
        else:
            answer.append('B')
            B += 1; C -= 1
    elif s == 'AC':
        if A == C == 0:
            print('No'); exit()
        elif A == 0:
            answer.append('A')
            A += 1; C -= 1; continue
        elif C == 0 or i == N-1:
            answer.append('C')
            C += 1; A -= 1; continue
        ne = S[i+1]
        if 'A' in ne:
            answer.append('A')
            A += 1; C -= 1
        else:
            answer.append('C')
            C += 1; A -= 1

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

Solution (Python):


n, a, b, c = map(int, input().split())
ss = [None] * n
for i in range(n):
    ss[i] = input()

abc = {"A": a, "B": b, "C": c}
ans = [None] * n



No = False
for i,s in enumerate(ss):
    zero = [i for i, item in abc.items() if item==0]
    one = [i for i, item in abc.items() if item==1]
    two = [i for i, item in abc.items() if item>=2]


    if len(zero)==0:
        if s in ["AB", "AC"]:
            ans[i] = "A"
            abc["A"] += 1
            abc[s[1]] -= 1
        else:
            ans[i] = "C"
            abc["C"] += 1
            abc["B"] -= 1
    elif len(zero)==1 and len(two)>=1:
        z = zero[0]
        t = two[0]
        if z in s:
            
            ans[i] = z
            abc[z] += 1
            abc[s.replace(z, "")] -= 1
        else:
            
            tmp = s.replace(t, "")
            ans[i] = tmp
            abc[tmp] += 1
            abc[t] -= 1
    elif len(zero)==1 and len(one)==2:
        z = zero[0]
        if s[0] in one and s[1] in one:
            
            ns = ss[i+1] if i+1<=n-1 else None
            if (ns is None) or (z not in ns):
                
                ans[i] = one[0]
                abc[one[0]] += 1
                abc[one[1]] -= 1
            else:
                
                tmp = ns.replace(z, "")
                ans[i] = tmp
                abc[tmp] += 1
                abc[s.replace(tmp, "")] -= 1
        else:
            
            z = zero[0]
            ans[i] = z
            abc[z] += 1
            abc[s.replace(z, "")] -= 1
    else:
        
        assert len(zero) >= 2
        if len(zero)==3:
            No = True
            break
        elif s[0] in zero and s[1] in zero:
            No = True
            break
        else:
            
            z = (set(s) & set(zero)).pop()
            ans[i] = z
            abc[z] += 1
            abc[s.replace(z, "")] -= 1
            
if No:
    print("No")
else:
    print("Yes")
    print("\n".join(ans))

Solution (Python):
import sys

n,a,b,c = map(int,input().split())
s_list = [input() for _ in range(n)]
print_list = []


for i,s in enumerate(s_list):
    if s == 'AB':
        if a == 0 and b == 0:  
            print('No')
            sys.exit()
        else:
            if a > b:
                print_list.append('B')
                a -= 1
                b += 1
            elif b > a:
                print_list.append('A')
                a += 1
                b -= 1
            else:
                if c == 0:
                    if i < len(s_list)-1 and s_list[i+1] == 'AC':
                        print_list.append('A')
                        a += 1
                        b -= 1
                    else:
                        print_list.append('B')
                        a -= 1
                        b += 1
                else:
                    print_list.append('B')
                    a -= 1
                    b += 1


    elif s == 'BC':
        if c == 0 and b == 0:  
            print('No')
            sys.exit()
        else:
            if c > b:
                print_list.append('B')
                c -= 1
                b += 1
            elif b > c:
                print_list.append('C')
                c += 1
                b -= 1
            else:
                if a == 0:
                    if i < len(s_list)-1 and s_list[i+1] == 'AB':
                        print_list.append('B')
                        c -= 1
                        b += 1
                    else:
                        print_list.append('C')
                        c += 1
                        b -= 1
                else:
                    print_list.append('B')
                    c -= 1
                    b += 1

    elif s == 'AC':
        if a == 0 and c == 0:  
            print('No')
            sys.exit()
        else:
            if a > c:
                print_list.append('C')
                a -= 1
                c += 1
            elif c > a:
                print_list.append('A')
                a += 1
                c -= 1

            else:
                if b == 0:
                    if i < len(s_list)-1 and s_list[i+1] == 'AB':
                        print_list.append('A')
                        c -= 1
                        a += 1
                    else:
                        print_list.append('C')
                        c += 1
                        a -= 1
                else:
                    print_list.append('C')
                    c += 1
                    a -= 1

print('Yes')
for p in print_list:
    print(p)

Solution (Python):
import sys

N,A,B,C = map(int,input().split())
s = [0]*N

for i in range(N):
    s[i] = input()

ans = [0]*N
for i in range(N):
    if s[i] == "AB":
        if A == 0 and B == 0:
            print("No")
            sys.exit()
        elif A == 0:
            ans[i] = "A"
            A += 1
            B -= 1
        elif B == 0:
            ans[i] = "B"
            B += 1
            A -= 1
        elif i < N-1 and s[i+1] == "BC":
            ans[i] = "B"
            B += 1
            A -= 1
        elif i < N-1 and s[i+1] == "AC":
            ans[i] = "A"
            A += 1
            B -= 1
        else:
            ans[i] = "A"
            A += 1
            B -= 1
    elif s[i] == "BC":
        if B == 0 and C == 0:
            print("No")
            sys.exit()
        elif B == 0:
            ans[i] = "B"
            B += 1
            C -= 1
        elif C == 0:
            ans[i] = "C"
            C += 1
            B -= 1
        elif i < N-1 and s[i+1] == "AB":
            ans[i] = "B"
            B += 1
            C -= 1
        elif i < N-1 and s[i+1] == "AC":
            ans[i] = "C"
            C += 1
            B -= 1
        else:
            ans[i] = "B"
            B += 1
            C -= 1
    elif s[i] == "AC":
        if A == 0 and C == 0:
            print("No")
            sys.exit()
        elif C == 0:
            ans[i] = "C"
            C += 1
            A -= 1
        elif A == 0:
            ans[i] = "A"
            A += 1
            C -= 1
        elif i < N-1 and s[i+1] == "AB":
            ans[i] = "A"
            A += 1
            C -= 1
        elif i < N-1 and s[i+1] == "BC":
            ans[i] = "C"
            C += 1
            A -= 1
        else:
            ans[i] = "C"
            C += 1
            A -= 1

print("Yes")
for i in range(N):
    print(ans[i])

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, a, b, c = LI()
ans = []
D = {'A':a, 'B':b, 'C':c}
sx = SR(n)
for i in range(n):
    s = sx[i]
    s1 = s[0]
    s2 = s[1]
    if D[s1] == D[s2] == 0:
        print('No')
        exit()
    elif D[s[0]] == D[s[1]] == 1 and i + 1 < n:
        if s1 in sx[i + 1]:
            D[s1] += 1
            D[s2] -= 1
            ans += [s1]
        else:
            D[s2] += 1
            D[s1] -= 1
            ans += [s2]
    elif D[s1] == 0:
        ans += [s1]
        D[s1] += 1
        D[s2] -= 1
    elif D[s2] == 0:
        ans += [s2]
        D[s1] -= 1
        D[s2] += 1
    else:
        if D[s1] > D[s2]:
            ans += [s2]
            D[s1] -= 1
            D[s2] += 1
        else:
            ans += [s1]
            D[s1] += 1
            D[s2] -= 1

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

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,a,b,c = m()

no = {"A":a,"B":b,"C":c}

ans = []

abc = ["A","B","C"]
fl = 0
for i in range(n):
    s = set(list(input()[:-1]))
    if i == 0:
        pre = s
        continue
    po = (pre & s)

    pre = list(pre)
    if no[pre[0]] == 0:
        no[pre[0]] += 1
        no[pre[1]] -= 1
        ans.append(pre[0])
    elif no[pre[1]] == 0:
        no[pre[0]] -= 1
        no[pre[1]] += 1
        ans.append(pre[1])
    else:
        if len(po) == 2:
            if no[pre[0]] >= no[pre[1]]:
                no[pre[0]] -= 1
                no[pre[1]] += 1
                ans.append(pre[1])
            else:
                no[pre[0]] += 1
                no[pre[1]] -= 1
                ans.append(pre[0])
        else:
            aaa = po.pop()
            if no[aaa] == 1:
                for j in pre:
                    if j == aaa:
                        no[j] += 1
                    else:
                        no[j] -= 1
                ans.append(aaa)
            else:
                if no[pre[0]] >= no[pre[1]]:
                    no[pre[0]] -= 1
                    no[pre[1]] += 1
                    ans.append(pre[1])
                else:
                    no[pre[0]] += 1
                    no[pre[1]] -= 1
                    ans.append(pre[0])



    for i in abc:
        if no[i] < 0:
            fl = 1
            break
    if fl:
        break

    pre = s
else:
    pre = list(pre)
    if no[pre[0]] == 0:
        no[pre[0]] += 1
        no[pre[1]] -= 1
        ans.append(pre[0])
    elif no[pre[1]] == 0:
        no[pre[0]] -= 1
        no[pre[1]] += 1
        ans.append(pre[1])
    else:
        ans.append(pre[1])
    for i in abc:
        if no[i] < 0:
            fl = 1
            break


if fl:
    print("No")
else:
    print("Yes")
    for i in ans:
        print(i)

Solution (Python):
n, a, b, c = map(int,input().split())
s = [input() for i in range(n)]
dic = {'A':a, 'B':b, 'C':c}
l = []
for i in range(n):
    temp1 = s[i][0]
    temp2 = s[i][1]
    if dic[temp1] == 0 and dic[temp2] == 0:
        print('No')
        exit()

    if dic[temp1] < dic[temp2]:
        dic[temp1] += 1
        dic[temp2] -= 1
        l.append(temp1)
    elif dic[temp1] == dic[temp2] and i != n - 1:
        n1, n2 = s[i + 1]
        if (n1, n2) == (temp1, temp2):
            dic[temp2] += 1
            dic[temp1] -= 1
            l.append(temp2)
        else:
            if temp1 == n1 or temp1 == n2:
                dic[temp1] += 1
                dic[temp2] -= 1
                l.append(temp1)
            else:
                dic[temp2] += 1
                dic[temp1] -= 1
                l.append(temp2)
    else:
        dic[temp2] += 1
        dic[temp1] -= 1
        l.append(temp2)
print('Yes')
print(*l, sep = '\n')