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:
from collections import deque
n, a, b, c = map(int, input().split())
s = [input() for _ in range(n)]
ans = []
if (a==0 and  b==0 and c==1) or (a==0 and  b==1 and c==0) or (a==1 and  b==0 and c==0):
    for i in range(n):
        if s[i] == "AB":
            if a >= 1:
                a -= 1
                b += 1
                ans.append("B")
            elif b >= 1:
                a += 1
                b -= 1
                ans.append("A")
            else:
                print("No")
                exit()
        elif s[i] == "AC":
            if a >= 1:
                a -= 1
                c += 1
                ans.append("C")
            elif c >= 1:
                a += 1
                c -= 1
                ans.append("A")
            else:
                print("No")
                exit()
        else:
            if b >= 1:
                b -= 1
                c += 1
                ans.append("C")
            elif c >= 1:
                b += 1
                c -= 1
                ans.append("B")
            else:
                print("No")
                exit()
    print("Yes")
    for i in ans:
        print(i)
    exit()

if (a==0 and  b==1 and c==1) or (a==1 and  b==0 and c==1) or (a==1 and  b==1 and c==0):
    que = deque([[a, b, c, []]])
    for i in range(n):
        if not que:
            print("No")
            exit()
        len_que = len(que)
        for _ in range(len_que):
            a, b, c, ans = que.popleft()
            if s[i] == "AB":
                if a>=1 and b==0:
                    a -= 1
                    b += 1
                    ans.append("B")
                elif b>=1 and a==0:
                    a += 1
                    b -= 1
                    ans.append("A")
                elif a==0 and b==0: continue
                else:
                    ans1 = ans.append("A")
                    ans2 = ans.append("B")
                    que.append([a+1, b-1, c, ans1])
                    que.append([a-1, b+1, c, ans2])
                    continue
            elif s[i] == "AC":
                if a>=1 and c==0:
                    a -= 1
                    c += 1
                    ans.append("C")
                elif c>=1and a==0:
                    a += 1
                    c -= 1
                    ans.append("A")
                elif a==0 and c==0: continue
                else:
                    ans1 = ans.append("A")
                    ans2 = ans.append("C")
                    que.append([a+1, b, c-1, ans1])
                    que.append([a-1, b, c+1, ans2])
                    continue
            else:
                if b >= 1 and c==0:
                    b -= 1
                    c += 1
                    ans.append("C")
                elif c >= 1and b==0:
                    b += 1
                    c -= 1
                    ans.append("B")
                elif b==0 and c==0: continue  
                else:
                    ans1 = ans.append("B")
                    ans2 = ans.append("C")
                    que.append([a, b+1, c-1, ans1])
                    que.append([a, b-1, c+1, ans2])
                    continue
            que.append([a, b, c, ans])
    a, b, c, ans = que.popleft()
    for i in ans:
        print(i)
        exit()

if a==0 and  b==0:
    if s[0] == "AB":
        print("No")
        exit()
elif a==0 and  c==0:
    if s[0] == "AC":
        print("No")
        exit()
elif b==0 and  c==0:
    if s[0] == "BC":
        print("No")
        exit()

print("Yes")
for i in range(n):
    if s[i] == "AB":
        if a >= b:
            a -= 1
            b += 1
            print("B")
        else:
            a += 1
            b -= 1
            print("A")
    elif s[i] == "AC":
        if a >= c:
            a -= 1
            c += 1
            print("C")
        else:
            a += 1
            c -= 1
            print("A")
    else:
        if b >= c:
            b -= 1
            c += 1
            print("C")
        else:
            b += 1
            c -= 1
            print("B")

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(N: int, A: int, B: int, C: int, s: "List[str]"):
    ABC = [A, B, C]
    ans = []
    d = {"AB": (0, 1), "BC": (1, 2), "AC": (0, 2)}
    for i in range(N):
        j, k = d[s[i]]
        if ABC[j] == ABC[k] == 0:
            no()
            return
        if ABC[j] == ABC[k] == 1:
            if i != N-1:
                if j not in s[i+1]:
                    j, k = k, j
            ABC[j] += 1
            ABC[k] -= 1
            ans.append("ABC"[j])
        if ABC[j] > ABC[k]:
            ABC[j] -= 1
            ABC[k] += 1
            ans.append("ABC"[k])
        else:
            ABC[j] += 1
            ABC[k] -= 1
            ans.append("ABC"[j])
    yes()
    for a in ans:
        print(a)
    return


def main():

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
n, a,b,c = map(int, input().split())

s = []
for _ in range(n):
    si = sys.stdin.readline().rstrip()
    if si == 'AB':
        s.append(0)
    elif si == 'BC':
        s.append(1)
    else:
        s.append(2)

ddic = [[0,1,2], [1,2,0], [2,0,1]]
ldic = ['A', 'B', 'C']

if a == 0 and b == 0 and c == 0:
    print('No')
    exit()
elif a +b+c == 1:
    log = []
    tani = [a, b, c]
    for x in s:
        i1 = ddic[x][0]
        i2 = ddic[x][1]
        if tani[i1] ==1:
            log.append(ldic[i2])
            tani[i1] -=1
            tani[i2] +=1
        elif tani[i2] == 1:
            log.append(ldic[i1])
            tani[i2] -=1
            tani[i1] +=1
        else:
            print('No')
            exit()
    print('Yes')
    for y in log:
        print(y)
    exit()
elif a >0 and b>0 and c>0:
    print('Yes')
    tani = [1, 1, 1]
    for x in s:
        i1 = ddic[x][0]
        i2 = ddic[x][1]
        if tani[i1]==0 or tani[i2] ==2:
            print(ldic[i1])
            tani[i1]+=1
            tani[i2]-=1
        else:
            print(ldic[i2])
            tani[i2]+=1
            tani[i1]-=1
    exit()
else:
    log = []
    count = 0
    tani = [a, b, c]
    for dis in ddic:
        i1 = dis[0]
        i2 = dis[1]
        if tani[i1] == 0 and tani[i2] == 0:
            x = s[0]
            if ddic[x][0] == i1 and ddic[x][1] == i2:
                print('No')
                exit()
            if tani[ddic[x][0]] > 0:
                log.append(ldic[ddic[x][1]])
                tani[ddic[x][0]] -=1
                tani[ddic[x][1]] +=1
            else:
                log.append(ldic[ddic[x][0]])
                tani[ddic[x][1]] -=1
                tani[ddic[x][0]] +=1
            count+=1
            break
    while True:
        i1 = ddic[s[count]][0]
        i2 = ddic[s[count]][1]
        i3 = ddic[s[count]][2]
        if tani[i3] == 0 and tani[i1] == 1 and tani[i2] == 1 and count < len(s)-1:
            if s[count+1] == s[count]:
                log.append(ldic[i1])
                log.append(ldic[i2])
                count+=1
            else:
                if ddic[s[count+1]][0] ==i1 or ddic[s[count+1]][1] ==i1:
                    log.append(ldic[i1])
                    tani[i1] +=1
                    tani[i2] -=1
                else:
                    log.append(ldic[i2])
                    tani[i2] +=1
                    tani[i1] -=1
        else:
            if tani[i1] > tani[i2]:
                log.append(ldic[i2])
                tani[i1] -=1
                tani[i2] +=1
            else:
                log.append(ldic[i1])
                tani[i2] -=1
                tani[i1] +=1
        count+=1
        if count >= len(s):
            break
    print('Yes')
    for y in log:
        print(y)
    exit()

Submission status: Runtime Error

Solution code:
n,a,b,c = (int(num) for num in input().split())

s = a + b + c
ans = "Yes"
if s == 0:
    ans = "No"
elif s == 1:
    if a == 0:
        z = "BC"
    elif b == 0:
        z = "AC"
    else:
        z = "AB"
    q = ""
    for _ in range(n):
        s = input()
        if s == z:
            ans = "No"
            break
        elif z == "AB":
            q = q + "C"
            if s == "BC":
                z = "AC"
            else:
                z = "BC"
        elif z == "AC":
            q = q + "B"
            if s == "AB":
                z = "BC"
            else:
                z = "AB"
        else:
            q = q + "A"
            if s == "AB":
                z = "AC"
            else:
                z = "AB"
elif s == 2:
    inp = [""] * n
    for i in range(n):
        inp[i] = input()
    idx = 0
    q = ""
    while idx < n:
        if (a,b) == (2,0) or (a,b) == (0,2) or (a,b) == (0,0):
            if inp[idx] == "AB":
                if a > b:
                    a -= 1
                    b += 1
                    q = q + "B"
                else:
                    a += 1
                    b -= 1
                    q = q + "A"
            elif inp[idx] == "AC":
                if a > c:
                    a -= 1
                    c += 1
                    q = q + "C"
                else:
                    a += 1
                    c -= 1
                    q = q + "A"
            else:
                if b > c:
                    b -= 1
                    c += 1
                    q = q + "C"
                else:
                    b += 1
                    c -= 1
                    q = q + "B"
            if a < 0 or b < 0 or c < 0:
                ans = "No"
                break
            idx += 1
        else:
            q = q + inp[idx+1]
            if inp[idx] == inp[idx + 1]:
                pass
            else:
                if inp[idx+1] == "AB":
                    a,b,c = 1,1,0
                elif inp[idx+1] == "AC":
                    a,b,c = 1,0,1
                else:
                    a,b,c = 0,1,1
            idx += 2
    if len(q) > n:
        q = q[:n]
        
else:
    q = ""
    for _ in range(n):
        s = input()
        if s == "AB":
            if a > b:
                a -= 1
                b += 1
                q = q + "B"
            else:
                a += 1
                b -= 1
                q = q + "A"
        elif s == "AC":
            if a > c:
                a -= 1
                c += 1
                q = q + "C"
            else:
                a += 1
                c -= 1
                q = q + "A"
        else:
            if b > c:
                b -= 1
                c += 1
                q = q + "C"
            else:
                b += 1
                c -= 1
                q = q + "B"
        if a < 0 or b < 0 or c < 0:
            ans = "No"
            break 
            
print(ans)
if ans == "Yes":
    for i in range(n):
        print(q[i])

Submission status: Runtime Error

Solution code:
from collections import deque
n, a, b, c = map(int, input().split())
s = [input() for _ in range(n)]
ans = []
if (a==0 and  b==0 and c==1) or (a==0 and  b==1 and c==0) or (a==1 and  b==0 and c==0):
    for i in range(n):
        if s[i] == "AB":
            if a >= 1:
                a -= 1
                b += 1
                ans.append("B")
            elif b >= 1:
                a += 1
                b -= 1
                ans.append("A")
            else:
                print("No")
                exit()
        elif s[i] == "AC":
            if a >= 1:
                a -= 1
                c += 1
                ans.append("C")
            elif c >= 1:
                a += 1
                c -= 1
                ans.append("A")
            else:
                print("No")
                exit()
        else:
            if b >= 1:
                b -= 1
                c += 1
                ans.append("C")
            elif c >= 1:
                b += 1
                c -= 1
                ans.append("B")
            else:
                print("No")
                exit()
    print("Yes")
    for i in ans:
        print(i)
    exit()

if (a==0 and  b==1 and c==1) or (a==1 and  b==0 and c==1) or (a==1 and  b==1 and c==0):
    que = deque([[a, b, c, []]])
    for i in range(n):
        if not que:
            print("No")
            exit()
        len_que = len(que)
        for _ in range(len_que):
            a, b, c, ans = que.popleft()
            if s[i] == "AB":
                if a>=1 and b==0:
                    a -= 1
                    b += 1
                    ans.append("B")
                elif b>=1 and a==0:
                    a += 1
                    b -= 1
                    ans.append("A")
                elif a==0 and b==0: continue
                else:
                    ans1 = ans.append("A")
                    ans2 = ans.append("B")
                    que.append([a+1, b-1, c, ans1])
                    que.append([a-1, b+1, c, ans2])
                    continue
            elif s[i] == "AC":
                if a>=1 and c==0:
                    a -= 1
                    c += 1
                    ans.append("C")
                elif c>=1and a==0:
                    a += 1
                    c -= 1
                    ans.append("A")
                elif a==0 and c==0: continue
                else:
                    ans1 = ans.append("A")
                    ans2 = ans.append("C")
                    que.append([a+1, b, c-1, ans1])
                    que.append([a-1, b, c+1, ans2])
                    continue
            else:
                if b >= 1 and c==0:
                    b -= 1
                    c += 1
                    ans.append("C")
                elif c >= 1and b==0:
                    b += 1
                    c -= 1
                    ans.append("B")
                elif b==0 and c==0: continue  
                else:
                    ans1 = ans.append("B")
                    ans2 = ans.append("C")
                    que.append([a, b+1, c-1, ans1])
                    que.append([a, b-1, c+1, ans2])
                    continue
            que.append([a, b, c, ans])
    a, b, c, ans = que.popleft()
    for i in ans:
        print(i)

if a==0 and  b==0:
    if s[0] == "AB":
        print("No")
        exit()
elif a==0 and  c==0:
    if s[0] == "AC":
        print("No")
        exit()
elif b==0 and  c==0:
    if s[0] == "BC":
        print("No")
        exit()

print("Yes")
for i in range(n):
    if s[i] == "AB":
        if a >= b:
            a -= 1
            b += 1
            print("B")
        else:
            a += 1
            b -= 1
            print("A")
    elif s[i] == "AC":
        if a >= c:
            a -= 1
            c += 1
            print("C")
        else:
            a += 1
            c -= 1
            print("A")
    else:
        if b >= c:
            b -= 1
            c += 1
            print("C")
        else:
            b += 1
            c -= 1
            print("B")

Submission status: Runtime Error

Solution code:
def solve(data,siji):
    global henkan
    ans=[]
    for s in siji:
        hiku,tasu=henkan[s]
        if(data[hiku]<data[tasu]):
            temp=hiku
            hiku=tasu
            tasu=temp
        #print(hiku,tasu,data)
        data[hiku]-=1
        data[tasu]+=1
        ans.append(tasu)
        if(data[hiku]<0):
            return [False,[]]
    return [True,ans]

n,a,b,c=map(int,input().split())
siji=[]
henkan=[(0,1),(0,2),(1,2)]
for i in range(n):
    s=input()
    if(s=="AB"):
        siji.append(0)
    elif(s=="AC"):
        siji.append(1)
    else:
        siji.append(2)



data=[a,b,c]
zeros=0
gokei=sum(data)
for i in range(3):
    if(data[i]==0):
        zeros+=1

if(zeros==3):
    koate=solve([0,0,0],siji)
elif(zeros==0):
    kotae=solve([1,1,1],siji)
    #print(kotae)
elif(gokei>=3):
    kotae=solve(data,siji)
elif(gokei==1):
    kotae=solve(data,siji)
elif(gokei==2):
    koate=solve(data,siji)
else:
    kotae=[True,[1,2,0]]




if(not kotae[0]):
    print("No")
else:
    print("Yes")
    alpha=["A","B","C"]
    for k  in kotae[1]:
        print(alpha[k])

Submission status: Runtime Error

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

res = ['0']*N

# 明らかに可能
if a+b+c >= 6:
    print('Yes')
    for i in range(N):
        if S[i]=='AC':
            if a<c:
                res[i] = 'A'
                a += 1
                c -= 1
            else:
                res[i] = 'C'
                c += 1
                a -= 1
        elif S[i]=='AB':
            if a<b:
                res[i] = 'A'
                a += 1
                b -= 1
            else:
                res[i] = 'B'
                b += 1
                a -= 1
        else:
            if b<c:
                res[i] = 'B'
                b += 1
                c -= 1
            else:
                res[i] = 'C'
                c += 1
                b -= 1
    for val in res:
        print(val)
elif a+b+c==0:
    print('No')
elif a+b+c==1:
    now = 'a'
    if b==1:
        now = 'b'
    elif c==1:
        now = 'c'
    for i in range(N):
        if S[i] == 'AC':
            if now=='b':
                print('No')
                exit()
            elif now=='a':
                res[i] = 'C'
                now = 'c'
            else:
                res[i] = 'A'
                now = 'a'
        if S[i] == 'BC':
            if now=='a':
                print('No')
                exit()
            elif now=='b':
                res[i] = 'C'
                now = 'c'
            else:
                res[i] = 'B'
                now = 'b'
        if S[i] == 'AB':
            if now=='c':
                print('No')
                exit()
            elif now=='a':
                res[i] = 'B'
                now = 'b'
            else:
                res[i] = 'A'
                now = 'a'
    print('Yes')
    for val in res:
        print(val)
elif a+b+c==2:
    assert()
    available = [(a,b,c)]
    next_available = []
    for s in S:
        for aa,bb,cc in available:
            if s=='AC':
                if aa==2:
                    next_available.append((1,0,1))
                elif aa==1 and cc==1:
                    next_available.append((2,0,0))
                    next_available.append((0,0,2))
                elif aa==1:
                    next_available.append((0,1,1))
                else:
                    next_available.append((1,0,1))
                    
            if s=='AB':
                if aa==2:
                    next_available.append((1,1,0))
                elif aa==1 and bb==1:
                    next_available.append((2,0,0))
                    next_available.append((0,2,0))
                elif aa==1:
                    next_available.append((0,1,1))
                else:
                    next_available.append((1,1,0))
                    
            if s=='BC':
                if bb==2:
                    next_available.append((0,1,1))
                elif bb==1 and cc==1:
                    next_available.append((0,2,0))
                    next_available.append((0,0,2))
                elif bb==1:
                    next_available.append((1,0,1))
                else:
                    next_available.append((0,1,1))
            if next_available==[]:
                print('No')
                exit()
else:
    assert()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(N: int, A: int, B: int, C: int, s: "List[str]"):
    ABC = [A, B, C]
    ans = []
    d = {"AB": (0, 1), "BC": (1, 2), "AC": (0, 2)}
    for i in range(N):
        j, k = d[s[i]]
        if ABC[j] == ABC[k] == 0:
            no()
            return
        if ABC[j] == ABC[k] == 1:
            if i < N-1:
                if s[i] == s[i+1]:
                    ABC[j] += 1
                    ABC[k] -= 1
                    ans.append(j)
                else:
                    if j in s[i+1]:
                        ABC[j] += 1
                        ABC[k] -= 1
                        ans.append(j)
                    else:
                        j, k = k, j
                        ABC[j] += 1
                        ABC[k] -= 1
                        ans.append(j)
            else:
                a.append("ABC"[j])
        if ABC[j] > ABC[k]:
            ABC[j] -= 1
            ABC[k] += 1
            ans.append("ABC"[k])
        else:
            ABC[j] += 1
            ABC[k] -= 1
            ans.append("ABC"[j])
    yes()
    for a in ans:
        print(a)
    return


def main():

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n, a, b, c = LI()
    s = SR(n)
    ans = [None] * n
    dp = [deque() for i in range(3)]
    l = [[0] * 3 for i in range(n)]
    d = {"A": 0, "B": 1, "C": 2}
    for i in range(n):
        l[i][d[s[i][0]]] = 1
        l[i][d[s[i][1]]] = 1
    for i in range(n - 1, 0, -1):
        l[i - 1][0] += l[i][0]
        l[i - 1][1] += l[i][1]
        l[i - 1][2] += l[i][2]
    dd = [0] * 3
    ddd = defaultdict(int)
    for i in range(n):
        if s[i] == "AB":
            if a < b:
                ans[i] = "A"
                a += 1
                b -= 1
            elif a > b:
                ans[i] = "B"
                a -= 1
                b += 1
            else:
                if a == 0:
                    if len(dp[0]) - dd[0] == 0 and len(dp[1]) - dd[1] == 0:
                        print("No")
                        return
                    if len(dp[0]) - dd[0] > len(dp[1]) - dd[1]:
                        x = dp[0].popleft()
                        while ddd[x]:
                            x = dp[0].popleft()
                        ddd[x] = 1
                        ans[x] = "A"
                        ans[i] = "B"
                    elif len(dp[0]) - dd[0] < len(dp[1]) - dd[1]:
                        x = dp[1].popleft()
                        while ddd[x]:
                            x = dp[1].popleft()
                        ddd[x] = 1
                        ans[x] = "B"
                        ans[i] = "A"
                    else:
                        if l[i][0] < l[i][1]:
                            x = dp[0].popleft()
                            while ddd[x]:
                                x = dp[0].popleft()
                            ddd[x] = 1
                            ans[x] = "A"
                            ans[i] = "B"
                        else:
                            x = dp[1].popleft()
                            while ddd[x]:
                                x = dp[1].popleft()
                            ddd[x] = 1
                            ans[x] = "B"
                            ans[i] = "A"
                else:
                    dp[0].append(i)
                    dp[1].append(i)
                    a -= 1
                    b -= 1
        elif s[i] == "AC":
            if a < c:
                ans[i] = "A"
                a += 1
                c -= 1
            elif a > c:
                ans[i] = "C"
                a -= 1
                c += 1
            else:
                if a == 0:
                    if len(dp[0]) - dd[0] == 0 and len(dp[2]) - dd[2] == 0:
                        print("No")
                        return
                    if len(dp[0]) - dd[0] > len(dp[2]) - dd[2]:
                        x = dp[0].popleft()
                        while ddd[x]:
                            x = dp[0].popleft()
                        ddd[x] = 1
                        ans[x] = "A"
                        ans[i] = "C"
                    elif len(dp[0]) - dd[0] < len(dp[2]) - dd[2]:
                        x = dp[2].popleft()
                        while ddd[x]:
                            x = dp[2].popleft()
                        ddd[x] = 1
                        ans[x] = "C"
                        ans[i] = "A"
                    else:
                        if l[i][0] < l[i][2]:
                            x = dp[0].popleft()
                            while ddd[x]:
                                x = dp[0].popleft()
                            ddd[x] = 1
                            ans[x] = "A"
                            ans[i] = "C"
                        else:
                            x = dp[2].popleft()
                            while ddd[x]:
                                x = dp[2].popleft()
                            ddd[x] = 1
                            ans[x] = "C"
                            ans[i] = "A"
                else:
                    dp[0].append(i)
                    dp[2].append(i)
                    a -= 1
                    c -= 1
        else:
            if b < c:
                ans[i] = "B"
                b += 1
                c -= 1
            elif a > c:
                ans[i] = "C"
                b -= 1
                c += 1
            else:
                if b == 0:
                    if len(dp[1]) - dd[1] == 0 and len(dp[2]) - dd[2] == 0:
                        print("No")
                        return
                    if len(dp[1]) - dd[1] > len(dp[2]) - dd[2]:
                        x = dp[1].popleft()
                        while ddd[x]:
                            x = dp[1].popleft()
                        ddd[x] = 1
                        ans[x] = "B"
                        ans[i] = "C"
                    elif len(dp[1]) - dd[1] < len(dp[2]) - dd[2]:
                        x = dp[2].popleft()
                        while ddd[x]:
                            x = dp[2].popleft()
                        ddd[x] = 1
                        ans[x] = "C"
                        ans[i] = "B"
                    else:
                        if l[i][1] < l[i][2]:
                            x = dp[1].popleft()
                            while ddd[x]:
                                x = dp[1].popleft()
                            ddd[x] = 1
                            ans[x] = "B"
                            ans[i] = "C"
                        else:
                            x = dp[2].popleft()
                            while ddd[x]:
                                x = dp[2].popleft()
                            ddd[x] = 1
                            ans[x] = "C"
                            ans[i] = "B"
                else:
                    dp[1].append(i)
                    dp[2].append(i)
                    b -= 1
                    c -= 1
    ll = ["A", "B", "C"]
    print("Yes")
    for i in range(3):
        while dp[i]:
            p = dp[i].pop()
            if ans[p] == None:
                ans[p] = ll[i]
    for i in ans:
        print(i)
    return


#main
if __name__ == '__main__':
    solve()