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:
def examA():
    S = SI()
    if S=="ARC":
        ans = "ABC"
    else:
        ans = "ARC"
    print(ans)
    return

def examB():
    N, K = LI()
    snuke = set(range(1,N+1))
    for _ in range(K):
        d = I()
        A = LI()
        for a in A:
            snuke.discard(a)
    ans = len(snuke)
    print(ans)
    return

def examC():
    N, M = LI()
    H = LI()
    good = set(range(1,N+1))
    for _ in range(M):
        a, b = LI()
        if H[a-1]>=H[b-1]:
            good.discard(b)
        if H[b-1]>=H[a-1]:
            good.discard(a)
    ans = len(good)
    print(ans)
    return

def examD():
    X = I()
    #print(1000**5-999**5)
    for a in range(-1000,1000):
        for b in range(-1000,1000):
            if a**5-b**5==X:
                print(a,b)
                return
    return

def examE():
    N = I()
    A = LI()
    B = [0]*N
    D = defaultdict(int)
    for i in range(N):
        B[i] = A[i]-i
        c = A[i]+i
        D[c] += 1
    #print(B)
    #print(D)
    ans = 0
    for b in B:
        ans += D[-b]
    print(ans)
    return

def examF():
    def Run_Length_Encoding(s):
        tmp, count, res = s[0], 1, []
        for i in range(1, len(s)):
            if tmp == s[i]:
                count += 1
            else:
                res.append((count, tmp))
                tmp = s[i]
                count = 1
        res.append((count, tmp))
        return res

    N, A, B, C = LI()
    S = [SI()for _ in range(N)]
    SS = Run_Length_Encoding(S)
    #print(SS)
    n = len(SS)
    ans = [""]*(N)
    def judge(a,b):
        if a<0 or b<0:
            return False
        return True
    def dfs(i,num,A,B,C):
        if i==n:
            if A>=0 and B>=0 and C>=0:
                print("Yes")
                for v in ans:
                    print(v)
                exit()
            return
        cnt, s = SS[i]
        if s=="AB":
            if A==0 and B==0:
                return
            for j in range(cnt//2 -1):
                if A==0:
                    ans[num] = "A"
                    num += 1
                    ans[num] = "B"
                else:
                    ans[num] = "B"
                    num += 1
                    ans[num] = "A"
            if cnt>=2:
                A += 1; B -= 1
                if judge(A, B):
                    ans[num] = "A"
                    dfs(i + 1, num + 1, A, B, C)
                A -= 2; B += 2
                if judge(A, B):
                    ans[num] = "B"
                    dfs(i + 1, num + 1, A, B, C)
                A += 1;
                B -= 2
            if cnt%2==0:
                dfs(i+1,num+1,A,B,C)
                return
            A += 1; B -= 1
            if judge(A,B):
                ans[num] = "A"
                dfs(i+1,num+1,A,B,C)
            A -= 2; B += 2
            if judge(A,B):
                ans[num] = "B"
                dfs(i+1,num+1,A,B,C)
            A += 1; B -= 2
        elif s=="BC":
            if B==0 and C==0:
                return
            for j in range(cnt//2 -1):
                if B==0:
                    ans[num] = "B"
                    num += 1
                    ans[num] = "C"
                else:
                    ans[num] = "C"
                    num += 1
                    ans[num] = "B"
            if cnt%2==0:

                dfs(i+1,num+1,A,B,C)
                return
            B += 1; C -= 1
            if judge(B,C):
                ans[num] = "B"
                dfs(i+1,num+1,A,B,C)
            B -= 2; C += 2
            if judge(B,C):
                ans[num] = "C"
                dfs(i+1,num+1,A,B,C)
            B += 1; C -= 2
        else:
            if A==0 and C==0:
                return
            for j in range(cnt//2 -1):
                if A==0:
                    ans[num] = "A"
                    num += 1
                    ans[num] = "C"
                else:
                    ans[num] = "C"
                    num += 1
                    ans[num] = "A"
            if cnt%2==0:
                dfs(i+1,num+1,A,B,C)
                return
            A += 1; C -= 1
            if judge(A, C):
                ans[num] = "A"
                dfs(i + 1,num+1,A,B,C)
            A -= 2; C += 2
            if judge(A, C):
                ans[num] = "C"
                dfs(i + 1,num+1,A,B,C)
            A += 1; C -= 2
        return
    dfs(0,0,A,B,C)
    print("No")
    return


def examF2():
    def Run_Length_Encoding(s):
        tmp, count, res = s[0], 1, []
        for i in range(1, len(s)):
            if tmp == s[i]:
                count += 1
            else:
                res.append((count, tmp))
                tmp = s[i]
                count = 1
        res.append((count, tmp))
        return res

    N, A, B, C = LI()
    S = [SI() for _ in range(N)]
    SS = Run_Length_Encoding(S)
    # print(SS)
    n = len(SS)
    ans = [""] * (N)

    def judge(a, b):
        if a < 0 or b < 0:
            return False
        return True

    def dfs(i, num, A, B, C):
        if i == n:
            if A >= 0 and B >= 0 and C >= 0:
                print("Yes")
                for v in ans:
                    print(v)
                exit()
            return
        cnt, s = SS[i]
        if s == "AB":
            if A == 0 and B == 0:
                return
            for j in range(cnt // 2):
                if A == 0:
                    ans[num] = "A"
                    num += 1
                    ans[num] = "B"
                else:
                    ans[num] = "B"
                    num += 1
                    ans[num] = "A"
            if cnt % 2 == 0:
                dfs(i + 1, num + 1, A, B, C)
                return
            A += 1;
            B -= 1
            if judge(A, B):
                ans[num] = "A"
                dfs(i + 1, num + 1, A, B, C)
            A -= 2;
            B += 2
            if judge(A, B):
                ans[num] = "B"
                dfs(i + 1, num + 1, A, B, C)
            A += 1;
            B -= 1
        elif s == "BC":
            if B == 0 and C == 0:
                return
            for j in range(cnt // 2):
                if B == 0:
                    ans[num] = "B"
                    num += 1
                    ans[num] = "C"
                else:
                    ans[num] = "C"
                    num += 1
                    ans[num] = "B"
            if cnt % 2 == 0:
                dfs(i + 1, num + 1, A, B, C)
                return
            B += 1;
            C -= 1
            if judge(B, C):
                ans[num] = "B"
                dfs(i + 1, num + 1, A, B, C)
            B -= 2;
            C += 2
            if judge(B, C):
                ans[num] = "C"
                dfs(i + 1, num + 1, A, B, C)
            B += 1;
            C -= 1
        else:
            if A == 0 and C == 0:
                return
            for j in range(cnt // 2):
                if A == 0:
                    ans[num] = "A"
                    num += 1
                    ans[num] = "C"
                else:
                    ans[num] = "C"
                    num += 1
                    ans[num] = "A"
            if cnt % 2 == 0:
                dfs(i + 1, num + 1, A, B, C)
                return
            A += 1;
            C -= 1
            if judge(A, C):
                ans[num] = "A"
                dfs(i + 1, num + 1, A, B, C)
            A -= 2;
            C += 2
            if judge(A, C):
                ans[num] = "C"
                dfs(i + 1, num + 1, A, B, C)
            A += 1;
            C -= 1
        return

    dfs(0, 0, A, B, C)
    print("No")
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    print("No")
    #examF2()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Wrong Answer

Solution code:

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


def score(start, queries):
    def rec(nums, d):
        if d >= len(queries):
            return min(nums)
        i,j = queries[d]
        nums[i] += 1
        nums[j] -= 1
        x = rec(nums, d+1)
        nums[i] -= 2
        nums[j] += 2
        y = rec(nums, d+1)
        nums[i] += 1
        nums[j] -= 1
        return max(x,y)
    return rec(start, 0)



Q = []
for _ in range(N):
    s = input()
    if s == 'AB':
        i,j = 0,1
    elif s == 'BC':
        i,j = 1,2
    else:
        i,j = 2,0

    Q.append((i,j))

nums = [A,B,C]
res = []
flag = True
for q,(i,j) in enumerate(Q):
    queries = Q[q:min(q+3, len(Q))]
    nums[i] += 1
    nums[j] -= 1
    x = score(nums, queries)
    nums[i] -= 2
    nums[j] += 2
    y = score(nums, queries)
    nums[i] += 1
    nums[j] -= 1
    if x > y:
        res.append(i)
        nums[i] += 1
        nums[j] -= 1
    else:
        res.append(j)
        nums[i] -= 1
        nums[j] += 1
    if max(x,y) < 0:
        flag = False
        break


if not flag:
    print('No')
else:
    print('Yes')
    res = tuple(str(chr(v+ord('A'))) for v in res)
    print(*res,sep='\n')

Submission status: Wrong Answer

Solution code:
#F
N,A,B,C = map(int,input().split())
S = [list(str(input())) for i in range(N)]
Ac = [0]*N
Bc = [0]*N
Cc = [0]*N

for i,s in enumerate(S):
    x,y = s
    if x == "A" or y == "A":
        Ac[i]+=1
    if x == "B" or y == "B":
        Bc[i]+=1
    if x == "C" or y == "C":
        Cc[i]+=1
        
Ac = Ac[::-1]
Bc = Bc[::-1]
Cc = Cc[::-1]
    
flag = True
ans = []
for i,s in enumerate(S):
    if s == "AB":
        if A == 0 and B == 0:
            flag = False
            break
        elif A == 0:
            A+=1
            B-=1
            ans.append("A")
        elif B == 0:
            A-=1
            B+=1
            ans.append("B")
        else:
            if A-Ac[i] >= B-Bc[i]:
                A-=1
                B+=1
                ans.append("B")
            else:
                A+=1
                B-=1
                ans.append("A")
    if s == "AC":
        if A == 0 and C == 0:
            flag = False
            break
        elif A == 0:
            A+=1
            C-=1
            ans.append("A")
        elif C == 0:
            A-=1
            C+=1
            ans.append("C")
        else:
            if A-Ac[i] >= C-Cc[i]:
                A-=1
                C+=1
                ans.append("C")
            else:
                A+=1
                C-=1
                ans.append("A")
    if s == "BC":
        if C == 0 and B == 0:
            flag = False
            break
        elif C == 0:
            C+=1
            B-=1
            ans.append("C")
        elif B == 0:
            C-=1
            B+=1
            ans.append("B")
        else:
            if C-Cc[i] >= B-Bc[i]:
                C-=1
                B+=1
                ans.append("B")
            else:
                C+=1
                B-=1
                ans.append("C")
                
if flag:
    print("Yes")
    for a in ans:
        print(a)
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,raw_input().split())
d=[]
flag=1
for i in range(n):
    s=raw_input()
    if s=='AB':
        if a<=b:
            a+=1
            b-=1
            d+=['A']
        
        else:
            a-=1
            b+=1
            d+=['B']
    
    
    elif s=='AC':
        if a<=c:
            a+=1
            c-=1
            d+=['A']
        
        else:
            a-=1
            c+=1
            d+=['C']
    
    else:
    
        if c<=b:
            c+=1
            b-=1
            d+=['C']
        
        else:
            c-=1
            b+=1
            d+=['B']
    
    if a<0 or b<0 or c<0:
        flag=0
        break

if flag==1:
    print "Yes"
    for i in range(len(d)):
        print d[i]

else:
    print "No"

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int, input().split())
d = {}
d["A"] = a
d["B"] = b
d["C"] = c
res = []
for _ in range(n):
    p = input()
    if d[p[0]]>d[p[1]]:
        if d[p[0]]<=0:
            print("No")
            exit()
        res.append(p[1])
        d[p[0]] -= 1
        d[p[1]] += 1
    else:
        if d[p[1]]<=0:
            print("No")
            exit()
        res.append(p[0])
        d[p[0]] += 1
        d[p[1]] -= 1

print("Yes")
for p in res:
    print(p)

Submission status: Wrong Answer

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

box = []
for line in select:
    if line == 'AB':
        if B > A:
            A += 1
            B -= 1
            box.append('A')
        else:
            A -= 1
            B += 1
            box.append('B')
    if line == 'BC':
        if C > B:
            B += 1
            C -= 1
            box.append('B')
        else:
            B -= 1
            C += 1
            box.append('C')
    if line == 'AC':
        if C > A:
            A += 1
            C -= 1
            box.append('A')
        else:
            A -= 1
            C += 1
            box.append('C')
    if A < 0 or B < 0 or C < 0:
        print('No')
        exit()

print('Yes')
for line in box:
    print(line)

Submission status: Wrong Answer

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

def output(a_ab, b_ab, a_ac, c_ac, b_bc, c_bc):
    for round in rounds:
        if round == "AB":
            if a_ab > 0:
                print("A")
                a_ab -= 1
            else:
                print("B")

        if round == "AC":
            if a_ac > 0:
                print("A")
                a_ac -= 1
            else:
                print("C")

        if round == "BC":
            if b_bc > 0:
                print("B")
                b_bc -= 1
            else:
                print("C")
                

ab = rounds.count("AB")
bc = rounds.count("BC")
ac = rounds.count("AC")

for a_ab in range(ab + 1):
    b_ab = ab - a_ab
    a_rest = a + a_ab - b_ab
    b_rest = b + b_ab - a_ab

    a_ac = max(0, (ac - a_rest + 1)//2)
    c_ac = ac - a_ac
    
    b_bc = max(0, (bc - b_rest + 1)//2)
    c_bc = bc - b_bc
    if a_ab < 0 or b_ab < 0 or a_ac < 0 or c_ac < 0 or b_bc < 0 or c_bc < 0:
        continue
    if a + a_ab - b_ab + a_ac - c_ac >= 0 and b + b_ab - a_ab + b_bc - c_bc >= 0 and c + c_bc - b_bc + c_ac - a_ac >= 0:
        print("Yes")
        output(a_ab, b_ab, a_ac, c_ac, b_bc, c_bc)
        exit()

print("No")

Submission status: Wrong Answer

Solution code:
n, a, b, c = map(int,input().split())
s = [input() for i in range(n)]
dic = {'A':a, 'B':b, 'C':c}
l = []
for i in s:
    temp1 = i[0]
    temp2 = i[1]
    if dic[temp1] + dic[temp2] == 0:
        print('No')
        exit()
    if dic[temp1] < dic[temp2]:
        dic[temp1] += 1
        dic[temp2] -= 1
        l.append(temp1)
    else:
        dic[temp2] += 1
        dic[temp1] -= 1
        l.append(temp2)
print('Yes')
print(*l, sep = '\n')

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int,input().split())
Y = []
f = True
for i in range(n):
    s = input()
    if s == "AB":
        if a>=b:
            a -= 1
            b += 1
            Y.append("B")
        else:
            a += 1
            b -= 1
            Y.append("A")
    elif s == "AC":
        if a>=c:
            a -= 1
            c += 1
            Y.append("C")
        else:
            a += 1
            c -= 1
            Y.append("A")
    else:
        if c>=b:
            c -= 1
            b += 1
            Y.append("B")
        else:
            c += 1
            b -= 1
            Y.append("C")
    # print(a,b,c)
    if a<0 or b<0 or c<0:
        f = False
        print("No")
        break
        
if f:
    print("Yes")
    for y in Y:
        print(y)

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int,input().split())
s = [input() for i in range(n)]+[0]
# if [a,b,c].count(0) >= 2:
#     print("No")
ans = ""

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

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

# 合計は同じ、0,0の場所が選ばれたら終わり
N, A, B, C = lr()
answer = []
for _ in range(N):
    S = sr()
    if S == 'AB':
        if A <= B:
            if B == 0:
                print('No'); exit()
            answer.append('A')
            A += 1; B -= 1
        else:
            answer.append('B')
            B += 1; A -= 1
    elif S == 'BC':
        if B <= C:
            if C == 0:
                print('No'); exit()
            answer.append(B)
            B += 1; C -= 1
        else:
            answer.append('C')
            C += 1; B -= 1
    elif S == 'AC':
        if A <= C:
            if C == 0:
                print('No'); exit()
            answer.append('A')
            A += 1; C -= 1
        else:
            answer.append('C')
            C += 1; A -= 1

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

Submission status: Wrong Answer

Solution code:
s = [0,0,0]
n,s[0],s[1],s[2] = map(int,input().split())
T = [0]*n
ABC = 'ABC'
for i in range(n):
    t = input()
    if t == 'AB':T[i] = 2
    if t == 'BC':T[i] = 0
    if t == 'AC':T[i] = 1
ans = ['' for _ in range(n)]
if s.count(0) <= 1 and sum(s) >= 3:
    for i,t in enumerate(T):
        nxt = [0,1,2]
        nxt.remove(t)
        if s[nxt[0]] < s[nxt[1]]:
            ans[i] = ABC[nxt[0]]
            s[nxt[0]] += 1
            s[nxt[1]] -= 1
        else:
            ans[i] = ABC[nxt[1]]
            s[nxt[0]] -= 1
            s[nxt[1]] += 1
    print('Yes')
    print('\n'.join(ans))
elif s.count(0) == 1:
    now = s.index(0)
    i = 0
    while i < n-1:
        if T[i] == T[i+1]:
            if T[i] == now:
                ans[i] = ABC[(now-1)%3]
                ans[i+1] = ABC[(now-2)%3]
            else:
                for j in range(3):
                    if j not in [T[i],now]:
                        ans[i+1] = ABC[j]
                ans[i] = ABC[now]
            i += 2
        elif T[i] == now:
            for j in range(3):
                if j not in [T[i+1],now]:ans[i] = ABC[j]
            ans[i+1] = ABC[T[i]]
            now = T[i+1]
            i += 2
        else:
            ans[i] = ABC[now]
            for j in range(3):
                if j not in [T[i],now]:
                    now = j
                    break
            i += 1
    if i == n-1:
        if T[i] == now:
            for j in range(3):
                if j not in [now,T[i]]:ans[i] = ABC[j]
        else:
            ans[i] = ABC[now]
    print('Yes')
    print('\n'.join(ans))
else:
    for i,t in enumerate(T):
        nxt = [0,1,2]
        nxt.remove(t)
        if s[nxt[0]] < s[nxt[1]]:
            ans[i] = ABC[nxt[0]]
            s[nxt[0]] += 1
            s[nxt[1]] -= 1
        else:
            ans[i] = ABC[nxt[1]]
            s[nxt[0]] -= 1
            s[nxt[1]] += 1
        if -1 in s:
            print('No')
            break
    else:
        print('Yes')
        print('\n'.join(ans))