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



Sample input:
2 1 3 0
AB
AC


Sample output:
Yes
A
C

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict

N,A,B,C=map(int, sys.stdin.readline().split())
S=[ sys.stdin.readline().strip() for _ in range(N) ]

L=[]    #i回目の選択で1を足す変数の名前を順番に格納

for i,s in enumerate(S): #0-indexed
    if s=="AB":
        if A<B:
            A+=1
            B-=1
            L.append("A")
        elif B<A:
            A-=1
            B+=1
            L.append("B")
        elif A==B==0:
            print "No"
            quit()
        elif A==B:
            next_s=S[i+1]
            if next_s=="AB":    #次が2文字とも一致している場合は、どっちの文字に1を足しても良い
                A+=1
                B-=1
                L.append("A")
            elif next_s=="AC":    #次に同じ文字が1文字出てくる場合は、その文字の方に+1
                A+=1
                B-=1
                L.append("A")
            elif next_s=="BC":    #次に同じ文字が1文字出てくる場合は、その文字の方に+1
                A-=1
                B+=1
                L.append("B")
            pass
    elif s=="AC":
        if A<C:
            A+=1
            C-=1
            L.append("A")
        elif C<A:
            A-=1
            C+=1
            L.append("C")
        elif A==C==0:
            print "No"
            quit()
        elif A==C:
            next_s=S[i+1]
            if next_s=="AC":    #次が2文字とも一致している場合は、どっちの文字に1を足しても良い
                A+=1
                C-=1
                L.append("A")
            elif next_s=="AB":    #次に同じ文字が1文字出てくる場合は、その文字の方に+1
                A+=1
                C-=1
                L.append("A")
            elif next_s=="BC":    #次に同じ文字が1文字出てくる場合は、その文字の方に+1
                A-=1
                C+=1
                L.append("C")
    elif s=="BC":
        if B<C:
            C-=1
            B+=1
            L.append("B")
        elif C<B:
            B-=1
            C+=1
            L.append("C")
        elif B==C==0:
            print "No"
            quit()
        elif B==C:
            next_s=S[i+1]
            if next_s=="BC":    #次が2文字とも一致している場合は、どっちの文字に1を足しても良い
                B+=1
                C-=1
                L.append("B")
            elif next_s=="AB":    #次に同じ文字が1文字出てくる場合は、その文字の方に+1
                B+=1
                C-=1
                L.append("B")
            elif next_s=="AC":    #次に同じ文字が1文字出てくる場合は、その文字の方に+1
                B-=1
                C+=1
                L.append("C")

print "Yes"
for x in L:
    print x

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, *abc = map(int, input().split())
s = [input()for _ in range(n)]
cond = {'AB': (0, 1), 'AC': (0, 2), 'BC': (1, 2)}
legend = ('A', 'B', 'C')
ans = []


def dfs(i):
    if -1 in abc:
        return 0
    elif i == n:
        print('Yes')
        print(*ans, sep='\n')
        exit()
        # return 0
    else:
        idx1, idx2 = cond[s[i]]
        abc[idx1] += 1
        abc[idx2] -= 1
        ans.append(legend[idx1])
        dfs(i+1)
        ans.pop()
        abc[idx1] -= 1
        abc[idx2] += 1

        abc[idx1] -= 1
        abc[idx2] += 1
        ans.append(legend[idx2])
        dfs(i+1)
        ans.pop()
        abc[idx1] += 1
        abc[idx2] -= 1


dfs(0)
print('No')

Submission status: Runtime Error

Solution code:
import sys
from collections import deque

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

    select_list = deque()
    select_list.append('Yes')
    for i, i_s in enumerate(s_list):
        if i_s == 'AB':
            if A == 0 and B == 0:
                select_list = ['No']
                break
            elif A == 1 and B == 1:
                if i+1 >= N:
                    A -= 1
                    B += 1
                    select_list.append('B')
                    continue
                if select_list[i+1] == 'AC':
                    A += 1
                    B -= 1
                    select_list.append('A')
                else:
                    A += 1
                    B -= 1
                    select_list.append('B')
            elif A > B:
                A -= 1
                B += 1
                select_list.append('B')
            else:
                A += 1
                B -= 1
                select_list.append('A')
        elif i_s == 'AC':
            if A == 0 and C == 0:
                select_list = ['No']
                break
            elif A == 1 and C == 1:
                if i+1 >= N:
                    A -= 1
                    C += 1
                    select_list.append('C')
                    continue
                if select_list[i+1] == 'AB':
                    A += 1
                    C -= 1
                    select_list.append('A')
                else:
                    A -= 1
                    C += 1
                    select_list.append('C')
            elif A > C:
                A -= 1
                C += 1
                select_list.append('C')
            else:
                A += 1
                C -= 1
                select_list.append('A')
        else:
            if B == 0 and C == 0:
                select_list = ['No']
                break
            elif B == 1 and C == 1:
                if i+1 >= N:
                    B -= 1
                    C += 1
                    select_list.append('C')
                    continue
                if select_list[i+1] == 'AB':
                    B += 1
                    C -= 1
                    select_list.append('B')
                else:
                    B -= 1
                    C += 1
                    select_list.append('C')
            elif B > C:
                B -= 1
                C += 1
                select_list.append('C')
            else:
                B += 1
                C -= 1
                select_list.append('B')

    for i in select_list:
        print(i)

    return

if __name__ == '__main__':
    main()
    sys.exit(0)

Submission status: Runtime Error

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


# def roop(abc, _S):
#     if not _S:
#         return ""

#     s = _S[0]
#     if s == "AB":
#         l1, l2 = 0, 1
#     if s == "AC":
#         l1, l2 = 0, 2
#     if s == "BC":
#         l1, l2 = 1, 2

#     if (abc[l1], abc[l2]) == (0, 0):
#         return False
#     elif abc[l1] == 0:
#         abc[l1] += 1
#         abc[l2] -= 1
#         return roop(abc, _S[1:])
#     elif abc[l2] == 0:
#         abc[l1] -= 1
#         abc[l2] += 1
#         return roop(abc, _S[1:])
#     else:


tt = sorted([A, B, C])
if tt[:2] == [0, 0] or tt == [0, 1, 1]:
    pri = ""
    abc = [A, B, C]
    chara = ["A", "B", "C"]

    for i in range(N):
        l1, l2 = chara.index(S[i][0]), chara.index(S[i][1])

        if (abc[l1], abc[l2]) == (0, 0):
            break
        elif abc[l1] == 0:
            abc[l1] += 1
            abc[l2] -= 1
            pri += (chara[l1] + "\n")
        elif abc[l2] == 0:
            abc[l1] -= 1
            abc[l2] += 1
            pri += (chara[l2] + "\n")
        else:
            l3, l4 = chara.index(S[i+1][0]), chara.index(S[i+1][1])
            amari = ["A", "B", "C"].pop(l2).pop(l1)
            if sorted([amari, l2]) == [l3, l4]:
                abc[l1] -= 1
                abc[l2] += 1
                pri += (chara[l2] + "\n")
            else:
                abc[l1] += 1
                abc[l2] -= 1
                pri += (chara[l1] + "\n")
    else:
        print(pri)

    print("No")


else:
    for s in S:
        if s == "AB":
            if A > B:
                A -= 1
                B += 1
                print("B")
            else:
                B -= 1
                A += 1
                print("A")

        if s == "AC":
            if A > C:
                A -= 1
                C += 1
                print("C")
            else:
                C -= 1
                A += 1
                print("A")

        if s == "BC":
            if C > B:
                C -= 1
                B += 1
                print("B")
            else:
                B -= 1
                C += 1
                print("C")

Submission status: Runtime Error

Solution code:
def recur(A, B, C, events, prev):
    if len(events) == 0:
        return(prev)

    if events[0] == "AC":
        if C > 0:
            return recur(A + 1, B, C - 1, events[1:], prev + "A")
        if A > 0:
            return recur(A - 1, B, C + 1, events[1:], prev + "C")
    elif events[0] == "AB":
        if B > 0:
            return recur(A + 1, B - 1, C, events[1:], prev + "A")
        if A > 0:
            return recur(A - 1, B + 1, C, events[1:], prev + "B")
    else:
        if C > 0:
            return recur(A, B + 1, C - 1, events[1:], prev + "B")
        if B > 0:
            return recur(A, B - 1, C + 1, events[1:], prev + "C")
    
N, A, B, C = map(int, input().split())

events = []
for n in range(0, N): events.append(input())

ans = recur(A, B, C, events, "")

if not ans:
    print("No")
else:
    print("Yes")
    for c in ans:
        print(c)

Submission status: Runtime Error

Solution code:
N, A, B, C = map(int, input().split())
if A + B + C == 0:
    print('No')
elif A + B + C == 1:
    res = []
    for _ in range(N):
        s = input()
        if s == 'AB':
            if A == 0 and B == 0:
                print('No')
                break
            elif A == 0:
                A += 1
                B -= 1
                res.append('A')
            else:
                A -= 1
                B += 1
                res.append('B')
        elif s == 'AC':
            if A == 0 and C == 0:
                print('No')
                break
            elif A == 0:
                A += 1
                C -= 1
                res.append('A')
            else:
                A -= 1
                C += 1
                res.append('C')
        else:
            if B == 0 and C == 0:
                print('No')
                breal
            elif B == 0:
                B += 1
                C -= 1
                res.append('B')
            else:
                B -= 1
                C += 1
                res.append('C')
    else:
        print('Yes')
        print('\n'.join(res))
else:
    res = []
    s = input()
    if (s == 'AB' and A == 0 and B == 0) or (s == 'AC' and A == 0 and C == 0) or (s == 'BC' and B == 0 and C == 0):
        print('No')
    else:
        for _ in range(N - 1):
            next = input()
            if s == 'AB':
                if A == 0:
                    B -= 1
                    A += 1
                    res.append('A')
                elif B == 0:
                    B += 1
                    A -= 1
                    res.append('B')
                else:
                    if next == 'AB':
                        A += 1
                        B -= 1
                        res.append('A')
                    elif next == 'AC':
                        A += 1
                        B -= 1
                        res.append('A')
                    else:
                        A -= 1
                        B += 1
                        res.append('B')
            if s == 'AC':
                if A == 0:
                    C -= 1
                    A += 1
                    res.append('A')
                elif C == 0:
                    C += 1
                    A -= 1
                    res.append('C')
                else:
                    if next == 'AC':
                        A += 1
                        C -= 1
                        res.append('C')
                    elif next == 'AB':
                        A += 1
                        C -= 1
                        res.append('A')
                    else:
                        A -= 1
                        C += 1
                        res.append('C')
            if s == 'BC':
                if C == 0:
                    B -= 1
                    C += 1
                    res.append('C')
                elif B == 0:
                    B += 1
                    C -= 1
                    res.append('B')
                else:
                    if next == 'CB':
                        C += 1
                        B -= 1
                        res.append('C')
                    elif next == 'AC':
                        C += 1
                        B -= 1
                        res.append('C')
                    else:
                        C -= 1
                        B += 1
                        res.append('B')
            s = next
        if s == 'AB':
            if A == 0:
                A += 1
                B -= 1
                res.append('A')
            else:
                A -= 1
                B += 1
                res.append('B')
        elif s == 'AC':
            if A == 0:
                A += 1
                C -= 1
                res.append('A')
            else:
                A -= 1
                C += 1
                res.append('C')
        else:
            if B == 0:
                B += 1
                C -= 1
                res.append('B')
            else:
                B -= 1
                C += 1
                res.append('C')
        print('Yes')
        print('\n'.join(res))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
abc = ["A","B","C"]

def calculate(x,y, q1,q2):
    flag = 0
    ans = ""
    if x == 1 and y == 1:
        if q1 == q2:
            y -= 1
            x += 1
            ans = abc[q1[0]]

        elif q2 != "":
            t = set(q1) & set(q2)
            s = set(q1) - t
            "print(q2)
            #print(int(list(t)[0]),int(list(s)[0]))
            if int(list(t)[0]) < int(list(s)[0]):
                y -= 1
                x += 1
                ans = abc[q1[0]]
            else:
                x -= 1
                y += 1
                ans = abc[q1[1]]
        else:
            y -= 1
            x += 1
            ans = abc[q1[0]]

    elif x <= y:
        y -= 1
        x += 1
        #print(y)
        if y < 0:
            print("No")
            flag = 1
            return(x, y, ans, flag)
        ans = abc[q1[0]]
    else:
        x -= 1
        y += 1
        ans = ""
        #print(x)
        if x < 0:
            print("No")
            flag = 1
            return(x, y, ans, flag)
        ans = abc[q1[1]]
    return (x, y, ans, flag)

def main():
    N, A, B, C  =  [int(i) for i in input().split()]
    s = []
    for i in range(N):
        t = input()
        if t == "AB":
            s.append([0,1])
        if t == "AC":
            s.append([0,2])
        if t == "BC":
            s.append([1,2])
    #print(s)
    answers  = []
    for i, q1 in enumerate(s):
        ans = ""
        f = 0
        q2 = ""
        if i+1 != N:
            q2 = s[i+1]

        if q1 == [0,1]:
            #print(1)
            A, B, ans, f = calculate(A,B,q1,q2)
        if q1 == [1,2]:
            #print(2)
            B, C, ans,f  = calculate(B,C,q1,q2)
        if q1 == [0,2]:
            #print(3)
            A, C, ans,f  = calculate(A,C,q1,q2)
        answers.append(ans)
        if f == 1:
            return
    print("Yes")

    for a in answers:
        print(a)
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
abc = ["A","B","C"]

def calculate(x,y, q1,q2):
    flag = 0
    ans = ""
    if x == 1 and y == 1:
        if q1 == q2:
            y -= 1
            x += 1
            #print(y)
            if y < 0:
                print("No")
                flag = 1
                return(x, y, ans, flag)
            ans = abc[q1[0]]

        elif q2 != "":
            t = set(q1) & set(q2)
            s = set(q1) - t
            #print(int(list(t)[0]),int(list(s)[0]))
            if int(list(t)[0] < int(list(s)[0]):
                y -= 1
                x += 1
                ans = abc[q1[0]]
            else:
                x -= 1
                y += 1
                ans = abc[q1[1]]

    elif x <= y:
        y -= 1
        x += 1
        #print(y)
        if y < 0:
            print("No")
            flag = 1
            return(x, y, ans, flag)
        ans = abc[q1[0]]
    else:
        x -= 1
        y += 1
        ans = ""
        #print(x)
        if x < 0:
            print("No")
            flag = 1
            return(x, y, ans, flag)
        ans = abc[q1[1]]
    return (x, y, ans, flag)

def main():
    N, A, B, C  =  [int(i) for i in input().split()]
    s = []
    for i in range(N):
        t = input()
        if t == "AB":
            s.append([0,1])
        if t == "AC":
            s.append([0,2])
        if t == "BC":
            s.append([1,2])
    #print(s)
    answers  = []
    for i, q1 in enumerate(s):
        ans = ""
        f = 0
        q2 = ""
        if i+1 != N:
            q2 = s[i+1]

        if q1 == [0,1]:
            #print(1)
            A, B, ans, f = calculate(A,B,q1,q2)
        if q1 == [1,2]:
            #print(2)
            B, C, ans,f  = calculate(B,C,q1,q2)
        if q1 == [0,2]:
            #print(3)
            A, C, ans,f  = calculate(A,C,q1,q2)
        answers.append(ans)
        if f == 1:
            return
    print("Yes")

    for a in answers:
        print(a)
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n,a,b,c = inpm()
    s = []
    ans = []
    for i in range(n):
        S = input()
        s.append(S)
    for i in range(n):
        s = S[i]
        if s == 'AB':
            if a == 0 and b == 0:
                print('No')
                return
            if a == 0:
                a += 1
                b -= 1
                ans.append('A')
            elif b == 0:
                a -= 1
                b += 1
                ans.append('B')
            elif a == 1 and b == 1 and i < n-1 and s != S[i+1]:
                if S[i+1] == 'AC':
                    a += 1
                    b -= 1
                    ans.append('A')
                else:
                    b += 1
                    a -= 1
                    ans.append('B')
            else:
                if a > b:
                    a -= 1
                    b += 1
                    ans.append('B')
                else:
                    a += 1
                    b -= 1
                    ans.append('A')
        if s == 'AC':
            if a == 0 and c == 0:
                print('No')
                return
            if a == 0:
                a += 1
                c -= 1
                ans.append('A')
            elif c == 0:
                a -= 1
                c += 1
                ans.append('C')
            elif a == 1 and c == 1 and i < n-1 and s != S[i+1]:
                if S[i+1] == 'AB':
                    a += 1
                    c -= 1
                    ans.append('A')
                else:
                    c += 1
                    a -= 1
                    ans.append('C')
            else:
                if a > c:
                    a -= 1
                    c += 1
                    ans.append('C')
                else:
                    a += 1
                    c -= 1
                    ans.append('A')
        if s == 'BC':
            if c == 0 and b == 0:
                print('No')
                return
            if b == 0:
                b += 1
                c -= 1
                ans.append('B')
            elif c == 0:
                b -= 1
                c += 1
                ans.append('C')
            elif b == 1 and c == 1 and i < n-1 and s != S[i+1]:
                if S[i+1] == 'AB':
                    b += 1
                    c -= 1
                    ans.append('B')
                else:
                    c += 1
                    b -= 1
                    ans.append('C')
            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])

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
for i in range(int(N)):
    s.append(input())

r =''
select =''
result = []
#print(' ',A,B,C)

for i in range(N):
    if (A== 0 and B ==0) :
        if s[i] == 'AB': 
            r = 'No'
            break
    if  (C== 0 and B ==0):
        if s[i] == 'BC':
            r = 'No'
            break
    if  (A== 0 and C ==0):
        if s[i] == 'AC': 
            r = 'No'
            break

    if s[i] == 'AB':
        if A*B == 1:
            if i < N:
                if s[i] == 'BC':
                    A += -1
                    B += +1
                    select ='B'
                if s[i] == 'AC':
                    A += +1
                    B += -1
                    select ='A'
            else:
                A += +1
                B += -1
                select ='A'

        else :
            if A <= B:    
                select ='A'
                A += +1
                B += -1
            else:
                select ='B'
                A += -1
                B += +1

                
    if s[i] == 'BC':
        if B*C == 1:
            if i < N:
                if s[i] == 'AB':
                    select ='B'
                    C += -1
                    B += +1
                if s[i] == 'AC':
                    select ='C'
                    C += +1
                    B += -1
            else:
                select ='B'
                B += +1
                C += -1

        else :
            if B <= C:    
                select ='B'
                B += +1
                C += -1
            else:
                select ='C'
                B += -1
                C += +1
            
    if s[i] == 'AC':
        if A*C == 1:
            if i < N:
                if s[i] == 'BC':
                    A += -1
                    C += +1
                    select ='C'
                if s[i] == 'AB':
                    A += +1
                    C += -1
                    select ='A'
            else:
                A += +1
                C += -1
                select ='A'

        else :
            if A <= C:    
                select ='C'
                A += -1
                C += +1
            else:
                select ='A'
                A += +1
                C += -1
    result.append(select)

if r == 'No':
    print('No')
else: 
    print('Yes')
    for i in range(N):
        print(result[i])

Submission status: Runtime Error

Solution code:
def main():
    n, a, b, c = map(int, input().split())
    s_list = [input() for _ in [0]*n]

    if a == b == c == 0:
        print("No")
    elif a+b+c == 1:
        if a == 1:
            color = "A"
        elif b == 1:
            color = "B"
        else:
            color = "C"
        l = []
        for i in s_list:
            if color not in i:
                print("No")
                return
            j = list(i)
            j.remove(color)
            color = j[0]
            l.append(color)
        print("Yes")
        for i in l:
            print(i)
    else:
        print(1/0)
        s_list += ["ABC"]
        l = []
        for j, i in enumerate(s_list[:-1]):
            if i == "AB":
                if a >= 2:
                    l.append("B")
                    a -= 1
                    b += 1
                elif b >= 2:
                    l.append("A")
                    a += 1
                    b -= 1
                elif a == b == 0:
                    print("No")
                    return
                elif a == 1 and b == 0:
                    l.append("B")
                    a -= 1
                    b += 1
                elif a == 0 and b == 1:
                    l.append("A")
                    a += 1
                    b -= 1
                else:
                    if "A" in s_list[j+1]:
                        l.append("A")
                        a += 1
                        b -= 1
                    else:
                        l.append("B")
                        a -= 1
                        b += 1
            elif i == "BC":
                if b >= 2:
                    l.append("C")
                    b -= 1
                    c += 1
                elif c >= 2:
                    l.append("B")
                    b += 1
                    c -= 1
                elif b == c == 0:
                    print("No")
                    return
                elif b == 1 and c == 0:
                    l.append("C")
                    b -= 1
                    c += 1
                elif b == 0 and c == 1:
                    l.append("B")
                    b += 1
                    c -= 1
                else:
                    if "B" in s_list[j+1]:
                        l.append("B")
                        b += 1
                        c -= 1
                    else:
                        l.append("C")
                        b -= 1
                        c += 1
            else:
                if c >= 2:
                    l.append("A")
                    c -= 1
                    a += 1
                elif a >= 2:
                    l.append("C")
                    c += 1
                    a -= 1
                elif c == a == 0:
                    print("No")
                    return
                elif c == 1 and a == 0:
                    l.append("A")
                    c -= 1
                    a += 1
                elif c == 0 and a == 1:
                    l.append("C")
                    c += 1
                    a -= 1
                else:
                    if "C" in s_list[j+1]:
                        l.append("C")
                        c += 1
                        a -= 1
                    else:
                        l.append("A")
                        c -= 1
                        a += 1
        print("Yes")
        for i in l:
            print(i)


main()