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):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B, C = mapint()
costs = {'A': A, 'B': B, 'C': C}
old_a, old_b = list(input())

if costs[old_a]==0 and costs[old_b]==0:
    print('No')
    exit()

commands = []
for _ in range(N-1):
    nx_a, nx_b = list(input())
    if costs[old_a]==0 and costs[old_b]==0:
        print('No')
        exit()
    elif costs[old_a]==0:
        costs[old_a] += 1
        costs[old_b] -= 1
        commands.append(old_a)
        
    elif costs[old_b]==0:
        costs[old_b] += 1
        costs[old_a] -= 1
        commands.append(old_b)

    else:
        if old_a==nx_a or old_a==nx_b:
            commands.append(old_a)
            costs[old_a] += 1
            costs[old_b] -= 1
        else:
            commands.append(old_b)
            costs[old_b] += 1
            costs[old_a] -= 1
    old_a, old_b = nx_a, nx_b

if costs[old_a]==0 and costs[old_b]==0:
    print('No')
    exit()
elif costs[old_a]==0:
    costs[old_a] += 1
    costs[old_b] -= 1
    commands.append(old_a)
    
else:
    costs[old_b] += 1
    costs[old_a] -= 1
    commands.append(old_b)

print('Yes')
print('\n'.join(commands))

Solution (Python):
N,A,B,C = map(int,input().split())
valid = True
array = []
for i in range(N):
    s = input()
    array.append(s)
array2 = []
for i in range(N):
    if array[i] == "AB":
        if A == B == 0:
            valid = False
            break
        elif i != N-1 and A == B and array[i+1] == "AC":
            A += 1
            B -= 1
            array2.append("A")
        elif i != N-1 and A == B and array[i+1] == "BC":
            A -= 1
            B += 1
            array2.append("B")
        elif A <= B:
            A += 1
            B -= 1
            array2.append("A")
        else:
            A -= 1
            B += 1
            array2.append("B")
    elif array[i] == "AC":
        if A == C == 0:
            valid = False
            break
        elif i != N-1 and A == C and array[i+1] == "BC":
            A -= 1
            C += 1
            array2.append("C")
        elif i != N-1 and A == C and array[i+1] == "AC":
            A += 1
            C -= 1
            array2.append("A")
        elif A <= C:
            A += 1
            C -= 1
            array2.append("A")
        else:
            A -= 1
            C += 1
            array2.append("C")
    else:
        if B == C == 0:
            valid = False
            break
        elif i != N-1 and B == C and array[i+1] == "AC":
            B -= 1
            C += 1
            array2.append("C")
        elif i != N-1 and B == C and array[i+1] == "AB":
            B += 1
            C -= 1
            array2.append("B")
        elif B <= C:
            B += 1
            C -= 1
            array2.append("B")
        else:
            B -= 1
            C += 1
            array2.append("C")
if valid:
    print("Yes")
    for i in range(len(array2)):
        print(array2[i])
else:
    print("No")

Solution (Python):
import sys
input = sys.stdin.readline
n, a, b, c = map(int, input().split())
S = [input().rstrip().replace("AC", "CA") for _ in range(n)]
D = ["AB", "BC", "CA"]
X = [a+b, b+c, c+a]
L = []
for i, s in enumerate(S):
  k = D.index(s)
  if X[k] == 0:
    print("No")
    exit()
  if X[(k+1)%3] == 1 and X[(k+2)%3] == 1 and i < n-1:
    l = D.index(S[i+1])
    if l == (k+1)%3:
      X[(k+1)%3] += 1
      X[(k+2)%3] -= 1
      L.append(s[1])
    else:
      X[(k+2)%3] += 1
      X[(k+1)%3] -= 1
      L.append(s[0])
  else:
    if X[(k+1)%3] < X[(k+2)%3]:
      X[(k+1)%3] += 1
      X[(k+2)%3] -= 1
      L.append(s[1])
    else:
      X[(k+2)%3] += 1
      X[(k+1)%3] -= 1
      L.append(s[0])
print("Yes")
print(*L, sep="\n")

Solution (Python):
n, a, b, c = (int(x) for x in input().split())
d = {"A": a, "B": b, "C": c}
S = [input() for _ in range(n)]
ANS = []

for i, s in enumerate(S):
    if d[s[0]] == 0 and d[s[1]] == 0:
        print("No")
        exit()
    else:
        if d[s[0]] > d[s[1]] or (d[s[0]] == d[s[1]] == 1 and i < n - 1 and s[1] in S[i + 1]):
            d[s[1]] += 1
            d[s[0]] -= 1
            ANS.append(s[1])
        else:
            d[s[0]] += 1
            d[s[1]] -= 1
            ANS.append(s[0])
print("Yes")
for ans in ANS:
    print(ans)

Solution (Python):
n,a,b,c=map(int,input().split())
s=[input() for _ in range(n)]
abc=[a,b,c]
d={'A':0,'B':1,'C':2}
dr={0:'A',1:'B',2:'C'}
ans=[]
for i,x in enumerate(s):
  x=[d[y] for y in list(x)]
  if abc[x[0]]==abc[x[1]]==1 and i<n-1:
    nx=[d[y] for y in list(s[i+1])]
    for j,y in enumerate(x):
      if y in nx:
        abc[y]+=1
        abc[x[(j+1)%2]]-=1
        ans.append(dr[y])
        break
  elif abc[x[0]]>abc[x[1]]:
    abc[x[1]]+=1
    abc[x[0]]-=1
    ans.append(dr[x[1]])
  else:
    abc[x[0]]+=1
    abc[x[1]]-=1
    ans.append(dr[x[0]])
  for y in abc:
    if y<0:
      print('No')
      exit()
  
print('Yes')
print(*ans,sep='\n')

Solution (Python):
N, A, B, C = map(int, input().split())
SS, res = [], []
for _ in range(N):
    SS.append(input().rstrip())
SS += ["
for i in range(N):
    S = SS[i]
    if S=="AB":
        if A==B==1:
            if SS[i+1]=="BC": A, B = A-1, B+1; res.append("B")
            else: A, B = A+1, B-1; res.append("A")
        elif A>B: A, B = A-1, B+1; res.append("B")
        else: A, B = A+1, B-1; res.append("A")
    if S=="AC":
        if A==C==1:
            if SS[i+1]=="BC": A, C = A-1, C+1; res.append("C")
            else: A, C = A+1, C-1; res.append("A")
        elif A>C: A, C = A-1, C+1; res.append("C")
        else: A, C = A+1, C-1; res.append("A")
    if S=="BC":
        if B==C==1:
            if SS[i+1]=="AC": B, C = B-1, C+1; res.append("C")
            else: B, C = B+1, C-1; res.append("B")
        elif B>C: B, C = B-1, C+1; res.append("C")
        else: B, C = B+1, C-1; res.append("B")
    if A<0 or B<0 or C<0:
        print("No")
        exit()
print("Yes")
print(*res, sep="\n")

Solution (Python):
def f(s):
    if s == "A":
        return A
    elif s == "B":
        return B
    elif s == "C":
        return C


def inc(s):
    global A, B, C

    if s == "A":
        A += 1
    elif s == "B":
        B += 1
    elif s == "C":
        C += 1


def dec(s):
    global A, B, C

    if s == "A":
        A -= 1
    elif s == "B":
        B -= 1
    elif s == "C":
        C -= 1


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

if A + B + C == 0:
    print("No")

elif A + B + C == 1:
    ans = []
    for _ in range(N):
        s = input()
        if f(s[0]) == f(s[1]) == 0:
            print("No")
            exit()
        else:
            if f(s[0]) == 1:
                ans.append(s[1])
                dec(s[0])
                inc(s[1])
            elif f(s[1]) == 1:
                ans.append(s[0])
                inc(s[0])
                dec(s[1])
    print("Yes")
    for i in range(N):
        print(ans[i])

elif A + B + C >= 2:
    s = []
    for i in range(N):
        s.append(input())

    
    
    if f(s[0][0]) == f(s[0][1]) == 0:
        print("No")
        exit()

    ans = []
    for i in range(len(s)):
        if f(s[i][0]) >= 1 and f(s[i][1]) == 0:
            ans.append(s[i][1])
            dec(s[i][0])
            inc(s[i][1])
        elif f(s[i][0]) == 0 and f(s[i][1]) >= 1:
            ans.append(s[i][0])
            inc(s[i][0])
            dec(s[i][1])
        
        elif (A + B + C == 2) and (f(s[i][0]) == f(s[i][1]) == 1) and (i < N - 1):
            
            if s[i][0] == s[i + 1][0] or s[i][0] == s[i + 1][1]:
                ans.append(s[i][0])
                inc(s[i][0])
                dec(s[i][1])
            
            elif s[i][1] == s[i + 1][0] or s[i][1] == s[i + 1][1]:
                ans.append(s[i][1])
                dec(s[i][0])
                inc(s[i][1])
        else:
            if f(s[i][0]) <= f(s[i][1]):
                ans.append(s[i][0])
                inc(s[i][0])
                dec(s[i][1])
            else:
                ans.append(s[i][1])
                inc(s[i][1])
                dec(s[i][0])

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

Solution (Python):
def f(s):
    if s == "A":
        return A
    elif s == "B":
        return B
    elif s == "C":
        return C


def inc(s):
    global A, B, C

    if s == "A":
        A += 1
    elif s == "B":
        B += 1
    elif s == "C":
        C += 1


def dec(s):
    global A, B, C

    if s == "A":
        A -= 1
    elif s == "B":
        B -= 1
    elif s == "C":
        C -= 1


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

if A + B + C == 0:
    print("No")

elif A + B + C == 1:
    ans = []
    for _ in range(N):
        s = input()
        if f(s[0]) == f(s[1]) == 0:
            print("No")
            exit()
        else:
            if f(s[0]) == 1:
                ans.append(s[1])
                dec(s[0])
                inc(s[1])
            elif f(s[1]) == 1:
                ans.append(s[0])
                inc(s[0])
                dec(s[1])
    print("Yes")
    for i in range(N):
        print(ans[i])

elif A + B + C >= 2:
    s = []
    for i in range(N):
        s.append(input())

    if f(s[0][0]) == f(s[0][1]) == 0:
        print("No")
        exit()

    ans = []
    for i in range(len(s)):
        if f(s[i][0]) >= 1 and f(s[i][1]) == 0:
            ans.append(s[i][1])
            dec(s[i][0])
            inc(s[i][1])
        elif f(s[i][0]) == 0 and f(s[i][1]) >= 1:
            ans.append(s[i][0])
            inc(s[i][0])
            dec(s[i][1])
        elif (A + B + C == 2) and (f(s[i][0]) == f(s[i][1]) == 1) and (i < N - 1) and (s[i] != s[i + 1]):
            if s[i][0] == s[i + 1][0] or s[i][0] == s[i + 1][1]:
                ans.append(s[i][0])
                inc(s[i][0])
                dec(s[i][1])
            elif s[i][1] == s[i + 1][0] or s[i][1] == s[i + 1][1]:
                ans.append(s[i][1])
                dec(s[i][0])
                inc(s[i][1])
        else:
            
            if f(s[i][0]) == 1:
                ans.append(s[i][0])
                inc(s[i][0])
                dec(s[i][1])
            else:
                ans.append(s[i][1])
                inc(s[i][1])
                dec(s[i][0])
                
    print("Yes")
    for i in range(N):
        print(ans[i])

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:
    ans = []
    for i in range(N):
        
        if A == 1:
            if S[i] == "BC":
                print("No")
                exit()
            elif S[i] == "AB":
                ans.append("B")
                A, B, C = 0, 1, 0
            elif S[i] == "AC":
                ans.append("C")
                A, B, C = 0, 0, 1
        
        elif B == 1:
            if S[i] == "AC":
                print("No")
                exit()
            elif S[i] == "AB":
                ans.append("A")
                A, B, C = 1, 0, 0
            elif S[i] == "BC":
                ans.append("C")
                A, B, C = 0, 0, 1
        
        elif C == 1:
            if S[i] == "AB":
                print("No")
                exit()
            elif S[i] == "BC":
                ans.append("B")
                A, B, C = 0, 1, 0
            elif S[i] == "AC":
                ans.append("A")
                A, B, C = 1, 0, 0

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



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

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def S(): return sys.stdin.readline().rstrip()


N,A,B,C = MI()
X = [S() for _ in range(N)]

if A+B+C == 0:
    print('No')

elif A+B+C == 1:
    ANS = []
    for i in range(N):
        if A == 1:
            if X[i] == 'BC':
                print('No')
                break
            elif X[i] == 'AB':
                ANS.append('B')
                A,B,C = 0,1,0
            else:
                ANS.append('C')
                A,B,C = 0,0,1
        elif B == 1:
            if X[i] == 'AC':
                print('No')
                break
            elif X[i] == 'AB':
                ANS.append('A')
                A,B,C = 1,0,0
            else:
                ANS.append('C')
                A,B,C = 0,0,1
        else:
            if X[i] == 'AB':
                print('No')
                break
            elif X[i] == 'BC':
                ANS.append('B')
                A,B,C = 0,1,0
            else:
                ANS.append('A')
                A,B,C = 1,0,0
    else:
        print('Yes')
        print(*ANS,sep='\n')

else:
    if X[0] == 'AB' and C == A+B+C:
        print('No')
    elif X[0] == 'BC' and A == A+B+C:
        print('No')
    elif X[0] == 'AC' and B == A+B+C:
        print('No')
    else:
        print('Yes')
        ANS = []
        if A+B+C >= 3:
            for i in range(N):
                if X[i] == 'AB':
                    if A > B:
                        A -= 1
                        B += 1
                        ANS.append('B')
                    else:
                        A += 1
                        B -= 1
                        ANS.append('A')
                elif X[i] == 'AC':
                    if A > C:
                        A -= 1
                        C += 1
                        ANS.append('C')
                    else:
                        A += 1
                        C -= 1
                        ANS.append('A')
                else:
                    if B > C:
                        B -= 1
                        C += 1
                        ANS.append('C')
                    else:
                        B += 1
                        C -= 1
                        ANS.append('B')
        else:
            for i in range(N):
                if A == B == 1 and X[i] == 'AB' and i < N-1:
                    if X[i+1] == 'AC':
                        ANS.append('A')
                        A += 1
                        B -= 1
                    else:
                        ANS.append('B')
                        A -= 1
                        B += 1
                elif A == C == 1 and X[i] == 'AC' and i < N-1:
                    if X[i+1] == 'AB':
                        ANS.append('A')
                        A += 1
                        C -= 1
                    else:
                        ANS.append('C')
                        A -= 1
                        C += 1
                elif B == C == 1 and X[i] == 'BC' and i < N-1:
                    if X[i+1] == 'AB':
                        ANS.append('B')
                        B += 1
                        C -= 1
                    else:
                        ANS.append('C')
                        B -= 1
                        C += 1
                else:
                    if X[i] == 'AB':
                        if A > B:
                            A -= 1
                            B += 1
                            ANS.append('B')
                        else:
                            A += 1
                            B -= 1
                            ANS.append('A')
                    elif X[i] == 'AC':
                        if A > C:
                            A -= 1
                            C += 1
                            ANS.append('C')
                        else:
                            A += 1
                            C -= 1
                            ANS.append('A')
                    else:
                        if B > C:
                            B -= 1
                            C += 1
                            ANS.append('C')
                        else:
                            B += 1
                            C -= 1
                            ANS.append('B')

        print(*ANS,sep='\n')

Solution (Python):
import sys
input = sys.stdin.readline
N,A,B,C = map(int,input().split())
S = [input().rstrip() for i in range(N)]

if A==B==C==0:
    print('No')
    exit()

if A+B+C == 1:
    ans = []
    for s in S:
        if (s=='AB' and A+B==0) or (s=='AC' and A+C==0) or (s=='BC' and B+C==0):
            print('No')
            exit()
        if s=='AB':
            if A<B:
                ans.append('A')
            else:
                ans.append('B')
            A,B = B,A
        if s=='AC':
            if A<C:
                ans.append('A')
            else:
                ans.append('C')
            A,C = C,A
        if s=='BC':
            if B<C:
                ans.append('B')
            else:
                ans.append('C')
            B,C = C,B
    print('Yes')
    print(*ans, sep='\n')

else:
    ans = []
    for i,s in enumerate(S):
        if (s=='AB' and A+B==0) or (s=='AC' and A+C==0) or (s=='BC' and B+C==0):
            print('No')
            exit()
        if s=='AB':
            if A==0:
                ans.append('A')
                A += 1
                B -= 1
            elif B==0:
                ans.append('B')
                B += 1
                A -= 1
            elif A==B==1:
                if i == N-1 or C > 0 or S[i+1]=='AB':
                    ans.append('A')
                    A += 1
                    B -= 1
                elif S[i+1]=='AC':
                    ans.append('A')
                    A += 1
                    B -= 1
                else:
                    ans.append('B')
                    B += 1
                    A -= 1
            elif A < B:
                ans.append('A')
                A += 1
                B -= 1
            else:
                ans.append('B')
                B += 1
                A -= 1
        if s=='AC':
            if A==0:
                ans.append('A')
                A += 1
                C -= 1
            elif C==0:
                ans.append('C')
                C += 1
                A -= 1
            elif A==C==1:
                if i == N-1 or B > 0 or S[i+1]=='AC':
                    ans.append('C')
                    C += 1
                    A -= 1
                elif S[i+1]=='AB':
                    ans.append('A')
                    A += 1
                    C -= 1
                else:
                    ans.append('C')
                    C += 1
                    A -= 1
            elif C < A:
                ans.append('C')
                C += 1
                A -= 1
            else:
                ans.append('A')
                A += 1
                C -= 1
        if s=='BC':
            if B==0:
                ans.append('B')
                B += 1
                C -= 1
            elif C==0:
                ans.append('C')
                C += 1
                B -= 1
            elif B==C==1:
                if i == N-1 or A > 0 or S[i+1]=='BC':
                    ans.append('B')
                    B += 1
                    C -= 1
                elif S[i+1]=='AB':
                    ans.append('B')
                    B += 1
                    C -= 1
                else:
                    ans.append('C')
                    C += 1
                    B -= 1
            elif B < C:
                ans.append('B')
                B += 1
                C -= 1
            else:
                ans.append('C')
                C += 1
                B -= 1
    print('Yes')
    print(*ans, sep='\n')

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

S = stdin.read().split()


if (A and B or B and C or C and A) and A+B+C >= 3:
    ans = []
    ans.append('Yes')
    for s in S:
        if s == 'AB':
            if A < B:
                A += 1
                B -= 1
                ans.append('A')
            else:
                A -= 1
                B += 1
                ans.append('B')
        elif s == 'AC':
            if A < C:
                C -= 1
                A += 1
                ans.append('A')
            else:
                A -= 1
                C += 1
                ans.append('C')
        else:
            if B < C:
                C -= 1
                B += 1
                ans.append('B')
            else:
                B -= 1
                C += 1
                ans.append('C')
    print('\n'.join(ans))
    exit()

ans = []
for i, s in enumerate(S):
    if s == 'AB':
        if A==B==1 and C==0 and i < N-1:
            if S[i+1] == 'AC':
                A += 1
                B -= 1
                ans.append('A')
                continue
            elif S[i+1] == 'BC':
                A -= 1
                B += 1
                ans.append('B')
                continue
        if A < B:
            A += 1
            B -= 1
            ans.append('A')
        else:
            A -= 1
            B += 1
            ans.append('B')

    elif s == 'AC':
        if A==C==1 and B==0 and i < N-1:
            if S[i+1] == 'AB':
                A += 1
                C -= 1
                ans.append('A')
                continue
            elif S[i+1] == 'BC':
                A -= 1
                C += 1
                ans.append('C')
                continue
        if A < C:
            A += 1
            C -= 1
            ans.append('A')
        else:
            A -= 1
            C += 1
            ans.append('C')
    else:
        if B==C==1 and A==0 and i < N-1:
            if S[i+1] == 'AB':
                B += 1
                C -= 1
                ans.append('B')
                continue
            elif S[i+1] == 'AC':
                B -= 1
                C += 1
                ans.append('C')
                continue
        if B < C:
            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')
        exit()

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

Solution (Python):
N,A,B,C = map(int,input().split())
C = {"A":A,"B":B,"C":C}
S = [input().strip() for _ in range(N)]
D = []
flag = 0
for i in range(N):
    a,b = S[i][0],S[i][1]
    if C[a]>C[b]:
        C[a] -= 1
        C[b] += 1
        D.append(b)
    elif C[b]>C[a]:
        C[b] -= 1
        C[a] += 1
        D.append(a)
    else:
        if C[a]>1:
            C[a] -= 1
            C[b] += 1
            D.append(b)
        elif C[a]==1:
            if i==N-1:
                D.append(b)
            elif S[i]==S[i+1]:
                C[a] -= 1
                C[b] += 1
                D.append(b)
            else:
                if a in S[i+1]:
                    C[a] += 1
                    C[b] -= 1
                    D.append(a)
                else:
                    C[a] -= 1
                    C[b] += 1
                    D.append(b)
        else:
            flag = 1
            break
    if C["A"]<0 or C["B"]<0 or C["C"]<0:
        flag = 1
        break
if flag==1:
    print("No")
else:
    print("Yes")
    for i in range(N):
        print(D[i])