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:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n, a, b, c = map(int,input().split())
    D = {"AB" : (0, 1), "AC" : (0, 2), "BC" : (1, 2)}
    E = {0 : 'A', 1 : 'B', 2 : 'C'}
    queries = [D[input()] for _ in range(n)]
    s = a + b + c

    if s != 2:
        ans = []
        state = [a, b, c]
        for i, j in queries:
            if state[i] == 0 and state[j] == 0:
                print("No")
                return
            if state[i] < state[j]:
                state[i] += 1
                state[j] -= 1
                ans.append(E[i])
            else:
                state[i] -= 1
                state[j] += 1
                ans.append(E[j])
        print("Yes")
        print(*ans, sep = '\n')
        return

    # s = 2
    # dp = set()
    # dp.add((a, b, c))
    # prev = [{}] * n
    # for k in range(n):
    #     ndp = set()
    #     i, j = queries[k]
    #     for key in dp:
    #         if key[i] > 0:
    #             tmp = list(key)
    #             tmp[i] -= 1
    #             tmp[j] += 1
    #             tmp = tuple(tmp)
    #             ndp.add(tmp)
    #             prev[k][tmp] = key
    #         if key[j] > 0:
    #             tmp = list(key)
    #             tmp[i] += 1
    #             tmp[j] -= 1
    #             tmp = tuple(tmp)
    #             ndp.add(tmp)
    #             prev[k][tmp] = key
    #     dp = ndp
    # 
    # if len(dp) == 0:
    #     print("No")
    #     return
    # 
    # print("Yes")
    # for key in dp:
    #     now = key
    #     break
    # 
    # ans = []
    # for k in range(n - 1, -1, -1):
    #     a, b, c = now
    #     pa, pb, pc = prev[k][now]
    #     if a > pa:
    #         ans.append('A')
    #     elif b > pb:
    #         ans.append('B')
    #     elif c > pc:
    #         ans.append('C')
    #     now = pa, pb, pc
    # ans.reverse()
    # print(*ans, sep = '\n')
resolve()

Submission status: Wrong Answer

Solution code:
n,a,b,c=map(int,input().split())
arr=[input() for _ in range(n)]
ans=[]
for i in range(n):
  if arr[i]=='AB':
    if a==1 and b==1:
      if i==n-1 or arr[i+1]=='AB' or arr[i+1]=='AC':
        a+=1
        b-=1
        ans.append('A')
      elif arr[i+1]=='BC':
        a-=1
        b+=1
        ans.append('B')
    elif a==0 and b==0:
      print('No')
      break
    else:
      if a>=b:
        a-=1
        b+=1
        ans.append('B')
      else:
        a+=1
        b-=1
        ans.append('A')
  elif arr[i]=='AC':
    if a==1 and c==1:
      if i==n-1 or arr[i+1]=='AC' or arr[i+1]=='AB':
        a+=1
        c-=1
        ans.append('A')
      elif arr[i+1]=='BC':
        a-=1
        c+=1
        ans.append('C')
    elif a==0 and c==0:
      print('No')
      break
    else:
      if a>=c:
        a-=1
        c+=1
        ans.append('C')
      else:
        a+=1
        c-=1
        ans.append('A')
  elif arr[i]=='BC':
    if b==1 and c==1:
      if i==n-1 or arr[i+1]=='BC' or arr[i+1]=='AB':
        b+=1
        c-=1
        ans.append('B')
      elif arr[i+1]=='AC':
        b-=1
        c+=1
        ans.append('C')
    elif a==0 and b==0:
      print('No')
      break
    else:
      if b>=c:
        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=map(int,input().split())
arr=[input() for _ in range(n)]
ans=[]
for i in range(n):
  if arr[i]=='AB':
    if a==1 and b==1:
      if i==n-1 or arr[i+1]=='AB':
        a+=1
        b-=1
        ans.append('A')
      elif arr[i+1]=='AC':
        a+=1
        b-=1
        ans.append('A')
      elif arr[i+1]=='BC':
        a-=1
        b+=1
        ans.append('B')
    elif a==0 and b==0:
      print('No')
      break
    else:
      if a>=b:
        a-=1
        b+=1
        ans.append('B')
      else:
        a+=1
        b-=1
        ans.append('A')
  elif arr[i]=='AC':
    if a==1 and c==1:
      if i==n-1 or 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')
    elif a==0 and c==0:
      print('No')
      break
    else:
      if a>=c:
        a-=1
        c+=1
        ans.append('C')
      else:
        a+=1
        c-=1
        ans.append('C')
  elif arr[i]=='BC':
    if b==1 and c==1:
      if i==n-1 or 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')
    elif a==0 and b==0:
      print('No')
      break
    else:
      if b>=c:
        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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


class Player():

    A = 0
    B = 1
    C = 2

    def __init__(self, data, op_list):
        self.data = data
        self.op_list = op_list
        self.move_history = ["X"] * len(self.op_list)
        self.key = 0
        self.ans = "Yes" # "Yes" or "No"
        self.flg_out = False
        self.flg_foresight = False
        s = sum(data)
        if s == 2:
            self.flg_foresight = True
        elif s == 0 or s == 1:
            self.ans = "No"
            self.flg_out = True

    def has_next_op(self):
        if self.key + 1 < len(self.op_list):
            return True
        else:
            return False

    def play(self):
        for key, op in enumerate(op_list):
            #print('self.data') # debug
            #print(self.data) # debug
            if self.flg_out:
                break
            self.key = key
            self.read_op(op)

    def read_op(self, op):
        if op == "AB":
            self.do(self.A, self.B)
        if op == "AC":
            self.do(self.A, self.C)
        if op == "BC":
            self.do(self.B, self.C)

    def do(self, x, y):
        if self.data[x] < self.data[y]:
            self.move(y, x)
        elif self.data[x] > self.data[y]:
            self.move(x, y)
        else: # same
            if self.flg_foresight:
                if self.is_next_used(x):
                    self.move(y, x)
                else:
                    self.move(x, y)
            else:
                self.move(x, y) # which is ok

    def move(self, frm, to):
        self.move_history[self.key] = self.num_to_char(to)
        self.data[frm] -= 1
        self.data[to] += 1
        if self.data[frm] < 0:
            self.ans = "No"
            self.flg_out = True

    @staticmethod
    def num_to_char(z):
        chars = ['A', 'B', 'C']
        return chars[z]

    def is_next_used(self, z):
        if not self.has_next_op():
            return False
        next_op = self.op_list[self.key + 1]
        if self.num_to_char(z) in next_op:
            return True
        else:
            return False

    def print_ans(self):
        print(self.ans)
        if self.ans == "No":
            return
        for h in self.move_history:
            print(h)




if __name__ == '__main__':
    n, a, b, c = list(map(int, input().split()))
    data = [a, b, c]
    #print('data') # debug
    #print(data) # debug
    op_list = [""] * n
    for i in range(n):
        op_list[i] = input()
    #print('op_list') # debug
    #print(op_list) # debug

    p = Player(data, op_list)
    p.play()
    p.print_ans()


    #print('\33[32m' + 'end' + '\033[0m') # debug

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==0:
            a+=1
            b-=1
            ans.append("A")
        elif b==0:
            a-=1
            b+=1
            ans.append("B")
        elif a>b:
            a-=1
            b+=1
            ans.append("B")
        else:
            a+=1
            b-=1
            ans.append("A")
    elif s=="AC":
        if a==0:
            a+=1
            c-=1
            ans.append("A")
        elif c==0:
            a-=1
            c+=1
            ans.append("C")
        elif a>c:
            a-=1
            c+=1
            ans.append("C")
        else:
            a+=1
            c-=1
            ans.append("A")
    else:
        if b==0:
            b+=1
            c-=1
            ans.append("B")
        elif c==0:
            b-=1
            c+=1
            ans.append("C")
        elif b>c:
            b-=1
            c+=1
            ans.append("C")
        else:
            b+=1
            c-=1
            ans.append("B")
    if a<0 or b<0 or c<0:
        ans.clear()
        break
if len(ans)==0:
    print("No")
else:
    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)]
ans=""
for i in range(n):
    s1,s2=s_[i]
    if s2=="B":
        if a==b==1 and i!=n-1:
            if s_[i+1][0]=="A":
                a,b,ans=(a+1,b-1,ans+"A")
            else:
                a,b,ans=(a-1,b+1,ans+"B")
            continue
        a,b,ans=(a-1,b+1,ans+"B") if a>b else (a+1,b-1,ans+"A")
        if min(a,b)==-1:
            print("No")
            break
    elif s1=="A":
        if a==c==1 and i!=n-1:
            if s_[i+1][1]=="C":
                a,c,ans=(a-1,c+1,ans+"C")
            else:
                a,c,ans=(a+1,c-1,ans+"A")
            continue
        a,c,ans=(a-1,c+1,ans+"C") if a>b else (a+1,c-1,ans+"A")
        if min(a,c)==-1:
            print("No")
            break
    else:
        if c==b==1 and i!=n-1:
            if s_[i+1][1]=="C":
                b,c,ans=(b-1,c+1,ans+"C")
            else:
                b,c,ans=(b+1,c-1,ans+"B")
            continue
        b,c,ans=(b-1,c+1,ans+"C") if a>b else (b+1,c-1,ans+"B")
        if min(b,c)==-1:
            print("No")
            break
else:
    print("Yes")
    for j in range(n):
        print(ans[j])

Submission status: Wrong Answer

Solution code:
n,a,b,c=map(int,input().split())
s_=[input() for i in range(n)]
ans=""
for i in range(n):
    s1,s2=s_[i]
    if s2=="B":
        if a==b==1:
            if s_[i+1][0]=="A":
                a,b,ans=(a+1,b-1,ans+"A")
            else:
                a,b,ans=(a-1,b+1,ans+"B")
            continue
        a,b,ans=(a-1,b+1,ans+"B") if a>b else (a+1,b-1,ans+"A")
        if min(a,b)==-1:
            print("No")
            break
    elif s1=="A":
        if a==c==1:
            if s_[i+1][1]=="C":
                a,c,ans=(a-1,c+1,ans+"C")
            else:
                a,c,ans=(a+1,c-1,ans+"A")
            continue
        a,c,ans=(a-1,c+1,ans+"C") if a>b else (a+1,c-1,ans+"A")
        if min(a,c)==-1:
            print("No")
            break
    else:
        if c==b==1:
            if s_[i+1][1]=="C":
                b,c,ans=(b-1,c+1,ans+"C")
            else:
                b,c,ans=(b+1,c-1,ans+"B")
            continue
        b,c,ans=(b-1,c+1,ans+"C") if a>b else (b+1,c-1,ans+"B")
        if min(b,c)==-1:
            print("No")
            break
else:
    print("Yes")
    for j in range(n):
        print(ans[j])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float('inf')
MOD=10**9+7

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

s=[input() for _ in range(n)]

#不可能な場合
if a+b+c==0:
    print("No")
    exit()

result=[]

abc=[a,b,c]
order=[]

def fukasa(order,abc,i):
    #print(order,abc,i)
    global n,s
    if -1 in abc:
        return 0
    if i== n:
        print("Yes")
        for item in order:
            print(item)
        exit()
    else:
        a=abc[0]
        b=abc[1]
        c=abc[2]
        if s[i]=="AB":
            if min([a+1,b-1,c])>min(a-1,b+1,c):
                fukasa(order+["A"],[a+1,b-1,c],i+1)
                fukasa(order+["A"],[a-1,b+1,c],i+1)
            else:
                fukasa(order+["B"],[a-1,b+1,c],i+1)
                fukasa(order+["B"],[a+1,b-1,c],i+1)
                
        if s[i]=="AC":
            if min([a+1,b,c-1])>min(a-1,b,c+1):
                fukasa(order+["A"],[a+1,b,c-1],i+1)
                fukasa(order+["A"],[a-1,b,c+1],i+1)
            else:
                fukasa(order+["C"],[a-1,b,c+1],i+1)
                fukasa(order+["C"],[a+1,b,c-1],i+1)
                
        if s[i]=="BC":
            if min([a,b+1,c-1])>min(a,b-1,c+1):
                fukasa(order+["B"],[a,b+1,c-1],i+1)
                fukasa(order+["B"],[a,b-1,c+1],i+1)
            else:
                fukasa(order+["C"],[a,b-1,c+1],i+1)
                fukasa(order+["C"],[a,b+1,c-1],i+1)



fukasa([],[a,b,c],0)
print("No")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float('inf')
MOD=10**9+7
input=sys.stdin.readline

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

s=[input() for _ in range(n)]

#不可能な場合
if a+b+c==0:
    print("No")
    exit()

result=[]

abc=[a,b,c]
order=[]

def fukasa(order,abc,i):
    #print(order,abc,i)
    global n,s
    if -1 in abc:
        return 0

    if i== n:
        print("Yes")
        for item in order:
            print(item)
        exit()
    else:
        if s[i]=="AB":
            for index,item in enumerate([[1,-1,0],[-1,1,0]]):
                fukasa(order+[s[i][index]],[abc[0]+item[0],abc[1]+item[1],abc[2]+item[2]],i+1)
        if s[i]=="AC":
            for index,item in enumerate([[1,0,-1],[-1,0,1]]):
                fukasa(order+[s[i][index]],[abc[0]+item[0],abc[1]+item[1],abc[2]+item[2]],i+1)
        if s[i]=="BC":
            for index,item in enumerate([[0,1,-1],[0,-1,1]]):
                fukasa(order+[s[i][index]],[abc[0]+item[0],abc[1]+item[1],abc[2]+item[2]],i+1)

fukasa([],[a,b,c],0)
print("No")

Submission status: Wrong Answer

Solution code:









N,A,B,C=map(int,input().split())
arr=[]
for i in range(N):
    s=input()
    if s=="AB":
        if A>=B:
            A-=1
            B+=1
            arr.append("B")
        else:
            A+=1
            B-=1    
            arr.append("A")

    elif s=="AC":
        if A>=C:
            A-=1
            C+=1
            arr.append("C")

        else:
            A+=1
            C-=1    
            arr.append("A")

    else:    
        if B>=C:
            B-=1
            C+=1
            arr.append("C")

        else:
            B+=1
            C-=1    
            arr.append("B")

if A>=0 and B>=0 and C>=0:
    print("Yes")
    for i in arr:
        print(i)
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n,a,b,c=map(int,input().split())
ans=[]
for i in range(n):
    s=input()
    if s=="AB":
        if a>b:
            a-=1
            b+=1
            ans.append("A")
        else:
            a+=1
            b-=1
            ans.append("B")
    elif s=="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:
        ans.clear()
        break
if len(ans)==0:
    print("No")
else:
    print("Yes")
    for i in range(n):
        print(ans[i])

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int,input().split())
l = [[*input()] for _ in range(n)]
l2 = l[1:]+["ABC"]
d = {"A":a, "B":b, "C":c}
isNo = 0
if (a>0)+(b>0)+(c>0)>= 1:
  if d[l[0][0]] == 0 and d[l[0][1]] == 0:
    isNo = 1
  elif a+b+c == 1:
    for s,s2 in zip(l,l2):
      if d[s[0]]<d[s[1]]:
        d[s[1]]+=-1
        d[s[0]]+=1
        if s[0] not in s2:
          isNo = 1
          break
      else:
        d[s[1]]+=1
        d[s[0]]+=-1
        if s[1] not in s2:
          isNo = 1
          break
  else:isNo = 0
else:isNo = 1

if isNo:print("No")
else:
  print("Yes")
  for s,s2 in zip(l,l2):
    if d[s[0]] > d[s[1]]:
      d[s[0]]+=-1
      d[s[1]]+=1
      print(s[1])
    elif d[s[0]] > d[s[1]]:
      d[s[1]]+=-1
      d[s[0]]+=1
      print(s[0])
    else:
      if s[0] in s2:
        d[s[1]]+=-1
        d[s[0]]+=1
        print(s[0])
      else:
        d[s[0]]+=-1
        d[s[1]]+=1
        print(s[1])

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int,input().split())
s = [str(input()) for i in range(n)]
lis = [a,b,c]
ans = ""
for i in range(n-1):
    if lis[ord(s[i][0]) - ord("A")] * lis[ord(s[i][1]) - ord("A")] == 0:
        print("No")
        exit()
    if s[i] == s[i+1]:
        if lis[ord(s[i][0])-ord("A")] == 0:
            ans += s[i][0]
            lis[ord(s[i][0])-ord("A")] += 1
            lis[ord(s[i][1])-ord("A")] -= 1
        else:
            ans += s[i][1]
            lis[ord(s[i][0])-ord("A")] -= 1
            lis[ord(s[i][1])-ord("A")] += 1
    else:
        if s[i] == "AB":
            if s[i+1] == "AC":
                if lis[1] == 0:
                    ans += "B"
                    lis[1] += 1
                    lis[0] -= 1
                else:
                    ans += "A"
                    lis[0] += 1
                    lis[1] -= 1
            else:
                if lis[0] == 0:
                    ans += "A"
                    lis[0] += 1
                    lis[1] -= 1
                else:
                    ans += "B"
                    lis[0] -= 1
                    lis[1] += 1
        elif s[i] == "AC":
            if s[i+1] == "AB":
                if lis[2] == 0:
                    ans += "C"
                    lis[2] += 1
                    lis[0] -= 1
                else:
                    ans += "A"
                    lis[0] += 1
                    lis[2] -= 1
            else:
                if lis[0] == 0:
                    ans += "A"
                    lis[0] += 1
                    lis[2] -= 1
                else:
                    ans += "C"
                    lis[0] -= 1
                    lis[2] += 1
        else:
            if s[i+1] == "AB":
                if lis[2] == 0:
                    ans += "C"
                    lis[2] += 1
                    lis[1] -= 1
                else:
                    ans += "B"
                    lis[2] -= 1
                    lis[1] += 1
            else:
                if lis[1] == 0:
                    ans += "B"
                    lis[1] += 1
                    lis[2] -= 1
                else:
                    ans += "C"
                    lis[2] += 1
                    lis[1] -= 1
if lis[ord(s[-1][0])-ord("A")] == 0:
    if lis[ord(s[-1][1])-ord("A")] == 0:
        print("No")
        exit()
    else:
        ans += s[-1][0]
else:
    ans += s[-1][1]
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 _ in range(n)]

can = 'Yes'
ans = []
val = {'A': a, 'B': b, 'C': c}
if a+b+c == 0:
    can = 'No'
elif a+b+c == 1:
    for ss in s:
        v1, v2 = ss[0], ss[1]
        if val[v1] == val[v2] == 0:
            can = 'No'
            break
        val[v1], val[v2] = val[v2], val[v1]
        ans.append(v1) if val[v1] else ans.append(v2)
else:
    for i in range(n):
        v1, v2 = s[i][0], s[i][1]
        if a+b+c == 2 and val[v1] == val[v2] == 1 and i != n-1 and s[i] != s[i+1]:
            if v1 in s[i+1]:
                val[v1] += 1
                val[v2] -= 1
                ans.append(v1)
            else:
                val[v2] += 1
                val[v1] -= 1
                ans.append(v2)
        else:
            if val[v1] < val[v2]:
                val[v1] += 1
                val[v2] -= 1
                ans.append(v1)
            else:
                val[v2] += 1
                val[v1] -= 1
                ans.append(v2)

print(can)
if can == 'Yes':
    print('\n'.join(ans))

Submission status: Wrong Answer

Solution code:

n,a,b,c=map(int,input().split())
s=[""]*n
abc=dict()
abc["A"]=a
abc["B"]=b
abc["C"]=c

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

t=[""]*n
yn=""
for i in range(n):
    if abc[s[i][0]]==abc[s[i][1]] and i<n-1:
        if s[i][1] in t[i+1]:
            t[i]=s[i][1]
            abc[s[i][0]]-=1
            abc[s[i][1]]+=1
            if abc[s[i][0]]<0:
                yn="No"
                break            
        else:
            t[i]=s[i][0]
            abc[s[i][0]]+=1
            abc[s[i][1]]-=1
            if abc[s[i][1]]<0:
                yn="No"
                break
    elif abc[s[i][0]]>=abc[s[i][1]]:
        t[i]=s[i][1]
        abc[s[i][0]]-=1
        abc[s[i][1]]+=1
        if abc[s[i][0]]<0:
            yn="No"
            break
    else:
        t[i]=s[i][0]
        abc[s[i][0]]+=1
        abc[s[i][1]]-=1
        if abc[s[i][1]]<0:
            yn="No"
            break

#    print(t[i],"a:",abc["A"],"b:",abc["B"],"c:",abc["C"])
            
if yn=="No":
    print("No")
else:
    print("Yes")
    for i in range(n):
        print(t[i])

Submission status: Wrong Answer

Solution code:
n,a,b,c=map(int,input().split())
s_=[input() for i in range(n)]
ans=""
for i in range(n):
    s1,s2=s_[i]
    if s2=="B":
        if a>b:
            a,b=a-1,b+1
            ans+="B"
        else:
            a,b=a+1,b-1
            ans+="A"
        if min(a,b)==-1:
            print("No")
            break
    elif s1=="A":
        if a>c:
            a,c=a-1,c+1
            ans+="C"
        else:
            a,c=a+1,c-1
            ans+="A"
        if min(a,c)==-1:
            print("No")
            break
    else:
        if b>c:
            b,c=b-1,c+1
            ans+="C"
        else:
            b,c=b+1,c-1
            ans+="B"
        if min(b,c)==-1:
            print("No")
            break
else:
    print("Yes")
    for j in range(n):
        print(ans[j])

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n,a,b,c=map(int,input().split())
s_=[input() for i in range(n)]
ans=""
for i in range(n):
    s=s_[i]
    if s is "AB":
        if a>b:
            a,b=a-1,b+1
            ans+="B"
        else:
            a,b=a+1,b-1
            ans+="A"
        if min(a,b)==-1:
            print("No")
            break
    elif s is "AC":
        if a>c:
            a,c=a-1,c+1
            ans+="C"
        else:
            a,c=a+1,c-1
            ans+="A"
        if min(a,c)==-1:
            print("No")
            break
    else:
        if b>c:
            b,c=b-1,c+1
            ans+="C"
        else:
            b,c=b+1,c-1
            ans+="B"
        if min(b,c)==-1:
            print("No")
            break
else:
    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 _ in range(n)]

can = 'Yes'
ans = []
val = {'A': a, 'B': b, 'C': c}
if a+b+c == 0:
    can = 'No'
elif a+b+c == 1:
    for ss in s:
        v1, v2 = ss[0], ss[1]
        if val[v1] == val[v2] == 0:
            can = 'No'
            break
        val[v1], val[v2] = val[v2], val[v1]
        ans.append(v1) if val[v1] else ans.append(v2)
else:
    for i in range(n):
        v1, v2 = s[i][0], s[i][1]
        if val[v1] == val[v2] == 0:
            can = 'No'
            break
        if val[v1] == 0:
            val[v1] += 1
            val[v2] -= 1
            ans.append(v1)
        elif val[v2] == 0:
            val[v2] += 1
            val[v1] -= 1
            ans.append(v2)
        elif a+b+c == 2 and val[v1] == val[v2] == 1 and i != n-1 and s[i] != s[i+1]:
            if v1 in s[i+1]:
                val[v1] += 1
                val[v2] -= 1
                ans.append(v1)
            else:
                val[v2] += 1
                val[v1] -= 1
                ans.append(v2)
        else:
            val[v1] += 1
            val[v2] -= 1
            ans.append(v1)

print(can)
if can == 'Yes':
    print('\n'.join(ans))

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int,input().split())
l = [[*input()] for _ in range(n)]
l2 = l[1:]+["AB"]
d = {"A":a, "B":b, "C":c}
isNo = 0
if (a>0)+(b>0)+(c>0)>= 1:
  if d[l[0][0]] == 0 and d[l[0][1]] == 0:
    isNo = 1
  elif a+b+c == 1:
    for s,s2 in zip(l,l2):
      if d[s[0]]<d[s[1]]:
        if s[0] not in s2:
          isNo = 1
          break
      else:
        if s[1] not in s2:
          isNo = 1
          break
  else:isNo = 0
else:isNo = 1

if isNo:print("No")
else:
  print("Yes")
  for s,s2 in zip(l,l2):
    if d[s[0]] > d[s[1]]:
      d[s[0]]+=-1
      d[s[1]]+=1
      print(s[1])
    elif d[s[0]] > d[s[1]]:
      d[s[1]]+=-1
      d[s[0]]+=1
      print(s[0])
    else:
      if s[0] in s2:
        d[s[1]]+=-1
        d[s[0]]+=1
        print(s[0])
      else:
        d[s[0]]+=-1
        d[s[1]]+=1
        print(s[1])

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n,a,b,c=map(int,input().split())
ans=""
for i in range(n):
    s=input()
    if s is "AB":
        if a>b:
            a,b=a-1,b+1
            ans+="B"
        else:
            a,b=a+1,b-1
            ans+="A"
        if min(a,b)==-1:
            print("No")
            break
    elif s is "AC":
        if a>c:
            a,c=a-1,c+1
            ans+="C"
        else:
            a,c=a+1,c-1
            ans+="A"
        if min(a,c)==-1:
            print("No")
            break
    else:
        if b>c:
            b,c=b-1,c+1
            ans+="C"
        else:
            b,c=b+1,c-1
            ans+="B"
        if min(b,c)==-1:
            print("No")
            break
else:
    print("Yes")
    for i in range(n):
        print(ans[i])

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n,a,b,c=map(int,input().split())
ans=""
for i in range(n):
    s=input()
    if s is "AB":
        if a>b:
            a,b=a-1,b+1
            ans+="B"
        else:
            a,b=a+1,b-1
            ans+="A"
        if min(a,b)==-1:
            print("No")
            break
    elif s is "AC":
        if a>c:
            a,c=a-1,c+1
            ans+="C"
        else:
            a,c=a+1,c-1
            ans+="A"
        if min(a,c)==-1:
            print("No")
            break
    else:
        if b>c:
            b,c=b-1,c+1
            ans+="C"
        else:
            b,c=a+1,c-1
            ans+="B"
        if min(b,c)==-1:
            print("No")
            break
else:
    print("Yes")
    for i in range(n):
        print(ans[i])

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int,input().split())
l = [[*input()] for _ in range(n)]
l2 = l[1:]+["AB"]
d = {"A":a, "B":b, "C":c}
isNo = 0
if (a>0)+(b>0)+(c>0)>= 1:
  if d[l[0][0]] == 0 and d[l[0][1]] == 0:
    isNo = 1
  elif a+b+c == 1:
    for s,s2 in zip(l,l2):
      if d[s[0]]<d[s[1]]:
        if s[0] not in s2:
          isNo = 1
          break
      else:
        if s[1] not in s2:
          isNo = 1
          break
  else:isNo = 0
else:isNo = 1

if isNo:print("No")
else:
  print("Yes")
  for s,s2 in zip(l,l2):
    if d[s[0]] > d[s[1]]:
      d[s[0]]+=-1
      d[s[1]]+=1
      print(s[1])
    elif d[s[0]] > d[s[1]]:
      d[s[1]]+=-1
      d[s[0]]+=1
      print(s[0])
    else:
      if s[0] in s2:
        d[s[1]]+=-1
        d[s[0]]+=1
        print(s[0])
      else:
        d[s[0]]+=-1
        d[s[1]]+=1
        print(s[1])

Submission status: Wrong Answer

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

can = 'Yes'
ans = []
if a+b+c == 0:
    can = 'No'
elif a+b+c == 1:
    for ss in s:
        v1 = ss[0].lower()
        v2 = ss[1].lower()
        if eval(v1) == eval(v2) == 0:
            can = 'No'
            break
        exec(f'{v1}, {v2} = {v2}, {v1}')
        ans.append(v1.upper()) if eval(v1) else ans.append(v2.upper())
else:
    for i in range(n):
        v1 = s[i][0].lower()
        v2 = s[i][1].lower()
        if eval(v1) == eval(v2) == 0:
            can = 'No'
            break
        if eval(v1) == 0:
            exec(f'{v1} += 1')
            exec(f'{v2} -= 1')
            ans.append(v1.upper())
        elif eval(v2) == 0:
            exec(f'{v2} += 1')
            exec(f'{v1} -= 1')
            ans.append(v2.upper())
        elif a+b+c == 2 and eval(v1) == eval(v2) == 1 and i != n-1 and s[i] != s[i+1]:
            if v1.upper() in s[i+1]:
                exec(f'{v1} += 1')
                exec(f'{v2} -= 1')
                ans.append(v1.upper())
            else:
                exec(f'{v2} += 1')
                exec(f'{v1} -= 1')
                ans.append(v2.upper())
        else:
            exec(f'{v1} += 1')
            exec(f'{v2} -= 1')
            ans.append(v1.upper())

print(can)
if can == 'Yes':
    print('\n'.join(ans))

Submission status: Wrong Answer

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

v = {
  'A': a,
  'B': b,
  'C': c
}
ss = []
for _ in range(n):
  ss.append(input())

history = [] 
flag = True
  
for i in range(n):
  
  s = ss[i]
  
  if v[s[0]] == 0 and v[s[1]] == 0:
    flag = False
    break
  elif v[s[0]] > v[s[1]]:
    history.append(s[1])
    v[s[0]] -= 1
    v[s[1]] += 1
  elif v[s[0]] < v[s[1]]:
    history.append(ss[0])
    v[s[0]] += 1
    v[s[1]] -= 1
  elif i == n-1:
    history.append(s[0])
    v[s[0]] += 1
    v[s[1]] -= 1
  elif s[0] in ss[i+1]:
    history.append(s[0])
    v[s[0]] += 1
    v[s[1]] -= 1
  else:
    history.append(s[1])
    v[s[0]] -= 1
    v[s[1]] += 1
if flag:
  print("Yes")
  print('\n'.join(history))
else:
  print("No")