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 read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def _solve(A, B, C, S):
    counter = {'A': A, 'B': B, 'C': C}
    last = S[0]
    answer = []
    for s in S:
        choices = set(s)-set(last)
        if len(choices) == 0:
            if counter[s[0]] > 0:
                counter[s[0]] -= 1
                counter[s[1]] += 1
                answer.append(s[1])
            elif counter[s[1]] > 0:
                counter[s[0]] += 1
                counter[s[1]] -= 1
                answer.append(s[0])
            else:
                return None
        else:
            dest = choices.pop()
            if s[0] == dest:
                src = s[1]
            else:
                src = s[0]
            if counter[src] == 0:
                return None
            counter[src] -= 1
            counter[dest] += 1
            answer.append(dest)
        last = s
    return answer



def solve():
    N, A, B, C = read_ints()
    S = []
    for _ in range(N):
        S.append(input().strip())
    answer = _solve(A, B, C, S)
    if answer is None:
        S[0] = S[0][1]+S[0][0]
        answer = _solve(A, B, C, S)
        if answer is None:
            print('No')
            return
    print('Yes')
    for a in answer:
        print(a)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def _solve(A, B, C, S):
    counter = {'A': A, 'B': B, 'C': C}
    last = S[0][0]
    answer = []
    for s in S:
        if s[0] == last:
            counter[s[0]] -= 1
            counter[s[1]] += 1
            if counter[s[0]] < 0:
                return None
            answer.append(s[1])
        else:
            counter[s[1]] -= 1
            counter[s[0]] += 1
            if counter[s[1]] < 0:
                return None
            answer.append(s[0])
        last = s[1]
    return answer



def solve():
    N, A, B, C = read_ints()
    S = []
    for _ in range(N):
        S.append(input().strip())
    answer = _solve(A, B, C, S)
    if answer is None:
        S[0] = S[0][1]+S[0][0]
        answer = _solve(A, B, C, S)
        if answer is None:
            print('No')
            return
    for a in answer:
        print(a)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:

def NextEnforcement(enfo1,enfo2):
    if(enfo1 == "AB") and (enfo2 == "AC"):
        return "1"
    elif (enfo1 == "AB") and (enfo2 == "BC"):
        return "2"
    elif (enfo1 == "BC") and (enfo2 == "AC"):
        return "2"
    elif (enfo1 == "BC") and (enfo2 == "AB"):
        return "1"
    elif (enfo1 == "AC") and (enfo2 == "AB"):
        return "1"
    elif (enfo1 == "AC") and (enfo2 == "BC"):
        return "2"
    else:
        return "0"


def Calculation(num1,num2,nextInfo):
    if num1 == num2 == 0:
        print("No")
        exit()
    elif num1 == 0:
        num1 += 1
        num1 -= 1
    elif num2 == 0:
        num1 -= 1
        num2 += 1
    elif nextInfo == "0":
        if num1 > num2:
            num1 -= 1
            num2 += 1
        elif num1 <= num2:
            num1 += 1
            num2 -= 1
    elif nextInfo == "1":
        num1 += 1
        num2 -= 1
    elif nextInfo == "2":
        num1 -= 1
        num2 += 1

    return num1,num2


n,a,b,c = map(int, input().split())

enforcement = ["NULL"]*n

for i in range(n):
    enforcement[i] = input()

ans = ["NULL"]*n

for i in range(n):
    tmpA = a
    tmpB = b
    tmpC = c
    if i != n-1:
        nextInfo = NextEnforcement(enforcement[i], enforcement[i + 1])
    else:
        nextInfo = "0"

    if enforcement[i] == "AC":
        a,c = Calculation(a,c,nextInfo)
        if tmpA < a :
            ans[i] = "A"
        else:
            ans[i] = "C"
    if enforcement[i] == "AB":
        a,b = Calculation(a,b,nextInfo)
        if tmpA < a :
            ans[i] = "A"
        else:
            ans[i] = "B"
    if enforcement[i] == "BC":
        b,c = Calculation(b,c,nextInfo)
        if tmpB < b :
            ans[i] = "B"
        else:
            ans[i] = "C"

print("Yes")

for i in range(n):
    print(ans[i])

Submission status: Wrong Answer

Solution code:

def NextEnforcement(enfo1,enfo2):
    if(enfo1 == "AB") and (enfo2 == "AC"):
        return "1"
    elif (enfo1 == "AB") and (enfo2 == "BC"):
        return "2"
    elif (enfo1 == "BC") and (enfo2 == "AC"):
        return "2"
    elif (enfo1 == "BC") and (enfo2 == "AB"):
        return "1"
    elif (enfo1 == "AC") and (enfo2 == "AB"):
        return "1"
    elif (enfo1 == "AC") and (enfo2 == "BC"):
        return "2"
    else:
        return "0"


def Calculation(num1,num2,nextInfo):
    if num1 == num2 == 0:
        print("No")
        exit()
    elif nextInfo == "0":
        if num1 > num2:
            num1 -= 1
            num2 += 1
        elif num1 <= num2:
            num1 += 1
            num2 -= 1
    elif nextInfo == "1":
        num1 += 1
        num2 -= 1
    elif nextInfo == "2":
        num1 -= 1
        num2 += 1

    return num1,num2


n,a,b,c = map(int, input().split())

enforcement = ["NULL"]*n

for i in range(n):
    enforcement[i] = input()

ans = ["NULL"]*n

for i in range(n):
    tmpA = a
    tmpB = b
    tmpC = c
    if i != n-1:
        nextInfo = NextEnforcement(enforcement[i], enforcement[i + 1])
    else:
        nextInfo = "0"

    if enforcement[i] == "AC":
        a,c = Calculation(a,c,nextInfo)
        if tmpA < a :
            ans[i] = "A"
        else:
            ans[i] = "C"
    if enforcement[i] == "AB":
        a,b = Calculation(a,b,nextInfo)
        if tmpA < a :
            ans[i] = "A"
        else:
            ans[i] = "B"
    if enforcement[i] == "BC":
        b,c = Calculation(b,c,nextInfo)
        if tmpB < b :
            ans[i] = "B"
        else:
            ans[i] = "C"

print("Yes")

for i in range(n):
    print(ans[i])

Submission status: Wrong Answer

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

def end():
    print("No")
    exit()

def under_zero(x):
    if x < 0:
        return True
    else:
        return False

def solve(string,a,b,c):

    if string == "AB":
        if a>b:
            a -= 1
            b += 1
            log.append("B")
            if under_zero(a):
                return end()
        else:
            a += 1
            b -= 1
            log.append("A")
            if under_zero(b):
                return end()
    elif string == "AC":
        if a>c:
            a -= 1
            c += 1
            log.append("C")
            if under_zero(a):
                return end()
        else:
            a += 1
            c -= 1
            log.append("A")
            if under_zero(c):
                return end()
    else:
        if b>c:
            b -= 1
            c += 1
            log.append("C")
            if under_zero(b):
                return end()
        else:
            b += 1
            c -= 1
            log.append("B")
            if under_zero(c):
                return end()

for i in range(n):
    solve(s[i],a,b,c)
else:
    print("Yes")
    print(*log, sep='\n')

Submission status: Wrong Answer

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

def end():
    print("NO")
    exit()

def under_zero(x):
    if x < 0:
        return True
    else:
        return False

def solve(string,a,b,c):

    if string == "AB":
        if a>b:
            a -= 1
            b += 1
            log.append("B")
            if under_zero(a):
                return end()
        else:
            a += 1
            b -= 1
            log.append("A")
            if under_zero(b):
                return end()
    elif string == "AC":
        if a>c:
            a -= 1
            c += 1
            log.append("C")
            if under_zero(a):
                return end()
        else:
            a += 1
            c -= 1
            log.append("A")
            if under_zero(c):
                return end()
    else:
        if b>c:
            b -= 1
            c += 1
            log.append("C")
            if under_zero(b):
                return end()
        else:
            b += 1
            c -= 1
            log.append("B")
            if under_zero(c):
                return end()

for i in range(n):
    solve(s[i],a,b,c)
else:
    print(*log, sep='\n')

Submission status: Wrong Answer

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

def end():
    print("NO")
    exit()

def under_zero(x):
    if x < 0:
        return True
    else:
        return False

def solve(string,a,b,c):

    if string == "AB":
        if a>b:
            a -= 1
            b += 1
            log.append("B")
            if under_zero(a):
                return end()
        else:
            a += 1
            b -= 1
            log.append("A")
            if under_zero(b):
                return end()
    elif string == "AC":
        if a>c:
            a -= 1
            c += 1
            log.append("C")
            if under_zero(a):
                return end()
        else:
            a += 1
            c -= 1
            log.append("A")
            if under_zero(c):
                return end()
    else:
        if b>c:
            b -= 1
            c += 1
            log.append("C")
            if under_zero(b):
                return end()
        else:
            b += 1
            c -= 1
            log.append("B")
            if under_zero(c):
                return end()

for i in range(n):
    solve(s[i],a,b,c)
else:
    print("YES")
    print(*log, sep='\n')

Submission status: Wrong Answer

Solution code:
def Calculation(num1,num2):
    if num1 == num2 == 0:
        print("No")
        exit()
    elif num1 > num2:
        num1 -= 1
        num2 += 1
    elif num1 <= num2:
        num1 += 1
        num2 -= 1
    return num1,num2

n,a,b,c = map(int, input().split())

enforcement = ["NULL"]*n

for i in range(n):
    enforcement[i] = input()

ans = ["NULL"]*n

for i in range(n):
    tmpA = a
    tmpB = b
    tmpC = c
    if enforcement[i] == "AC":
        a,c = Calculation(a,c)
        if tmpA < a :
            ans[i] = "A"
        else:
            ans[i] = "C"
    if enforcement[i] == "AB":
        a,b = Calculation(a,b)
        if tmpA < a :
            ans[i] = "A"
        else:
            ans[i] = "B"
    if enforcement[i] == "BC":
        b,c = Calculation(b,c)
        if tmpB < b :
            ans[i] = "B"
        else:
            ans[i] = "C"

print("Yes")

for i in range(n):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
#coding:utf-8

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

solve = []
s = str(input())

for i in range(N):

    if i != N-1:
        p = str(input())
    else:
        p = s
    
    if s == 'AB':
        if A == 0 and B == 0:
            print('No')
            break
        if A == 1 and B == 1 and C == 0 and s != p:
            if p == 'BC':
                B += 1
                A -= 1
                solve.append('B')
            elif p == 'AC':
                A += 1
                B -= 1
                solve.append('A')
            continue
        if A >= B:
            A -= 1
            B += 1
            solve.append('B')
        else:
            A += 1
            B -= 1
            solve.append('A')
    elif s == 'BC':
        if B == 0 and C == 0:
            print('No')
            break
        if A == 0 and B == 1 and C == 1 and s != p:
            if p == 'AB':
                B += 1
                C -= 1
                solve.append(B)
            elif p == 'AC':
                C += 1
                B -= 1
                solve.append(C)
            continue
        if B >= C:
            B -= 1
            C += 1
            solve.append('C')
        else:
            B += 1
            C -= 1
            solve.append('B')
    elif s == 'AC':
        if C == 0 and A == 0:
            print('No')
            break
        if A == 1 and B == 0 and C == 1 and s != p:
            if p == 'BC':
                C += 1
                A -= 1
                solve.append(C)
            elif p == 'AB':
                A += 1
                C -= 1
                solve.append(A)
            continue
        if C >= A:
            C -= 1
            A += 1
            solve.append('A')
        else:
            C += 1
            A -= 1
            solve.append('C')

    s = p
            
    if i == N-1:
        print('Yes')
        for t in solve:
            print(t)

Submission status: Wrong Answer

Solution code:
#coding:utf-8

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

solve = []
s = str(input())

for i in range(N-1):

    if i != N-2:
        p = str(input())
    else:
        p = s
    
    if s == 'AB':
        if A == 0 and B == 0:
            print('No')
            break
        if A == 1 and B == 1 and C == 0 and s != p:
            if p == 'BC':
                B += 1
                A -= 1
                solve.append('B')
            elif p == 'AC':
                A += 1
                B -= 1
                solve.append('A')
            continue
        if A >= B:
            A -= 1
            B += 1
            solve.append('B')
        else:
            A += 1
            B -= 1
            solve.append('A')
    elif s == 'BC':
        if B == 0 and C == 0:
            print('No')
            break
        if A == 0 and B == 1 and C == 1 and s != p:
            if p == 'AB':
                B += 1
                C -= 1
                solve.append(B)
            elif p == 'AC':
                C += 1
                B -= 1
                solve.append(C)
            continue
        if B >= C:
            B -= 1
            C += 1
            solve.append('C')
        else:
            B += 1
            C -= 1
            solve.append('B')
    elif s == 'AC':
        if C == 0 and A == 0:
            print('No')
            break
        if A == 1 and B == 0 and C == 1 and s != p:
            if p == 'BC':
                C += 1
                A -= 1
                solve.append(C)
            elif p == 'AB':
                A += 1
                C -= 1
                solve.append(A)
            continue
        if C >= A:
            C -= 1
            A += 1
            solve.append('A')
        else:
            C += 1
            A -= 1
            solve.append('C')

    s = p
            
    if i == N-2:
        print('Yes')
        for t in solve:
            print(t)

Submission status: Wrong Answer

Solution code:
#coding:utf-8

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

solve = []

for i in range(N):
    s = str(input())
    if s == 'AB':
        if A == 0 and B == 0:
            print('No')
            break
        if A >= B:
            A -= 1
            B += 1
            solve.append('B')
        else:
            A += 1
            B -= 1
            solve.append('A')
    elif s == 'BC':
        if B == 0 and C == 0:
            print('No')
            break
        if B >= C:
            B -= 1
            C += 1
            solve.append('C')
        else:
            B += 1
            C -= 1
            solve.append('B')
    elif s == 'AC':
        if C == 0 and A == 0:
            print('No')
            break
        if C >= A:
            C -= 1
            A += 1
            solve.append('A')
        else:
            C += 1
            A -= 1
            solve.append('C')
    if i == N-1:
        print('Yes')
        for t in solve:
            print(t)

Submission status: Wrong Answer

Solution code:
n,a,b,c=map(int,input().split())
new=[]
for i in range(0,n):
    s=input()
    new.append(s)
final=[]
for i in range(0,n):
    if new[i]=='AB':
        if a==0 and b==0:
            print('No')
            break
        elif a<b:
            a+=1
            b-=1
            final.append('A')
        elif a>b:
            b+=1
            a-=1
            final.append('B')
        else:
            a-=1
            b+=1
            final.append('B')
    elif new[i]=='AC':
        if a==0 and c==0:
            print('No')
            break
        elif a<c:
            a+=1
            c-=1
            final.append('A')
        elif a>c:
            c+=1
            a-=1
            final.append('C')
        else:
            a-=1
            c+=1
            final.append('C')
    else:
        if b==0 and c==0:
            print('No')
            break
        elif b<c:
            b+=1
            c-=1
            final.append('B')
        elif b>c:
            c+=1
            b-=1
            final.append('C')
        else:
            b-=1
            c+=1
            final.append('C')
else:
    print('Yes')
    for i in range(0,len(final)):
        print(final[i])

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int,input().split())
ans = []
S = []
for i in range(n):S.append(input())
for i in range(n):
    s = S[i]
    id = (i+1)%n
    if s=="AB":
        if a>b:
            a-=1
            b+=1
            ans.append("B")
        if a<b:
            a+=1
            b-=1
            ans.append("A")
        if a==b:
            if S[id] =="AC":
                a+=1
                b-=1
                ans.append("A")
            else:
                a-=1
                b+=1
                ans.append("B")

    if s=="AC":
        if a>c:
            a-=1
            c+=1
            ans.append("C")
        if a<c:
            a+=1
            c-=1
            ans.append("A")
        if a==c:
            if S[id] =="AB":
                a+=1
                c-=1
                ans.append("A")
            else:
                a-=1
                c+=1
                ans.append("C")

    if s=="BC":
        if b>c:
            b-=1
            c+=1
            ans.append("C")
        if b<c:
            b+=1
            c-=1
            ans.append("B")
        if b==c:
            if S[id] =="AC":
                c+=1
                b-=1
                ans.append("C")
            else:
                c-=1
                b+=1
                ans.append("B")

    if b<0 or c<0 or a<0:
        print("No")
        exit()
print("Yes")
for an in ans:print(an)

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>=b:
            a-=1
            b+=1
            ans.append("B")
        else:
            a+=1
            b-=1
            ans.append("A")
    if s=="AC":
        if a>=c:
            a-=1
            c+=1
            ans.append("C")
        else:
            a+=1
            c-=1
            ans.append("A")
    if s=="BC":
        if b>=c:
            b-=1
            c+=1
            ans.append("C")
        else:
            b+=1
            c-=1
            ans.append("B")
    if b<0 or c<0 or a<0:
        print("No")
        exit()
print("Yes")
for an in ans:print(an)

Submission status: Wrong Answer

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

ans='Yes'
L_ans=['']*(N+1)
i=0
while i<N:
    if S[i]=='AB':
        if A>B:
            B+=1
            A-=1
            L_ans[i]='B'
        elif A<B:
            A+=1
            B-=1
            L_ans[i]='A'
        elif A==B==1 and S[i+1]=='BC':
            B+=1
            A-=1
            L_ans[i]='B'
        else:
            A+=1
            B-=1
            L_ans[i]='A'
    elif S[i]=='AC':
        if A>C:
            C+=1
            A-=1
            L_ans[i]='C'
        elif A<C:
            A+=1
            C-=1
            L_ans[i]='A'
        elif A==C==1 and S[i+1]=='BC':
            C+=1
            A-=1
            L_ans[i]='C'
        else:
            A+=1
            C-=1
            L_ans[i]='A'
    elif S[i]=='BC':
        if C>B:
            B+=1
            C-=1
            L_ans[i]='B'
        elif C<B:
            C+=1
            B-=1
            L_ans[i]='C'
        elif A==B==1 and S[i+1]=='AB':
            B+=1
            C-=1
            L_ans[i]='B'
        else:
            C+=1
            B-=1
            L_ans[i]='C'
    i+=1
    if any([A<0,B<0,C<0]):
        ans='No'
        break

print(ans)
if ans=='Yes':
    j=0
    while j<N:
        print(L_ans[j])
        j+=1

Submission status: Wrong Answer

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

ans='Yes'
L_ans=['']*N
i=0
while i<N:
    if S[i]=='AB':
        if A>=B:
            B+=1
            A-=1
            L_ans[i]='B'
        else:
            A+=1
            B-=1
            L_ans[i]='A'
    elif S[i]=='AC':
        if A>=C:
            C+=1
            A-=1
            L_ans[i]='C'
        else:
            A+=1
            C-=1
            L_ans[i]='A'
    elif S[i]=='BC':
        if C>=B:
            B+=1
            C-=1
            L_ans[i]='B'
        else:
            C+=1
            B-=1
            L_ans[i]='C'
    i+=1
    if any([A<0,B<0,C<0]):
        ans='No'
        break

print(ans)
if ans=='Yes':
    for j in L_ans:
        print(j)

Submission status: Wrong Answer

Solution code:
from collections import deque
from itertools import product
import sys
import math
import numpy as np
import bisect

sys.setrecursionlimit(200000)
input = sys.stdin.readline


def read():
    N, A, B, C = map(int, input().strip().split())
    S = []
    for i in range(N):
        s = input().strip()
        S.append(s)
    return N, A, B, C, S


def choose_at_corner_state(A, B, C, s):
    """次の一手を返す"""
    if A == 0 and C == 0:
        if s == "BC" and not is_error_state(A, B-1, C+1):
            return ("B", A, B-1, C+1)
        if s == "AB" and not is_error_state(A+1, B-1, C):
            return ("A", A+1, B-1, C)
    elif A == 0 and B == 0:
        if s == "AC" and not is_error_state(A+1, B, C-1):
            return ("A", A+1, B, C-1)
        if s == "BC" and not is_error_state(A, B+1, C-1):
            return ("B", A, B+1, C-1)
    elif B == 0 and C == 0:
        if s == "AC" and not is_error_state(A-1, B, C+1):
            return ("A", A-1, B, C+1)
        if s == "AB" and not is_error_state(A-1, B+1, C):
            return ("B", A-1, B+1, C)
    return ("X", -1, -1, -1)


def is_error_state(A, B, C):
    if A < 0 or B < 0 or C < 0:
        return True
    return False


def is_corner_state(A, B, C):
    if A == 0 and B == 0:
        return True
    elif A == 0 and C == 0:
        return True
    elif B == 0 and C == 0:
        return True
    return False


def choose_at_normal_state(A, B, C, s0, s1):
    """先読みして、次の一手を返す"""
    if s0 == "BC":
        op0, a0, b0, c0 = ("C", A, B-1, C+1)
        if is_error_state(a0, b0, c0):
            pass
        elif is_corner_state(a0, b0, c0):
            op1, a1, b1, c1 = choose_at_corner_state(a0, b0, c0, s1)
            if op1 != "X":
                return (op0, a0, b0, c0)
        else:
            return (op0, a0, b0, c0)
        op0, a0, b0, c0 = ("B", A, B+1, C-1)
        if is_error_state(a0, b0, c0):
            pass
        elif is_corner_state(a0, b0, c0):
            op1, a1, b1, c1 = choose_at_corner_state(a0, b0, c0, s1)
            if op1 != "X":
                return (op0, a0, b0, c0)
        else:
            return (op0, a0, b0, c0)
    elif s0 == "AC":
        op0, a0, b0, c0 = ("C", A-1, B, C+1)
        if is_error_state(a0, b0, c0):
            pass
        elif is_corner_state(a0, b0, c0):
            op1, a1, b1, c1 = choose_at_corner_state(a0, b0, c0, s1)
            if op1 != "X":
                return (op0, a0, b0, c0)
        else:
            return (op0, a0, b0, c0)
        op0, a0, b0, c0 = ("A", A+1, B, C-1)
        if is_error_state(a0, b0, c0):
            pass
        elif is_corner_state(a0, b0, c0):
            op1, a1, b1, c1 = choose_at_corner_state(a0, b0, c0, s1)
            if op1 != "X":
                return (op0, a0, b0, c0)
        else:
            return (op0, a0, b0, c0)
    elif s0 == "AB":
        op0, a0, b0, c0 = ("B", A-1, B+1, C)
        if is_error_state(a0, b0, c0):
            pass
        elif is_corner_state(a0, b0, c0):
            op1, a1, b1, c1 = choose_at_corner_state(a0, b0, c0, s1)
            if op1 != "X":
                return (op0, a0, b0, c0)
        else:
            return (op0, a0, b0, c0)
        op0, a0, b0, c0 = ("A", A+1, B-1, C)
        if is_error_state(a0, b0, c0):
            pass
        elif is_corner_state(a0, b0, c0):
            op1, a1, b1, c1 = choose_at_corner_state(a0, b0, c0, s1)
            if op1 != "X":
                return (op0, a0, b0, c0)
        else:
            return (op0, a0, b0, c0)
    return ("X", -1, -1, -1)


def trial(N, A, B, C, S):
    
    if A + B + C == 0:
        return False, []
    
    ans, choices = True, []

    S = S + [S[-1]]  # S[-1] is terminal state

    if A + B + C == 1:
        for i in range(N):
            x, A, B, C = choose_at_corner_state(A, B, C, S[i])
            if x == "X":
                return False, []
            else:
                choices.append(x)
    else:
        for i in range(N):
            if is_corner_state(A, B, C):
                x, A, B, C = choose_at_corner_state(A, B, C, S[i])
            else:
                x, A, B, C = choose_at_normal_state(A, B, C, S[i], S[i+1])
            if x == "X":
                return False, []
            else:
                choices.append(x)
    return ans, choices


def solve(N, A, B, C, S):
    ans, choices = trial(N, A, B, C, S)
    if ans:
        print("Yes")
        for c in choices:
            print(c)
    else:
        print("No")


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("{}".format(outputs))