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())
S = [input() for _ in range(N)]

ANS = ['']*N
for i in range(N):
    if S[i]=='AB':
        if A==0 and B==0:
            print('No')
            exit()
        if i != N-1 and A==B and S[i+1]!='AB':
            if S[i+1]=='AC':
                ANS[i] = 'A'
                A += 1
                B -= 1
            elif S[i+1]=='BC':
                ANS[i] = 'B'
                B += 1
                A -= 1

        elif A<B:
            ANS[i] = 'A'
            A += 1
            B -= 1
        else:
            ANS[i] = 'B'
            A -= 1
            B += 1
            

    elif S[i]=='AC':
        if A==0 and C==0:
            print('No')
            exit()
        if i != N-1 and A==C and S[i+1]!='AC':
            if S[i+1]=='AB':
                ANS[i] = 'A'
                A += 1
                C -= 1
            elif S[i+1]=='BC':
                ANS[i] = 'C'
                C += 1
                A -= 1
        elif A<C:
            ANS[i] = 'A'
            A += 1
            C -= 1
        else:
            ANS[i] = 'C'
            A -= 1
            C += 1


    elif S[i]=='BC':
        if C==0 and B==0:
            print('No')
            exit()
        if i != N-1 and C==B and S[i+1]!='BC':
            if S[i+1]=='AC':
                ANS[i] = 'C'
                C += 1
                B -= 1
            elif S[i+1]=='AB':
                ANS[i] = 'B'
                B += 1
                C -= 1
        elif C<B:
            ANS[i] = 'C'
            C += 1
            B -= 1
        else:
            ANS[i] = 'B'
            C -= 1
            B += 1
if A<0 or B<0 or C<0:
    print('No')
    exit()

print('Yes')
for a in ANS:
    print(a)

Solution (Python):
n,a,b,c=map(int,input().split())
s=[input() for _ in range(n)]
if a+b+c==0:
    print("No")
elif a+b+c==1:
    choice=[]
    for si in s:
        if si=="AB":
            if c==1:
                print("No")
                exit()
            elif a==1:
                a-=1
                b+=1
                choice.append("B")
            else:
                a+=1
                b-=1
                choice.append("A")
        elif si=="AC":
            if b==1:
                print("No")
                exit()
            elif a==1:
                a-=1
                c+=1
                choice.append("C")
            else:
                a+=1
                c-=1
                choice.append("A")
        else:
            if a==1:
                print("No")
                exit()
            elif b==1:
                b-=1
                c+=1
                choice.append("C")
            else:
                b+=1
                c-=1
                choice.append("B")
    print("Yes")
    for ch in choice:
        print(ch)
else:
    choice=[]
    if s[0]=="AB":
        if a==0 and b==0:
            print("No")
            exit()
    elif s[0]=="AC":
        if a==0 and c==0:
            print("No")
            exit()
    else:
        if b==0 and c==0:
            print("No")
            exit()
    for i in range(n):
        if a+b+c>=3:
            if s[i]=="AB":
                if a>=b:
                    a-=1
                    b+=1
                    choice.append("B")
                else:
                    a+=1
                    b-=1
                    choice.append("A")
            elif s[i]=="AC":
                if a>=c:
                    a-=1
                    c+=1
                    choice.append("C")
                else:
                    a+=1
                    c-=1
                    choice.append("A")
            else:
                if b>=c:
                    b-=1
                    c+=1
                    choice.append("C")
                else:
                    b+=1
                    c-=1
                    choice.append("B")
        else:
            if i<n-1:
                
                if s[i]=="AB":
                    if a==b:
                        if s[i+1]=="AB" or s[i+1]=="BC":
                            a-=1
                            b+=1
                            choice.append("B")
                        else:
                            a+=1
                            b-=1
                            choice.append("A")
                    elif b>a:
                        a+=1
                        b-=1
                        choice.append("A")
                    else:
                        a-=1
                        b+=1
                        choice.append("B")
                        
                elif s[i]=="AC":
                    if a==c:
                        if s[i+1]=="AC" or s[i+1]=="BC":
                            a-=1
                            c+=1
                            choice.append("C")
                        else:
                            a+=1
                            c-=1
                            choice.append("A")
                    elif c>a:
                        a+=1
                        c-=1
                        choice.append("A")
                    else:
                        a-=1
                        c+=1
                        choice.append("C")
                else:
                    if b==c:
                        if s[i+1]=="BC" or s[i+1]=="AC":
                            b-=1
                            c+=1
                            choice.append("C")
                        else:
                            b+=1
                            c-=1
                            choice.append("B")
                    elif b>c:
                        b-=1
                        c+=1
                        choice.append("C")
                    else:
                        b+=1
                        c-=1
                        choice.append("B")
            else:
                if s[i]=="AB":
                    if a>=b:
                        a-=1
                        b+=1
                        choice.append("B")
                    else:
                        a+=1
                        b-=1
                        choice.append("A")
                elif s[i]=="AC":
                    if a>=c:
                        a-=1
                        c+=1
                        choice.append("C")
                    else:
                        a+=1
                        c-=1
                        choice.append("A")
                else:
                    if b>=c:
                        b-=1
                        c+=1
                        choice.append("C")
                    else:
                        b+=1
                        c-=1
                        choice.append("B")
    print("Yes")
    
    for ch in choice:
        print(ch)

Solution (Python):
N, A, B, C = map(int, input().split())
S = [input() for i in range(N)]
add = []

flag = True

for x in range(len(S)):
    if S[x] == "AB":
        if A == 0 and B == 0:
            flag = False
            break
        if A == 0:
            A += 1
            B -= 1
            add.append("A")
        elif B == 0:
            B += 1
            A -= 1
            add.append("B")
        elif x + 1 < len(S) and A + B + C == 2 and S[x + 1] != "AB":
            if S[x + 1] == "AC":
                A += 1
                B -= 1
                add.append("A")
            else:
                B += 1
                A -= 1
                add.append("B")
        elif A < B:
            A += 1
            B -= 1
            add.append("A")
        else:
            B += 1
            A -= 1
            add.append("B")
    elif S[x] == "AC":
        if A == 0 and C == 0:
            flag = False
            break
        if A == 0:
            A += 1
            C -= 1
            add.append("A")
        elif C == 0:
            C += 1
            A -= 1
            add.append("C")
        elif x + 1 < len(S) and A + B + C == 2 and S[x + 1] != "AC":
            if S[x + 1] == "BC":
                C += 1
                A -= 1
                add.append("C")
            else:
                A += 1
                C -= 1
                add.append("A")
        elif A < C:
            A += 1
            C -= 1
            add.append("A")
        else:
            C += 1
            A -= 1
            add.append("C")
    else:
        if B == 0 and C == 0:
            flag = False
            break
        if B == 0:
            B += 1
            C -= 1
            add.append("B")
        elif C == 0:
            C += 1
            B -= 1
            add.append("C")
        elif x + 1 < len(S) and A + B + C == 2 and S[x + 1] != "BC":
            if S[x + 1] == "AB":
                B += 1
                C -= 1
                add.append("B")
            else:
                C += 1
                B -= 1
                add.append("C")
        elif B < C:
            B += 1
            C -= 1
            add.append("B")
        else:
            C += 1
            B -= 1
            add.append("C")

if flag is True and A >= 0 and B >= 0 and C >= 0:
    print("Yes")
    for y in add:
        print(y)
else:
    print("No")

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float('inf')
MOD=10**9+7

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

s=[input() for _ in range(n)]


if a+b+c==0:
    print("No")
    exit()
elif a+b+c==1:
    result=[]
    for order in s:
        if "AB" == order:
            if c==1:
                print("No")
                exit()
            elif a==1:
                a-=1
                b+=1
                result.append("B")
            else:
                b-=1
                a+=1
                result.append("A")
        elif "AC" == order:
            if b==1:
                print("No")
                exit()
            elif a==1:
                a-=1
                c+=1
                result.append("C")
            else:
                c-=1
                a+=1
                result.append("A")
        elif "BC" == order:
            if a==1:
                print("No")
                exit()
            elif b==1:
                b-=1
                c+=1
                result.append("C")
            else:
                c-=1
                b+=1
                result.append("B")
    print("Yes")
    for item in result:
        print(item)
    exit()

else:
    result=[]
    for index,order in enumerate(s):
        if "AB" == order:
            if a==0 and b==0:
                print("No")
                exit()
            elif a==1 and b==1:
                if index <n-1:
                    if s[index+1]=="AB":
                        result.append("B")
                        a-=1
                        b+=1
                    elif s[index+1]=="AC":
                        result.append("A")
                        a+=1
                        b-=1
                    elif s[index+1]=="BC":
                        result.append("B")
                        a-=1
                        b+=1
                else:
                    a-=1
                    b+=1
                    result.append("B")
            else:
                if a<b:
                    a+=1
                    b-=1
                    result.append("A")
                else:
                    a-=1
                    b+=1
                    result.append("B")
                    

        elif "AC" == order:
            if a==0 and c==0:
                print("No")
                exit()
            elif a==1 and c==1:
                if index <n-1:
                    if s[index+1]=="AB":
                        result.append("A")
                        a+=1
                        c-=1
                    elif s[index+1]=="AC":
                        result.append("A")
                        a+=1
                        c-=1
                    elif s[index+1]=="BC":
                        result.append("C")
                        a-=1
                        c+=1
                else:
                    a-=1
                    c+=1
                    result.append("C")
            else:
                if a<c:
                    a+=1
                    c-=1
                    result.append("A")
                else:
                    a-=1
                    c+=1
                    result.append("C")


        elif "BC" == order:
            if b==0 and c==0:
                print("No")
                exit()
            elif b==1 and c==1:
                if index <n-1:
                    if s[index+1]=="AB":
                        result.append("B")
                        b+=1
                        c-=1
                    elif s[index+1]=="AC":
                        result.append("C")
                        c+=1
                        b-=1
                    elif s[index+1]=="BC":
                        result.append("C")
                        b-=1
                        c+=1
                else:
                    c-=1
                    b+=1
                    result.append("B")
            else:
                if b<c:
                    b+=1
                    c-=1
                    result.append("B")
                else:
                    b-=1
                    c+=1
                    result.append("C")

        
    print("Yes")
    for item in result:
        print(item)
    exit()

Solution (Python):
N, A, B, C = map(int, input().split())
ans = []
d = {'A': A, 'B': B, 'C': C}
s = [input() for _ in range(N)]


def add_ans(s1, s2):
    d[s1] += 1
    d[s2] -= 1
    ans.append(s1)


for i in range(N):
    now = s[i]
    x = now[0]
    y = now[1]
    if d[x] == d[y] == 0:
        print('No')
        exit()
    elif d[x] == 0:
        add_ans(x, y)
    elif d[y] == 0:
        add_ans(y, x)
    elif i == N - 1:
        add_ans(x, y)
    elif x in s[i + 1]:
        add_ans(x, y)
    else:
        add_ans(y, x)

print("Yes")
for i in ans:
    print(i)

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

strs=[]
for _ in range(N):
    s=input()
    if s=='AB':
        strs.append((0,1))
    elif s=='AC':
        strs.append((0,2))
    else: 
        strs.append((1,2))

l=[A,B,C]
ans=[]
ds={0:'A',1:'B',2:'C'}

if sum(l)==0:
    print('No')
    exit()

if sum(l)==1:
    for n in range(N):
        i1,i2=strs[n]
        if l[i1]==0 and l[i2]==0:
            break
        else:
            if l[i1]==0:
                l[i1]+=1
                l[i2]-=1
                ans.append(ds[i1])
            else: 
                l[i1]-=1
                l[i2]+=1
                ans.append(ds[i2])
    else:
        print('Yes')
        print(*ans,sep='\n')
        exit()
    print('No')
    exit()

i1,i2=strs[0]
if l[i1]==0 and l[i2]==0:
    print('No')
else:
    print('Yes')
    for n in range(N):
        i1,i2=strs[n]

        if n < N-1:
            i1_n,i2_n=strs[n+1]
        else:
            i1_n,i2_n=i1,i2
        
        if l[i1]*l[i2]==0:
            if l[i1]==0:
                l[i1]+=1
                l[i2]-=1
                ans.append(ds[i1])
            else:
                l[i1]-=1
                l[i2]+=1
                ans.append(ds[i2])
        elif (l[i1]==1 or l[i2]==1) and n<N-1 and [i1,i2]!=[i1_n,i2_n]:
            if i1==i1_n or i1==i2_n:
                l[i1]+=1
                l[i2]-=1
                ans.append(ds[i1])
            else:
                l[i1]-=1
                l[i2]+=1
                ans.append(ds[i2])
        else:
            l[i1]+=1
            l[i2]-=1
            ans.append(ds[i1])
    print(*ans,sep='\n')

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  


def solve(N: int, A: int, B: int, C: int, s: "List[str]"):
    L = ["A" for _ in range(N)]
    for i in range(N):
        if s[i] == "AB":
            if A == 0 and B == 0:
                print(NO)
                return
            else:
                if A > B:
                    A -= 1
                    B += 1
                    L[i] = "B"
                elif A < B:
                    A += 1
                    B -= 1
                    L[i] = "A"
                else:
                    if i == N - 1:
                        A -= 1
                        B += 1
                        L[i] = "B"
                    else:
                        if s[i+1] == "AB":
                            A -= 1
                            B += 1
                            L[i] = "B"
                        elif s[i+1] == "BC":
                            A -= 1
                            B += 1
                            L[i] = "B"
                        else:   
                            A += 1
                            B -= 1
                            L[i] = "A"
        elif s[i] == "BC":
            if B == 0 and C == 0:
                print(NO)
                return
            else:
                if B > C:
                    B -= 1
                    C += 1
                    L[i] = "C"
                elif B < C:
                    B += 1
                    C -= 1
                    L[i] = "B"
                else:
                    if i == N - 1:
                        B -= 1
                        C += 1
                        L[i] = "C"
                    else:
                        if s[i+1] == "AB":
                            B += 1
                            C -= 1
                            L[i] = "B"
                        elif s[i+1] == "BC":
                            B -= 1
                            C += 1
                            L[i] = "C"
                        else:   
                            B -= 1
                            C += 1
                            L[i] = "C"
        else:   
            if A == 0 and C == 0:
                print(NO)
                return
            else:
                if A > C:
                    A -= 1
                    C += 1
                    L[i] = "C"
                elif A < C:
                    A += 1
                    C -= 1
                    L[i] = "A"
                else:
                    if i == N - 1:
                        A -= 1
                        C += 1
                        L[i] = "C"
                    else:
                        if s[i+1] == "AB":
                            A += 1
                            C -= 1
                            L[i] = "A"
                        elif s[i+1] == "BC":
                            A -= 1
                            C += 1
                            L[i] = "C"
                        else:   
                            A -= 1
                            C += 1
                            L[i] = "C"
    print(YES)
    for l in L:
        print(l)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = int(next(tokens))  
    B = int(next(tokens))  
    C = int(next(tokens))  
    s = [next(tokens) for _ in range(N)]  
    solve(N, A, B, C, s)

if __name__ == '__main__':
    main()

Solution (Python):
n, a, b, c = map(int, input().split())
ans = []
prev = ''
for _ in range(n):
    s = input()
    if 'C' not in s:
        if a == b == 0 and ans:
            
            prev_x = ans.pop()
            if prev_x == prev[0]:
                prev_y = prev[1]
            else:
                prev_y = prev[0]
            ans.append(prev_y)
            if prev_x == 'A':
                a -= 2
            elif prev_x == 'B':
                b -= 2
            else:
                c -= 2
            if prev_y == 'A':
                a += 2
            elif prev_y == 'B':
                b += 2
            else:
                c += 2
        if a < b:
            a += 1
            b -= 1
            ans.append('A')
        else:
            a -= 1
            b += 1
            ans.append('B')

    elif 'B' not in s:
        if a == c == 0 and ans:
            
            prev_x = ans.pop()
            if prev_x == prev[0]:
                prev_y = prev[1]
            else:
                prev_y = prev[0]
            ans.append(prev_y)

            if prev_x == 'A':
                a -= 2
            elif prev_x == 'B':
                b -= 2
            else:
                c -= 2
            if prev_y == 'A':
                a += 2
            elif prev_y == 'B':
                b += 2
            else:
                c += 2
        if a < c:
            a += 1
            c -= 1
            ans.append('A')
        else:
            a -= 1
            c += 1
            ans.append('C')
    elif 'A' not in s:
        if b == c == 0 and ans:
            
            prev_x = ans.pop()
            if prev_x == prev[0]:
                prev_y = prev[1]
            else:
                prev_y = prev[0]
            ans.append(prev_y)
            if prev_x == 'A':
                a -= 2
            elif prev_x == 'B':
                b -= 2
            else:
                c -= 2
            if prev_y == 'A':
                a += 2
            elif prev_y == 'B':
                b += 2
            else:
                c += 2
        if b < c:
            b += 1
            c -= 1
            ans.append('B')
        else:
            b -= 1
            c += 1
            ans.append('C')
    prev = s
    if -1 in (a, b, c):
        print('No')
        break
else:
    print('Yes')
    for x in ans:
        print(x)

Solution (Python):
import sys
def input():
    return sys.stdin.readline().strip()
n, a, b, c = map(int, input().split())
s = []
for _ in range(n):
    s.append(input())


ans = []
for i in range(n-1):
    if s[i] == 'BC':
        if b > c:
            ans.append('C')
            b -= 1
            c += 1
        elif b < c:
            ans.append('B')
            b += 1
            c -= 1
        elif s[i+1] == 'AB':
            ans.append('B')
            b += 1
            c -= 1
        else:
            ans.append('C')
            b -= 1
            c += 1

    elif s[i] == 'AC':
        if a > c:
            ans.append('C')
            a -= 1
            c += 1
        elif a < c:
            ans.append('A')
            a += 1
            c -= 1
        elif s[i+1] == 'BC':
            ans.append('C')
            a -= 1
            c += 1
        else:
            ans.append('A')
            a += 1
            c -= 1

    else:
        if a > b:
            ans.append('B')
            a -= 1
            b += 1
        elif a < b:
            ans.append('A')
            a += 1
            b -= 1
        elif s[i+1] == 'AC':
            ans.append('A')
            a += 1
            b -= 1
        else:
            ans.append('B')
            a -= 1
            b += 1

    if a < 0 or b < 0 or c < 0:
        print('No')
        exit()


if s[n-1] == 'BC':
    if b > c:
        ans.append('C')
        b -= 1
        c += 1
    else:
        ans.append('B')
        b += 1
        c -= 1

elif s[n-1] == 'AC':
    if a > c:
        ans.append('C')
        a -= 1
        c += 1
    else:
        ans.append('A')
        a += 1
        c -= 1

else:
    if a > b:
        ans.append('B')
        a -= 1
        b += 1
    else:
        ans.append('A')
        a += 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):
import sys
def input():
    return sys.stdin.readline().strip()
n, a, b, c = map(int, input().split())
s = []
for _ in range(n):
    s.append(input())


ans = []
for i in range(n-1):
    if s[i] == 'BC':
        if b > c:
            ans.append('C')
            b -= 1
            c += 1
        elif b < c:
            ans.append('B')
            b += 1
            c -= 1
        elif s[i+1] == 'AB':
            ans.append('B')
            b += 1
            c -= 1
        else:
            ans.append('C')
            b -= 1
            c += 1

    elif s[i] == 'AC':
        if a > c:
            ans.append('C')
            a -= 1
            c += 1
        elif a < c:
            ans.append('A')
            a += 1
            c -= 1
        elif s[i+1] == 'BC':
            ans.append('C')
            a -= 1
            c += 1
        else:
            ans.append('A')
            a += 1
            c -= 1

    else:
        if a > b:
            ans.append('B')
            a -= 1
            b += 1
        elif a < b:
            ans.append('A')
            a += 1
            b -= 1
        elif s[i+1] == 'AC':
            ans.append('A')
            a += 1
            b -= 1
        else:
            ans.append('B')
            a -= 1
            b += 1

    if a < 0 or b < 0 or c < 0:
        print('No')
        exit()


if s[n-1] == 'BC':
    if b > c:
        ans.append('C')
        b -= 1
        c += 1
    else:
        ans.append('B')
        b += 1
        c -= 1

elif s[n-1] == 'AC':
    if a > c:
        ans.append('C')
        a -= 1
        c += 1
    else:
        ans.append('A')
        a += 1
        c -= 1

else:
    if a > b:
        ans.append('B')
        a -= 1
        b += 1
    else:
        ans.append('A')
        a += 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):
n,a,b,c=map(int,input().split())
s_=[input() for i in range(n)]
ans=""
for i in range(n):
    s1,s2=s_[i]
    if s2=="B":
        if i!=n-1:
            if s_[i+1]=="AC" and c==0 and a==1:
                a,b,ans=(a+1,b-1,ans+"A")
            elif s_[i+1]=="BC" and c==0 and b==1:
                a,b,ans=(a-1,b+1,ans+"B")
            else:
                a,b,ans=(a-1,b+1,ans+"B") if a>b else (a+1,b-1,ans+"A")
        else:
            a,b,ans=(a-1,b+1,ans+"B") if a>b else (a+1,b-1,ans+"A")
        if min(a,b)==-1:
            print("No")
            break
    elif s1=="A":
        if i!=n-1:
            if s_[i+1]=="AB" and b==0 and a==1:
                a,c,ans=(a+1,c-1,ans+"A")
            elif s_[i+1]=="BC" and b==0 and c==1:
                a,c,ans=(a-1,c+1,ans+"C")
            else:
                a,c,ans=(a-1,c+1,ans+"C") if a>c else (a+1,c-1,ans+"A")
        else:
            a,c,ans=(a-1,c+1,ans+"C") if a>c else (a+1,c-1,ans+"A")
        if min(a,c)==-1:
            print("No")
            break
    else:
        if i!=n-1:
            if s_[i+1]=="AB" and a==0 and b==1:
                b,c,ans=(b+1,c-1,ans+"B")
            elif s_[i+1]=="AC" and a==0 and c==1:
                b,c,ans=(b-1,c+1,ans+"C")
            else:
                b,c,ans=(b-1,c+1,ans+"C") if b>c else (b+1,c-1,ans+"B")
        else:
            b,c,ans=(b-1,c+1,ans+"C") if b>c else (b+1,c-1,ans+"B")
        if min(b,c)==-1:
            print("No")
            break
else:
    print("Yes")
    for j in range(n):
        print(ans[j])

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

abc = {'A': a, 'B': b, 'C': c}

def answer():
    solution = []
    if a + b + c == 0:
        return False, None
    elif a + b + c == 1:
        for s in ls:
            s0, s1 = s[0], s[1]
            if abc[s0] == 1:
                abc[s0] -= 1
                abc[s1] += 1
                solution.append(s1)
            elif abc[s1] == 1:
                abc[s0] += 1
                abc[s1] -= 1
                solution.append(s0)
            else:
                return False, None
        return True, solution
    else:
        for i, s in enumerate(ls):
            s0, s1 = s[0], s[1]
            if abc[s0] == 0 and abc[s1] == 0:
                return False, None
            elif i == n - 1:
                if abc[s0] == 0:
                    abc[s0] += 1
                    abc[s1] -= 1
                    solution.append(s0)
                else:
                    abc[s0] -= 1
                    abc[s1] += 1
                    solution.append(s1)
            elif abc[s0] == 0:
                abc[s0] += 1
                abc[s1] -= 1
                solution.append(s0)
            elif abc[s1] == 0:
                abc[s0] -= 1
                abc[s1] += 1
                solution.append(s1)
            elif abc[s0] == 1 and (s0 in ls[i + 1]):
                abc[s0] += 1
                abc[s1] -= 1
                solution.append(s0)
            else:
                abc[s0] -= 1
                abc[s1] += 1
                solution.append(s1)
        return True, solution


yn, solution = answer()
if yn:
    print('Yes')
    for s in solution:
        print(s)
else:
    print('No')

Solution (Python):
N, A, B, C = list(map(int, input().split()))
d = {'A': A, 'B': B, 'C': C}
res = []
SN = [input() for i in range(N)]
for i in range(N):
    s = SN[i]
    s0 = s[0]
    s1 = s[1]

    if d[s0] == d[s1] == 0:
        print('No')
        exit()
    elif d[s0] == 0:
        d[s0] += 1
        d[s1] -= 1
        res.append(s0)
    elif d[s1] == 0:
        d[s0] -= 1
        d[s1] += 1
        res.append(s1)
    elif i == N-1:
        res.append(s0)
    elif s0 in SN[i+1]:
        d[s0] += 1
        d[s1] -= 1
        res.append(s0)
    else:
        d[s0] -= 1
        d[s1] += 1
        res.append(s1)

print('Yes')
for r in res:
    print(r)