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: Wrong Answer

Solution code:

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

SL = []
nonZero = 0
nonZero += A>0
nonZero += B>0
nonZero += C>0

for i in range(N):
    s = input()
    SL.append(s)


def op2(f, t):
    global A, B, C
    if f=="A":
        A -=1
    elif f=="B":
        B -=1
    elif f=="C":
        C -=1
    if t=="A":
        A +=1
    elif t=="B":
        B +=1
    elif t=="C":
        C +=1

def op(f, t):
    global A, B, C
    if f=="A":
        A -=1
    elif f=="B":
        B -=1
    elif f=="C":
        C -=1
    if t=="A":
        A +=1
    elif t=="B":
        B +=1
    elif t=="C":
        C +=1
    print(t)

def show():
    print("Yes")
    global A, B, C
    for s in SL:
        if s=="AB":
            if A > B:
                op("A", "B")
            else: op("B", "A")
        elif s=="BC":
            if B >C:
                op("B", "C")
            else: op("C", "B")
        elif s=="AC":
            if A >C:
                op("A", "C")
            else: op("C", "A")


def fight():
    print("wrong")
    global A, B, C
    pA = A
    pB = B
    pC = C
    for s in SL:
        if s=="AB":
            if A > B:
                op2("A", "B")
            else: op2("B", "A")
        elif s=="BC":
            if B >C:
                op2("B", "C")
            else: op2("C", "B")
        elif s=="AC":
            if A >C:
                op2("A", "C")
            else: op2("C", "A")
        print("fight: ", A, B, C)
        if min(A, B, C) <= -1:
            print("No")
            exit()
    else:
        A = pA
        B = pB
        C = pC
        show()



# main


if nonZero >=2:
    show()


elif nonZero == 1:
    if max(A, B, C) >= 2:
        s = SL[0]
        if A!=0:
            if s == "BC":
                print("No")
                exit()
        if B!=0:
            if s == "AC":
                print("No")
                exit()
        if C!=0:
            if s == "AB":
                print("No")
                exit()
        show()
    else:
        fight()
else:
    print("No")

Submission status: Wrong Answer

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

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

if a+b==0 or b+c==0 or a+c==0:
  print("No")
else:
  print("Yes")
  for one in lis:
    i = one[0]
    j = one[1]
    if now[i] == 0:
  	  print(i)
    else:
      print(j)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:

N, a, b, c, *S = open(0).read().split()
N, a, b, c = map(int, (N, a, b, c))


ans = []
for s in S:
    if s == 'AB':
        ans.append('B' if a > b else 'A')
        if a> b:
            a -=1
            b += 1
        else:
            a += 1
            b -= 1

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

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

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

    print(a, b, c)

print('Yes')
[print(r) for r in ans]

Submission status: Wrong Answer

Solution code:
n,a,b,c  = map(int, input().split())
Ss = [input() for i in range(n)]
ans = []
flg = True
for S in Ss:
    if S == "AB":
        if a == b == 0:
            flg = False
        if 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
        if 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
        if 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")

Submission status: Wrong Answer

Solution code:
import sys
if sys.subversion[0] == "PyPy":
    import io, atexit
    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
    
    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()

n, a, b, c = map(int, raw_input().split())
cmds = []

def print_res(cnts, res):
    rem = [a, b, c]
    p = [0, 0, 0]
    for i in xrange(3):
        p[i] = cnts[i] + res[i]
        assert p[i] % 2 == 0
        p[i] /= 2

    print 'Yes'
    for s in cmds:
        nr = {
            'AB': 0,
            'AC': 1,
            'BC': 2
        }[s]

        x, y = ord(s[0]) - ord('A'), ord(s[1]) - ord('A')

        if p[nr] > 0:
            p[nr] -= 1
            print s[0]
            rem[x] += 1
            rem[y] -= 1
        else:
            print s[1]
            rem[y] += 1
            rem[x] -= 1

    assert min(rem) >= 0


cnts = [0, 0, 0]

for i in xrange(n):
    s = raw_input()
    cmds.append(s)

    nr = {
        'AB': 0,
        'AC': 1,
        'BC': 2
    }[s]

    cnts[nr] += 1


for i in xrange(-cnts[0], cnts[0] + 1, 2):
    aa = a + i
    bb = b - i
    cc = c

    res = [i, -1, -1]

    delta = cnts[1]
    da = max(0, (delta - aa + 1) / 2)
    dc = delta - da
    res[1] = da - dc
    if da < 0 or dc < 0:
        continue
    assert da + dc == delta
    aa = aa + da - dc
    cc = cc + dc - da

    delta = cnts[2]
    db = max(0, (delta - bb + 1) / 2)
    dc = delta - db
    if db < 0 or dc < 0:
        continue
    assert db + dc == delta
    bb = bb + db - dc
    cc = cc + dc - db
    res[2] = db - dc

    if aa >= 0 and bb >= 0 and cc >= 0:
        print_res(cnts, res)
        break
else:
    print 'No'

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, a, b, c = map(int, input().split())
S = []
T = []
r = 0
for i in range(n):
    S.append(input())
for i in range(n):
    if S[i] == "AB":
        if a < b:
            a += 1
            b -= 1
            T.append("A")
        else:
            a -= 1
            b += 1
            T.append("B")
    elif S[i] == "AC":
        if a < c:
            a += 1
            c -= 1
            T.append("A")
        else:
            a -= 1
            c += 1
            T.append("C")
    else:
        if b < c:
            b += 1
            c -= 1
            T.append("B")
        else:
            b -= 1
            c += 1
            T.append("C")
    if a < 0 or b < 0 or c < 0:
        r = 1
        break;
if r == 0:
    print("Yes")
    for i in range(n):
        print(T[i])
else:
    print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

##### dict の for文 #####
# for k, v in d.items():
#     print(k, v)

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,A,B,C = inputMap()
	stat = [0,0,0]
	Q = []
	for i in range(N):
		s = inputStr()
		Q.append(s)
		if s == "AB":
			stat[0] += 1
			stat[1] += 1
		elif s == "AC":
			stat[0] += 1
			stat[2] += 1
		elif s == "BC":
			stat[1] += 1
			stat[2] += 1

	delA = False
	delB = False
	delC = False
	if stat[0] <= A:
		delA = True
	if stat[1] <= B:
		delB = True
	if stat[2] <= C:
		delC = True

	targetA = False
	targetB = False
	targetC = False
	AA = A - stat[0]
	BB = B - stat[1]
	CC = C - stat[2]
	tmp = min(AA,BB,CC)
	if AA == tmp:
		targetA = True
	if BB == tmp:
		targetB = True
	if CC == tmp:
		targetC = True

	#print(stat)
	#print("{} {} {}".format(delA,delB,delC))

	hon = "Yes"
	ans = []
	for s in Q:
		#print(i)
		#print("{} {} {}".format(A,B,C))
		if s == "AB":
			stat[0] -= 1
			stat[1] -= 1
			if delA == True:
				B += 1
				A -= 1
				ans.append("B")
			elif delB == True:
				B -= 1
				A += 1
				ans.append("A")
			elif targetA == True and B-1 >= 0:
				B -= 1
				A += 1
				ans.append("A")
			elif targetB == True and A-1 >= 0:
				B += 1
				A -= 1
				ans.append("B")
			elif A < B:
				B -= 1
				A += 1
				ans.append("A")
			else:
				B += 1
				A -= 1
				ans.append("B")
			if A < 0 or B < 0:
				hon = "No"
				break
		elif s == "AC":
			stat[0] -= 1
			stat[2] -= 1
			if delA == True:
				C += 1
				A -= 1
				ans.append("C")
			elif delC == True:
				C -= 1
				A += 1
				ans.append("A")
			elif targetA == True and C-1 >= 0:
				C -= 1
				A += 1
				ans.append("A")
			elif targetC == True and A-1 >= 0:
				C += 1
				A -= 1
				ans.append("C")
			elif A < C:
				C -= 1
				A += 1
				ans.append("A")
			else:
				C += 1
				A -= 1
				ans.append("C")
			if A < 0 or C < 0:
				hon = "No"
				break
		elif s == "BC":
			stat[1] -= 1
			stat[2] -= 1
			if delB == True:
				C += 1
				B -= 1
				ans.append("C")
			elif delC == True:
				C -= 1
				B += 1
				ans.append("B")
			elif targetB == True and C-1 >= 0:
				C -= 1
				B += 1
				ans.append("B")
			elif targetC == True and B-1 >= 0:
				C += 1
				B -= 1
				ans.append("C")
			elif B < C:
				C -= 1
				B += 1
				ans.append("B")
			else:
				C += 1
				B -= 1
				ans.append("C")
			if C < 0 or B < 0:
				hon = "No"
				break

		if stat[0] <= A:
			delA = True
		if stat[1] <= B:
			delB = True
		if stat[2] <= C:
			delC = True

	if hon == "No":
		print(hon)
	else:
		print(hon)
		for i in ans:
			print(i)


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# dfs のサンプル
def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import sys
from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

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

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

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

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

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