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())
arr=[input() for _ in range(n)]
if a>=1 and b>=1 and c>=1:
  print('Yes')
  ans=[]
  for i in range(n):
    if arr[i]=='AB':
      if a>=b:
        a-=1
        b+=1
        ans.append('B')
      else:
        a+=1
        b-=1
        ans.append('A')
    elif arr[i]=='AC':
      if a>=c:
        a-=1
        c+=1
        ans.append('C')
      else:
        a+=1
        c-=1
        ans.append('A')
    elif arr[i]=='BC':
      if b>=c:
        b-=1
        c+=1
        ans.append('C')
      else:
        b+=1
        c-=1
        ans.append('B')
  for i in range(n):
    print(ans[i])
else:
  ans=[]
  for i in range(n):
    if arr[i]=='AB':
      if a>b:
        a-=1
        b+=1
        ans.append('B')
      elif a<b:
        a+=1
        b-=1
        ans.append('A')
      elif a==b:
        if a==0:
          print('No')
          break
        else:
          if i!=n-1:
            if arr[i+1]=='AB':
              a+=1
              b-=1
              ans.append('A')
            elif arr[i+1]=='BC':
              a-=1
              b+=1
              ans.append('B')
            elif arr[i+1]=='AC':
              a+=1
              b-=1
              ans.append('C')
          else:
            a+=1
            b-=1
            ans.append('A')
    elif arr[i]=='AC':
      if a>c:
        a-=1
        c+=1
        ans.append('C')
      elif a<c:
        a+=1
        c-=1
        ans.append('A')
      elif a==c:
        if a==0:
          print('No')
          break
        else:
          if i!=n-1:
            if arr[i+1]=='AC':
              a+=1
              c-=1
              ans.append('A')
            elif arr[i+1]=='AB':
              a+=1
              c-=1
              ans.append('A')
            elif arr[i+1]=='BC':
              a-=1
              c+=1
              ans.append('C')
          else:
            a+=1
            c-=1
            ans.append('A')
    elif arr[i]=='BC':
      if b>c:
        b-=1
        c+=1
        ans.append('C')
      elif b<c:
        b+=1
        c-=1
        ans.append('B')
      elif b==c:
        if b==0:
          print('No')
          break
        else:
          if i!=n-1:
            if arr[i+1]=='BC':
              b+=1
              c-=1
              ans.append('B')
            elif arr[i+1]=='AB':
              b+=1
              c-=1
              ans.append('B')
            elif arr[i+1]=='AC':
              b-=1
              c+=1
              ans.append('C')
          else:
            b+=1
            c-=1
            ans.append('B')
  else:
    print('Yes')
    for i in range(n):
      print(ans[i])

Submission status: Wrong Answer

Solution code:
n, a, b, c = list(map(int, input().split()))
ans = []
for _ in range(n):
    move = input()
    if move == 'AB':
        if a <= b:
            a += 1
            b -= 1
            ans.append('A')
        else:
            a -= 1
            b += 1
            ans.append('B')
    elif move == 'AC':
        if a <= c:
            a += 1
            c -= 1
            ans.append('A')
        else:
            a -= 1
            c += 1
            ans.append('C')
    else:
        if b <= c:
            b += 1
            c -= 1
            ans.append('B')
        else:
            b -= 1
            c += 1
            ans.append('C')
    if a < 0 or b < 0 or c < 0:
        print('NO')
        exit()
if a >= 0 and b >= 0 and c >= 0:
    print('YES')
    for i in ans:
        print(i)
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
N, A, B, C = map(int, input().split())
v = [A, B, C]
id_d = {'A':0, 'B':1, 'C':2}
ans = [0] * N
temp = []
for i in range(N):
  s1, s2 = list(input())
  v1, v2 = v[id_d[s1]], v[id_d[s2]]
  if v1 == v2 == 0:
    print('No')
    quit()
  else:
    if v1 >= v2:
      ans[i] = s2
      v[id_d[s1]] -= 1
      v[id_d[s2]] += 1
    else:
      ans[i] = s1
      v[id_d[s2]] -= 1
      v[id_d[s1]] += 1

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

Submission status: Wrong Answer

Solution code:
import sys
n,a,b,c = map(int, input().split())
s=[input() for _ in range(n)]
num = [a,b,c]
ans = ''

def f(st):
    if st == 'A':
        return 0
    elif st == 'B':
        return 1
    else:
        return 2

if a+b+c == 0:
    print('No')
    sys.exit()
    
if a+b+c == 1:
    for i in range(n):
        x,y=f(s[i][0]),f(s[i][1])
        if num[x] == 0 and num[y] == 0:
            print('No')
            sys.exit()
        else:
            if num[x] == 0:
                ans += (s[i][0] + '\n')
                num[x] += 1
                num[y] -= 1
                
            else:
                ans += (s[i][1] + '\n')
                num[y] += 1
                num[x] -= 1
        #print(ans)
    print('Yes')
    print(ans[:-1],end='')
    sys.exit()

if a+b+c == 2:
    for i in range(n):
        x,y=f(s[i][0]),f(s[i][1])
        if num[x] == 0 and num[y] == 0:
            print('No')
            sys.exit()
        else:
            if num[x] == 0:
                ans += (s[i][0] + '\n')
                num[x] += 1
                num[y] -= 1
                
            elif num[y] == 0:
                ans += (s[i][1] + '\n')
                num[y] += 1
                num[x] -= 1
            
            else:
                if i == n-1:
                    ans += (s[i][1] + '\n')
                else:
                    xx,yy=f(s[i+1][0]),f(s[i+1][1])
                    if x==xx:
                        ans += (s[i][0] + '\n')
                        num[x] += 1
                        num[y] -= 1                       
                    else:
                        ans += (s[i][1] + '\n')
                        num[y] += 1
                        num[x] -= 1
                   
    print('Yes')
    print(ans[:-1],end='')
    sys.exit()

if (a+b+c==a and s[0]=='BC') or (a+b+c==b and s[0]=='AC') or (a+b+c==c and s[0]=='AC'):
    print('No')
    sys.exit()
    

for i in range(n):
    x,y=f(s[i][0]),f(s[i][1])
    if num[x] == 0 and num[y] == 0:
        print('No')
        sys.exit()
    
    else:
        if num[x] == 0:
            ans += (s[i][0] + '\n')
            num[x] += 1
            num[y] -= 1
            
        elif num[y] == 0:
            ans += (s[i][1] + '\n')
            num[y] += 1
            num[x] -= 1
        
        elif num[x] == 1:
            #if num[y] == 1:
                
            ans += (s[i][0] + '\n')
            num[x] += 1
            num[y] -= 1
            
        else:
            ans += (s[i][1] + '\n')
            num[y] += 1
            num[x] -= 1
    
print('Yes')
print(ans[:-1],end='')
sys.exit()

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int, input().split())
ans = []
for i in range(n):
    if (a==0):
            if (b==0 or c==0):
                print("No")
                exit()
    if (b==0):
        if (c==0):
            print("No")
            exit()
    x = input()    
    if (x=="AB"):
        if a<=b:
            a += 1
            b -= 1
            ans.append("A")
        else:
            a -= 1
            b += 1
            ans.append("B")
    elif (x=="BC"):
        if b<=c:
            b += 1
            c -= 1
            ans.append("B")
        else:
            b -= 1
            c += 1
            ans.append("C")
    else:
        if a<=c:
            a += 1
            c -= 1
            ans.append("A")
        else:
            a -= 1
            c += 1
            ans.append("C")
print("Yes")            
print(*ans, sep="\n")

Submission status: Wrong Answer

Solution code:

MOD = 10 ** 9 + 7
RLIMIT = 1000
DEBUG = 1

def main():
    for _ in inputt(1):
        n, a, b, c = inputi()
        S = inputl(n, input)
        if a == b == 0 and "AB" == S[0]:
            print("No")
            break
        if b == c == 0 and "BC" == S[0]:
            print("No")
            break
        if c == a == 0 and "AC" == S[0]:
            print("No")
            break
        if sum([a, b, c]) > 2:
            print("Yes")
            for z in S:
                if z == "AB":
                    if a < b:
                        print("A")
                        a += 1
                        b -= 1
                    else:
                        print("B")
                        a -= 1
                        b += 1
                elif z == "BC":
                    if b < c:
                        print("B")
                        b += 1
                        c -= 1
                    else:
                        print("C")
                        b -= 1
                        c += 1

                else:
                    if a < c:
                        print("A")
                        a += 1
                        c -= 1
                    else:
                        print("C")
                        a -= 1
                        c += 1
            break
        R = []
        if sum([a, b, c]) == 1:
            for z in S:
                if z == "AB":
                    if a == b == 0:
                        break
                    if a < b:
                        R.append("A")
                        a += 1
                        b -= 1
                    else:
                        R.append("B")
                        a -= 1
                        b += 1
                elif z == "BC":
                    if c == b == 0:
                        break
                    if b < c:
                        R.append("B")
                        b += 1
                        c -= 1
                    else:
                        R.append("C")
                        b -= 1
                        c += 1
                else:
                    if a == c == 0:
                        break
                    if a < c:
                        R.append("A")
                        a += 1
                        c -= 1
                    else:
                        R.append("C")
                        a -= 1
                        c += 1
            else:
                print("Yes")
                print(*R, split = "\n")
                break
            print("No")
            break

        print("YES")
        for i, z in enumerate(S):
            if z == "AB":
                if a == 0:
                    print("A")
                    a += 1
                    b -= 1
                elif b == 0:
                    print("B")
                    a -= 1
                    b += 1
                else:
                    if i + 1 < n and "A" in S[i + 1]:
                        print("A")
                        a += 1
                        b -= 1
                    else:
                        print("B")
                        a -= 1
                        b += 1

            elif z == "BC":
                if c == 0:
                    print("C")
                    c += 1
                    b -= 1
                elif b == 0:
                    print("B")
                    c -= 1
                    b += 1
                else:
                    if i + 1 < n and "C" in S[i + 1]:
                        print("C")
                        c += 1
                        b -= 1
                    else:
                        print("B")
                        c -= 1
                        b += 1

            else:
                if a == 0:
                    print("A")
                    a += 1
                    c -= 1
                elif c == 0:
                    print("C")
                    a -= 1
                    c += 1
                else:
                    if i + 1 < n and "A" in S[i + 1]:
                        print("A")
                        a += 1
                        c -= 1
                    else:
                        print("C")
                        a -= 1
                        c += 1



# region M


# region import

from math import *
from heapq import *
from itertools import *
from functools import reduce, lru_cache, partial
from collections import Counter, defaultdict
import re, copy, operator, cmath
import sys, io, os, builtins
sys.setrecursionlimit(RLIMIT)

# endregion

# region fastio

BUFSIZE = 8192
class FastIO(io.IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = io.BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(io.IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
    if args:
        sys.stdout.write(str(args[0]))
        split = kwargs.pop("split", " ")
        for arg in args[1:]:
            sys.stdout.write(split)
            sys.stdout.write(str(arg))
    sys.stdout.write(kwargs.pop("end", "\n"))
def debug(*args, **kwargs):
    if DEBUG and not __debug__:
        print("debug", *args, **kwargs)
        sys.stdout.flush()
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip()
inputt = lambda t = 0: range(t) if t else range(int(input()))
inputs = lambda: input().split()
inputi = lambda k = int: map(k, inputs())
inputl = lambda t = 0, k = lambda: list(inputi()): [k() for _ in range(t)] if t else list(k())

# endregion

# region bisect

def len(a):
    if isinstance(a, range):
        return -((a.start - a.stop) // a.step)
    return builtins.len(a)
def bisect_left(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if key(a[mid]) < x: lo = mid + 1
        else: hi = mid
    return lo
def bisect_right(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if x < key(a[mid]): hi = mid
        else: lo = mid + 1
    return lo
def insort_left(a, x, key = None, lo = 0, hi = None):
    lo = bisect_left(a, x, key, lo, hi)
    a.insert(lo, x)
def insort_right(a, x, key = None, lo = 0, hi = None):
    lo = bisect_right(a, x, key, lo, hi)
    a.insert(lo, x)
do_nothing = lambda x: x
bisect = bisect_right
insort = insort_right
def index(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi and key(a[i]) == x: return a[i]
    if default != None: return default
    raise ValueError
def find_lt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_le(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_gt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError
def find_ge(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError

# endregion

# region csgraph
# TODO

class Tree:
    def __init__(n):
        self._n = n
        self._conn = [[] for _ in range(n)]
        self._list = [0] * n
    def connect(a, b):
        pass

# endregion

# region ntheory

class Sieve:
    def __init__(self):
        self._n = 6
        self._list = [2, 3, 5, 7, 11, 13]
    def extend(self, n):
        if n <= self._list[-1]: return
        maxbase = int(n ** 0.5) + 1
        self.extend(maxbase)
        begin = self._list[-1] + 1
        newsieve = [i for i in range(begin, n + 1)]
        for p in self.primerange(2, maxbase):
            for i in range(-begin % p, len(newsieve), p):
                newsieve[i] = 0
        self._list.extend([x for x in newsieve if x])
    def extend_to_no(self, i):
        while len(self._list) < i: 
            self.extend(int(self._list[-1] * 1.5))
    def primerange(self, a, b):
        a = max(2, a)
        if a >= b: return
        self.extend(b)
        i = self.search(a)[1]
        maxi = len(self._list) + 1
        while i < maxi:
            p = self._list[i - 1]
            if p < b:
                yield p
                i += 1
            else: return
    def search(self, n):
        if n < 2: raise ValueError
        if n > self._list[-1]: self.extend(n)
        b = bisect(self._list, n)
        if self._list[b - 1] == n: return b, b
        else: return b, b + 1
    def __contains__(self, n):
        if n < 2: raise ValueError
        if not n % 2: return n == 2
        a, b = self.search(n)
        return a == b
    def __getitem__(self, n):
        if isinstance(n, slice):
            self.extend_to_no(n.stop + 1)
            return self._list[n.start: n.stop: n.step]
        else:
            self.extend_to_no(n + 1)
            return self._list[n]
sieve = Sieve()
def isprime(n):
    if n <= sieve._list[-1]:
        return n in sieve
    for i in sieve:
        if not n % i: return False
        if n < i * i: return True
prime = sieve.__getitem__
primerange = lambda a, b = 0: sieve.primerange(a, b) if b else sieve.primerange(2, a)
def factorint(n):
    factors = []
    for i in sieve:
        if n < i * i: break
        while not n % i:
            factors.append(i)
            n //= i
    if n != 1: factors.append(n)
    return factors
factordict = lambda n: Counter(factorint(n))

# endregion

# region main

if __name__ == "__main__":
    main()

# endregion


# endregion

Submission status: Wrong Answer

Solution code:
def resolve():
    N,A,B,C = map(int,input().split())

    S=[input() for i in range(N)]
    ans =[]
    for s in S:
        if s =="AB":
            if A ==B ==0:
                print("No")
                return
            elif A>B:
                A-=1
                B+=1
                ans.append("B")
            else:
                A+=1
                B-=1
                ans.append("A")

        elif s =="BC":
            if C ==B ==0:
                print("No")
                return
            elif C>B:
                C-=1
                B+=1
                ans.append("B")
            else:
                C+=1
                B-=1
                ans.append("C")

        elif s =="AC":
            if C ==A ==0:
                print("No")
                return
            elif C>A:
                C-=1
                A+=1
                ans.append("A")
            else:
                C+=1
                A-=1
                ans.append("C")



    print("\n".join(ans))







if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
ans = []
n,a,b,c = map(int, input().split())
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')
    elif s == 'BC':
        if b > c:
            b-=1
            c+=1
            ans.append('C')
        else:
            b+=1
            c-=1
            ans.append('B')
    else:
        if c > a:
            c-=1
            a+=1
            ans.append('A')
        else:
            c+=1
            a-=1
            ans.append('C')
if a >= 0 and b >= 0 and c >= 0:
    print('Yes')
    for num in ans:
        print(num)
else:
    print('No')

Submission status: Wrong Answer

Solution code:
#!python3

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


def main():
    l = [A, B, C]
    d = {"AB": (0, 1, 2), "AC": (0, 2, 1), "BC": (1, 2, 0)}
    dl = ["A", "B", "C"]
    ans = []
    for n in range(N):
        i, j, k = d[S[n]]
        if l[i] < l[j]:
            l[i] += 1
            l[j] -= 1
            ans.append(dl[i])
        elif l[i] > l[j]:
            l[i] -= 1
            l[j] += 1
            ans.append(dl[j])
        elif l[i] == 0:
            print("No")
            return
        elif S[n] == S[n + 1]:
            l[i] += 1
            l[j] -= 1
            ans.append(dl[i])
        else:
            if j == d[S[n + 1]][2]:
                i, j = j, i
            if l[i] <= l[k]:
                l[i] -= 1
                l[j] += 1
                ans.append(dl[j])
            else:
                l[i] += 1
                l[j] -= 1
                ans.append(dl[i])
        
    print("Yes")
    print("\n".join(ans))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,a,b,c=map(int,input().split())
li=[]
ansl=[]
flag=0
for i in range(n):
    si=input()
    li.append(si)
for j in range(n):
    if li[j]=="AB":
        if a==0 and b==0:
            break
        if a>b:
            a-=1
            b+=1
            ansl.append("B")
        elif a<b:
            a+=1
            b-=1
            ansl.append("A")
        elif a==b:
            if j==n-1:
                a+=1
                b-=1
                ansl.append("A")
            elif li[j+1]=="AB":
                a+=1
                b-=1
                ansl.append("A")
            elif li[j+1]=="AC":
                a+=1
                b-=1
                ansl.append("A")
            elif li[j+1]=="BC":
                a-=1
                b+=1
                ansl.append("B")
    elif li[j]=="AC":
        if a==0 and c==0:
            break
        if a>c:
            a-=1
            c+=1
            ansl.append("C")
        elif a<c:
            a+=1
            b-=1
            ansl.append("A")
        elif a==c:
            if j==n-1:
                a+=1
                c-=1
                ansl.append("A")
            elif li[j+1]=="AB":
                a+=1
                c-=1
                ansl.append("A")
            elif li[j+1]=="AC":
                a+=1
                c-=1
                ansl.append("A")
            elif li[j+1]=="BC":
                a-=1
                c+=1
                ansl.append("C")

    elif li[j]=="BC":
        if c==0 and b==0:
            break
        if c>b:
            c-=1
            b+=1
            ansl.append("B")
        elif c<b:
            c+=1
            b-=1
            ansl.append("C")
        elif c==b:
            if j==n-1:
                c+=1
                b-=1
                ansl.append("C")
            elif li[j+1]=="AB":
                c-=1
                b+=1
                ansl.append("B")
            elif li[j+1]=="AC":
                c+=1
                b-=1
                ansl.append("C")
            elif li[j+1]=="BC":
                c-=1
                b+=1
                ansl.append("B")
    if j==n-1:
        flag=1

if flag==0:
    print("No")
elif flag==1:
    print("Yes")
    for ii in range(n):
        print(ansl[ii])

Submission status: Wrong Answer

Solution code:
n,a,b,c=map(int,input().split())
z=a+b+c
if z==0:
    print('No')
else:
    ans=[]
    sl=[]
    for i in range(n):
        sl.append(input())
    i=0
    while i<n:
        s=sl[i]
        if s=='AB' and a==0 and b==0:
            print('No')
            exit()
        if s=='BC' and c==0 and b==0:
            print('No')
            exit()
        if s=='AC' and a==0 and c==0:
            print('No')
            exit()
        if s=='AB':
            if a<b:
                b-=1
                a+=1
                ans.append('A')
            elif a>b:
                a-=1
                b+=1
                ans.append('B')
            else:
                i+=1
                ff=1
                while i<n and sl[i]=='AB':
                    ff+=1
                    i+=1
                if i==n:
                    for pp in range(ff):
                        if pp%2==0:
                            ans.append('A')
                        else:
                            ans.append('B')
                    break
                if sl[i]=='AC':
                    for pp in range(ff):
                        if pp%2==0:
                            ans.append('A')
                        else:
                            ans.append('B')
                if sl[i]=='BC':
                    for pp in range(ff):
                        if pp%2==0:
                            ans.append('B')
                        else:
                            ans.append('A')
                            
                continue
        if s=='AC':
            if c<a:
                a-=1
                c+=1
                ans.append('C')
            elif c>a:
                c-=1
                a+=1
                ans.append('A')
            else:
                i+=1
                ff=1
                while i<n and sl[i]=='AC':
                    ff+=1
                    i+=1
                if i==n:
                    for pp in range(ff):
                        if pp%2==0:
                            ans.append('A')
                        else:
                            ans.append('C')
                    break
                if sl[i]=='AB':
                    for pp in range(ff):
                        if pp%2==0:
                            ans.append('A')
                        else:
                            ans.append('C')
                if sl[i]=='BC':
                    for pp in range(ff):
                        if pp%2==0:
                            ans.append('C')
                        else:
                            ans.append('A')
                            
                continue
        if s=='BC':
            if c<b:
                b-=1
                c+=1
                ans.append('C')
            elif c>b:
                c-=1
                b+=1
                ans.append('B')
            else:
                i+=1
                ff=1
                while i<n and sl[i]=='BC':
                    ff+=1
                    i+=1
                if i==n:
                    for pp in range(ff):
                        if pp%2==0:
                            ans.append('C')
                        else:
                            ans.append('B')
                    break
                if sl[i]=='AC':
                    for pp in range(ff):
                        if pp%2==0:
                            ans.append('C')
                        else:
                            ans.append('B')
                if sl[i]=='AB':
                    for pp in range(ff):
                        if pp%2==0:
                            ans.append('B')
                        else:
                            ans.append('C')
                            
                continue
        i+=1
    print('Yes')
    for i in ans:
        print(i)
exit()
if z>=3 or z==1:
    ans=[]
    for i in range(n):
        s=input()
        if s=='AB' and a==0 and b==0:
            print('No')
            exit()
        if s=='BC' and c==0 and b==0:
            print('No')
            exit()
        if s=='AC' and a==0 and c==0:
            print('No')
            exit()
        if s=='AB':
            if b<a:
                a-=1
                b+=1
                ans.append('B')
            else:
                b-=1
                a+=1
                ans.append('A')
        if s=='AC':
            if c<a:
                a-=1
                c+=1
                ans.append('C')
            else:
                c-=1
                a+=1
                ans.append('A')
        if s=='BC':
            if c<b:
                b-=1
                c+=1
                ans.append('C')
            else:
                c-=1
                b+=1
                ans.append('B')
    print('Yes')
    for i in ans:
        print(i)