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())
d = {'A':a, 'B':b, 'C':c}
cnt = 0
ans = []

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


for x in s:
    if x == 'AB':
        if d['A'] > d['B']:
            if (d['A'] - 1 >= 0):
                if (d['B'] + 1 >= 0):
                    cnt += 1
                    ans.append('B')
                    d['A'] -= 1
                    #print(d['A'])
                    d['B'] += 1
                    #print(d['B'])
        elif d['A'] <= d['B']:
            if (d['A'] + 1 >= 0):
                if (d['B'] - 1 >= 0):
                    cnt += 1
                    ans.append('A')
                    d['A'] += 1
                    #print(d['A'])
                    d['B'] -= 1
                    #print(d['B'])
    elif x == 'AC':
        if d['A'] > d['C']:
            if (d['A'] - 1 >= 0):
                if (d['C'] + 1 >= 0):
                    cnt += 1
                    ans.append('C')
                    d['A'] -= 1
                    #print(d['A'])
                    d['C'] += 1
                    #print(d['C'])
        elif d['A'] <= d['C']:
            if (d['A'] + 1 >= 0):
                if (d['C'] - 1 >= 0):
                    cnt += 1
                    ans.append('A')
                    d['A'] += 1
                    #print(d['A'])
                    d['C'] -= 1
                    #print(d['C'])
    else:
        if d['B'] > d['C']:
            if (d['B'] - 1 >= 0):
                if (d['C'] + 1 >= 0):
                    cnt += 1
                    ans.append('C')
                    d['B'] -= 1
                    #print(d['B'])
                    d['C'] += 1
                    #print(d['C'])
        elif d['B'] <= d['C']:
            if (d['B'] + 1 >= 0):
                if (d['C'] - 1 >= 0):
                    cnt += 1
                    ans.append('B')
                    d['B'] += 1
                    #print(d['B'])
                    d['C'] -= 1
                    #print(d['C'])
        

if cnt == n:
    print('Yes')
    for y in ans:
        print(y)
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n, a, b, c = map(int, input().split())
d = {'A':a, 'B':b, 'C':c}
cnt = 0
ans = []

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


for x in s:
    if x == 'AB':
        if d['A'] > d['B']:
            if (d['A'] - 1 >= 0) and (d['B'] + 1 >= 0):
                cnt += 1
                ans.append('B')
        elif d['A'] <= d['B']:
            if (d['A'] + 1 >= 0) and (d['B'] - 1 >= 0):
                cnt += 1
                ans.append('A')
    elif x == 'AC':
        if d['A'] > d['C']:
            if (d['A'] - 1 >= 0) and (d['C'] + 1 >= 0):
                cnt += 1
                ans.append('C')
        elif d['A'] <= d['C']:
            if (d['A'] + 1 >= 0) and (d['C'] - 1 >= 0):
                cnt += 1
                ans.append('A')
    else:
        if d['B'] > d['C']:
            if (d['B'] - 1 >= 0) and (d['C'] + 1 >= 0):
                cnt += 1
                ans.append('C')
        elif d['B'] <= d['C']:
            if (d['B'] + 1 >= 0) and (d['C'] - 1 >= 0):
                cnt += 1
                ans.append('B')
        

if cnt == n:
    print('Yes')
    for y in ans:
        print(y)
else:
    print('No')

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    nabc = input()
    nabc = nabc.split()
    n = int(nabc[0])
    a = int(nabc[1])
    b = int(nabc[2])
    c = int(nabc[3])
    abc = a+b+c
    user_ins = [0]*n
    for i in range(n):
        user_ins[i] = input()
    first = user_ins[0][0]
    second = user_ins[0][1]
    flag = True

    if abc == 0:
        flag = False
    else:
        if (first == 'A' and second == 'B' and a==0 and b==0) or (first == 'B' and second == 'C' and b==0 and c==0) or (first == 'A' and second == 'C' and c==0 and a==0):
            flag = False
        else:    
            ans_list = [0]*n
            for i in range(n):
                user_in = user_ins[i]
                if user_in == "AB":
                    if a>b:
                        ans_list[i] = 'B'
                        a -= 1
                        b += 1
                    else:
                        ans_list[i] = 'A'
                        a += 1
                        b -= 1
                elif user_in == "BC":
                    if b>c:
                        ans_list[i] = 'C'
                        b -= 1
                        c += 1
                    else:
                        ans_list[i] = 'B'
                        b += 1
                        c -= 1
                elif user_in == "AC":
                    if a>c:
                        ans_list[i] = 'C'
                        a -= 1
                        c += 1
                    else:
                        ans_list[i] = 'A'
                        a += 1
                        c -= 1

                if a<0 or b<0 or c<0:
                    flag = False
                    break

    if flag:
        print("Yes")
        for i in range(n):
            print(ans_list[i])
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    nabc = input()
    nabc = nabc.split()
    n = int(nabc[0])
    a = int(nabc[1])
    b = int(nabc[2])
    c = int(nabc[3])
    user_ins = [0]*n
    for i in range(n):
        user_ins[i] = input()

    flag = True
    ans_list = [0]*n
    for i in range(n):
        user_in = user_ins[i]
        if user_in == "AB":
            if a>b:
                ans_list[i] = 'B'
                a -= 1
                b += 1
            else:
                ans_list[i] = 'A'
                a += 1
                b -= 1
        elif user_in == "BC":
            if b>c:
                ans_list[i] = 'C'
                b -= 1
                c += 1
            else:
                ans_list[i] = 'B'
                b += 1
                c -= 1
        elif user_in == "AC":
            if a>c:
                ans_list[i] = 'C'
                a -= 1
                c += 1
            else:
                ans_list[i] = 'A'
                a += 1
                c -= 1

        if a<0 or b<0 or c<0:
            flag = False
            break

    if flag:
        print("Yes")
        for i in range(n):
            print(ans_list[i])
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    nabc = input()
    nabc = nabc.split()
    n = int(nabc[0])
    a = int(nabc[1])
    b = int(nabc[2])
    c = int(nabc[3])

    flag = True
    ans_list = [0]*n
    for i in range(n):
        user_in = input()
        if user_in == "AB":
            if a>b:
                ans_list[i] = 'B'
                a -= 1
                b += 1
            else:
                ans_list[i] = 'A'
                a += 1
                b -= 1
        elif user_in == "BC":
            if b>c:
                ans_list[i] = 'C'
                b -= 1
                c += 1
            else:
                ans_list[i] = 'B'
                b += 1
                c -= 1
        elif user_in == "AC":
            if a>c:
                ans_list[i] = 'C'
                a -= 1
                c += 1
            else:
                ans_list[i] = 'A'
                a += 1
                c -= 1

        if a<0 or b<0 or c<0:
            flag = False
            break

    if flag:
        print("Yes")
        for i in range(n):
            print(ans_list[i])
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    nabc = input()
    nabc = nabc.split()
    n = int(nabc[0])
    a = int(nabc[1])
    b = int(nabc[2])
    c = int(nabc[3])

    abc = a+b+c

    flag = True
    if abc == 0 or abc >= 2:
        flag = False
    else:
        ans_list = []
        for i in range(n):
            user_in = input()
            if user_in == "AB":
                if a>b:
                    ans_list.append('B')
                    a -= 1
                    b += 1
                else:
                    ans_list.append('A')
                    a += 1
                    b -= 1
            elif user_in == "BC":
                if b>c:
                    ans_list.append('C')
                    b -= 1
                    c += 1
                else:
                    ans_list.append('B')
                    b += 1
                    c -= 1
            elif user_in == "AC":
                if a>c:
                    ans_list.append('C')
                    a -= 1
                    c += 1
                else:
                    ans_list.append('A')
                    a += 1
                    c -= 1

            if a<0 or b<0 or c<0:
                flag = False
                break

    if flag:
        print("Yes")
        for i in range(len(ans_list)):
            print(ans_list[i])
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    nabc = input()
    nabc = nabc.split()
    n = int(nabc[0])
    a = int(nabc[1])
    b = int(nabc[2])
    c = int(nabc[3])

    flag = True
    ans_list = []
    for i in range(n):
        user_in = input()
        if user_in == "AB":
            if a>b:
                ans_list.append('B')
                a -= 1
                b += 1
            else:
                ans_list.append('A')
                a += 1
                b -= 1
        elif user_in == "BC":
            if b>c:
                ans_list.append('C')
                b -= 1
                c += 1
            else:
                ans_list.append('B')
                b += 1
                c -= 1
        elif user_in == "AC":
            if a>c:
                ans_list.append('C')
                a -= 1
                c += 1
            else:
                ans_list.append('A')
                a += 1
                c -= 1

        if a<0 or b<0 or c<0:
            flag = False
            break

    if flag:
        print("Yes")
        for i in range(len(ans_list)):
            print(ans_list[i])
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    nabc = input()
    nabc = nabc.split()
    n = int(nabc[0])
    a = int(nabc[1])
    b = int(nabc[2])
    c = int(nabc[3])

    flag = True
    ans_list = []
    for i in range(n):
        user_in = input()
        if user_in == "AB":
            if a>=b:
                ans_list.append('B')
                a -= 1
                b += 1
            else:
                ans_list.append('A')
                a += 1
                b -= 1
        elif user_in == "BC":
            if b>=c:
                ans_list.append('C')
                b -= 1
                c += 1
            else:
                ans_list.append('B')
                b += 1
                c -= 1
        elif user_in == "AC":
            if a>=c:
                ans_list.append('C')
                a -= 1
                c += 1
            else:
                ans_list.append('A')
                a += 1
                c -= 1

        if a<0 or b<0 or c<0:
            flag = False
            break

    if flag:
        print("Yes")
        for i in range(len(ans_list)):
            print(ans_list[i])
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
N, A, B, C = [int(i) for i in input().split()]

ans = list()
l = list()

for i in range(N):
    l.append(input())

if len(ans) > 0:
    print('Yes')
    for x in reversed(ans):
        print(x)
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n, a, b, c = map(int, input().split())
q = [input() for i in range(n)]
ab, ac, bc = "AB", "AC", "BC"
ans = []
for i in range(n):
  
  if((q[i] == ab and a == b == 0)
  or (q[i] == ac and a == c == 0) 
  or (q[i] == bc and b == c == 0)):
      print("No")
      exit()
      
  elif(q[i] == ab and [a, b, c] == [1, 1, 0] and i != n - 1):
    if q[i+1] == ac: 
      a, b = a+1, b-1
      ans.append("A")
    else:
      a, b = a-1, b+1
      ans.append("B")     
      
  elif(q[i] == ac and [a, b, c] == [1, 0, 1] and i != n - 1):
    if q[i] == ab:
      a, c = a+1, c-1
      ans.append("A")
    else:
      a, c = a-1, c+1
      ans.append("C")
      
  elif(q[i] == bc and [a, b, c] == [0, 1, 1] and i != n - 1):
    if q[i] == ab:
      b, c = b+1, c-1
      ans.append("B")
    else:
      b, c = b-1, c+1
      ans.append("C")
      
  elif q[i] == ab:
    if a > b:
      a, b = a-1, b+1
      ans.append("B")
    else:
      a, b = a+1, b-1
      ans.append("A")
      
  elif q[i] == ac:
    if a > c:
      a, c = a-1, c+1
      ans.append("C")
    else:
      a, c = a+1, c-1
      ans.append("A")
      
  elif q[i] == bc:
    if b > c:
      b, c = b-1, c+1
      ans.append("C")
    else:
      b, c = b+1, c-1
      ans.append("B")
      
print("Yes")
for i in range(n):
  print(ans[i])

Submission status: Wrong Answer

Solution code:
n, a, b, c = map(int, input().split())
q = [input() for i in range(n)]
ab, ac, bc = "AB", "AC", "BC"
ans = []
for i in range(n):
  
  if((q[i] == ab and a == b == 0)
  or (q[i] == ac and a == c == 0) 
  or (q[i] == bc and b == c == 0)):
      print("No")
      exit()
      
  elif(q[i] == ab and [a, b, c] == [1, 1, 0]):
    if q[i] == ac: 
      a, b = a+1, b-1
      ans.append("A")
    else:
      a, b = a-1, b+1
      ans.append("B")     
      
  elif(q[i] == ac and [a, b, c] == [1, 0, 1]):
    if q[i] == ab:
      a, c = a+1, c-1
      ans.append("A")
    else:
      a, c = a-1, c+1
      ans.append("C")
      
  elif(q[i] == bc and [a, b, c] == [0, 1, 1]):
    if q[i] == ab:
      b, c = b+1, c-1
      ans.append("B")
    else:
      b, c = b-1, c+1
      ans.append("C")
      
  elif q[i] == ab:
    if a > b:
      a, b = a-1, b+1
      ans.append("B")
    else:
      a, b = a+1, b-1
      ans.append("A")
      
  elif q[i] == ac:
    if a > c:
      a, c = a-1, c+1
      ans.append("C")
    else:
      a, c = a+1, c-1
      ans.append("A")
      
  elif q[i] == bc:
    if b > c:
      b, c = b-1, c+1
      ans.append("C")
    else:
      b, c = b+1, c-1
      ans.append("B")
      
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)]

ABC = [A, B, C]
dic = {"A": 0, "B": 1, "C": 2}
cid = {0: "A", 1: "B", 2: "C"}

def prt(a):
    for aa in a:
        print(aa)

su = A + B + C
answer = []
if su == 1:
    for s in S:
        s1, s2 = s[0], s[1]
        i1, i2 = dic[s1], dic[s2]
        if ABC[i1] == ABC[i2] == 0:
            print("No")
            exit()
        else:
            if ABC[i1] > ABC[i2]:
                ABC[i1] -= 1
                ABC[i2] += 1
                answer.append(cid[i2])
            else:
                ABC[i1] += 1
                ABC[i2] -= 1
                answer.append(cid[i1])
elif su == 2:
    for i in range(N):
        s = S[i]
        s1, s2 = s[0], s[1]
        i1, i2 = dic[s1], dic[s2]
        if ABC[i1] == ABC[i2] == 0:
            print("No")
            exit()
        else:
            if ABC[i1] > ABC[i2]:
                ABC[i1] -= 1
                ABC[i2] += 1
                answer.append(cid[i2])
            elif ABC[i1] < ABC[i2]:
                ABC[i1] += 1
                ABC[i2] -= 1
                answer.append(cid[i1])
            else:
                if i < N - 1:
                    if "A" in S[i] and "A" in S[i + 1]:
                       ABC[0] += 1
                       ABC[i2] -= 1
                       answer.append("A")
                    elif "B" in S[i] and "B" in S[i + 1]:
                        ABC[1] += 1
                        if i1 == 1:
                            ABC[i2] -= 1
                        else:
                            ABC[i1] -= 1
                        answer.append("B")
                    elif "C" in S[i] and "C" in S[i + 1]:
                        ABC[2] += 1
                        ABC[i1] -= 1
                        answer.append("C")
else:
    for s in S:
        s1, s2 = s[0], s[1]
        i1, i2 = dic[s1], dic[s2]
        if ABC[i1] == ABC[i2] == 0:
            print("No")
            exit()
        s1, s2 = s[0], s[1]
        i1, i2 = dic[s1], dic[s2]
        if ABC[i1] > ABC[i2]:
            ABC[i1] -= 1
            ABC[i2] += 1
            answer.append(cid[i2])
        else:
            ABC[i1] += 1
            ABC[i2] -= 1
            answer.append(cid[i1])
print("Yes")
prt(answer)

Submission status: Wrong Answer

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

ABC = [A, B, C]
dic = {"A": 0, "B": 1, "C": 2}
cid = {0: "A", 1: "B", 2: "C"}

def prt(a):
    for aa in a:
        print(aa)

su = A + B + C
answer = []
if su == 1:
    for s in S:
        s1, s2 = s[0], s[1]
        i1, i2 = dic[s1], dic[s2]
        if ABC[i1] == ABC[i2] == 0:
            print("No")
            exit()
        else:
            if ABC[i1] > ABC[i2]:
                ABC[i1] -= 1
                ABC[i2] += 1
                answer.append(cid[i2])
            else:
                ABC[i1] += 1
                ABC[i2] -= 1
                answer.append(cid[i1])
elif su == 2:
    for i in range(N):
        s = S[i]
        s1, s2 = s[0], s[1]
        i1, i2 = dic[s1], dic[s2]
        if ABC[i1] == ABC[i2] == 0:
            print("No")
            exit()
        else:
            if ABC[i1] > ABC[i2]:
                ABC[i1] -= 1
                ABC[i2] += 1
                answer.append(cid[i2])
            elif ABC[i1] < ABC[i2]:
                ABC[i1] += 1
                ABC[i2] -= 1
                answer.append(cid[i1])
            else:
                if i < N - 1:
                    if "A" in S[i] and "A" in S[i + 1]:
                       ABC[0] += 1
                       ABC[i2] -= 1
                       answer.append("A")
                    elif "B" in S[i] and "B" in S[i + 1]:
                       ABC[1] += 1
                       if i1 == 1:
                           ABC[i2] -= 1
                       else:
                           ABC[i1] -= 1
                       answer.append("B")
                    elif "C" in S[i] and "C" in S[i + 1]:
                       ABC[2] += 1
                       ABC[i1] -= 1
                       answer.append("C")
else:
    for s in S:
        s1, s2 = s[0], s[1]
        i1, i2 = dic[s1], dic[s2]
        if ABC[i1] > ABC[i2]:
            ABC[i1] -= 1
            ABC[i2] += 1
            answer.append(cid[i2])
        else:
            ABC[i1] += 1
            ABC[i2] -= 1
            answer.append(cid[i1])
print("Yes")
prt(answer)

Submission status: Wrong Answer

Solution code:
import sys
#input = sys.stdin.buffer.readline

def main():
    N,A,B,C = map(int,input().split())
    use = [A,B,C]
    conv = ["A","B","C"]
    
    l = []
    for _ in range(N):
        s = input()
        if s == "AB":
            s = 0
        elif s == "BC":
            s = 1
        else:
            s = 2
        l.append(s)
        
    ans = []
        
    for i in range(N):
        num = l[i]
        if use[num]+use[(num+1)%3] == 0:
            print("No")
            exit()
        elif use[num] == use[(num+1)%3] == 1:
            if i == N-1:
                ans.append(conv[num])
                use[num] += 1
                use[(num+1)%3] -= 1
            else:
                _num = l[i+1]
                if num == _num:
                    ans.append(conv[num])
                    use[num] += 1
                    use[(num+1)%3] -= 1
                else:
                    if (_num+3-num)%3 == 1:
                        ans.append(conv[_num])
                        use[_num] += 1
                        use[(_num+1)%3] -= 1
                    else:
                        ans.append(conv[num])
                        use[num] += 1
                        use[(num+1)%3] -= 1
        else:
            if use[num] >= use[(num+1)%3]:
                ans.append(conv[(num+1)%3])
                use[num] -= 1
                use[(num+1)%3] += 1
            else:
                ans.append(conv[num])
                use[num] += 1
                use[(num+1)%3] -= 1

    print("Yes")
    for st in ans:
        print(st)
    
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
def update_vrs(vrs, idx, s):
    if idx == 0:
        vrs[s[0]] += 1
        vrs[s[1]] -= 1
    elif idx == 1:
        vrs[s[0]] -= 1
        vrs[s[1]] += 1
    else:
        raise ValueError()


def process1(vrs, lst_s):
    selects = []

    for s in lst_s:
        if vrs[s[0]] == 1:
            selects.append(s[1])
            update_vrs(vrs, 1, s)
        elif vrs[s[1]] == 1:
            selects.append(s[0])
            update_vrs(vrs, 0, s)
        else:
            return False, None
    return True, selects


def process2(vrs, lst_s):
    selects = []
    for i, s in enumerate(lst_s):
        if vrs[s[0]] == 0 and vrs[s[1]] == 0:
            return False, None
        elif vrs[s[0]] == 0:
            selects.append(s[1])
            update_vrs(vrs, 1, s)
        elif vrs[s[1]] == 0:
            selects.append(s[1])
            update_vrs(vrs, 0, s)
        else:
            if i == len(lst_s) - 1:
                selects.append(s[0])
            else:
                next_s = lst_s[i + 1]
                if s[0] in next_s:
                    selects.append(s[0])
                    update_vrs(vrs, 0, s)
                else:
                    selects.append(s[1])
                    update_vrs(vrs, 1, s)
    return True, selects


def main():
    vrs = {}
    n, vrs['A'], vrs['B'], vrs['C'] = [int(v) for v in input().split(' ')]
    lst_s = []
    for _ in range(n):
        lst_s.append(input().strip())

    sum_abc = vrs['A'] + vrs['B'] + vrs['C']

    if sum_abc == 0:
        ans = False
    elif sum_abc == 1:
        ans, selects = process1(vrs, lst_s)
    else:
        ans, selects = process2(vrs, lst_s)

    if ans is True:
        print('Yes')
        for s in selects:
            print(s)
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, a, b, c = list(map(int, input().split()))
s = [list(input()) for _ in range(n)]
d = {"A": a, "B": b, "C": c}
ans = []

def calc(add, sub):
    d[add] += 1
    d[sub] -= 1
    ans.append(add)
    
for i, [j, k] in enumerate(s):
    if d[j] == 0 and d[k] == 0:
        print("No")
        break
    elif d[j] > d[k]:
        calc(k, j)
    elif d[j] < d[k]:
        calc(j, k)
    elif i + 1 != n:
        if j == "A":
            if s[i + 1][1] == "C":
                calc(k, j)
            else:
                calc(j, k)        
        else:
            if s[i + 1] == ["A", "C"]:
                calc(k, j)
            else:
                calc(j, k)
    else:
        calc(j, k)
else:
    print("Yes")
    for i in ans:
        print(i)

Submission status: Wrong Answer

Solution code:
print("Yes")
print("B")
print("C")

Submission status: Wrong Answer

Solution code:
print("Yes")
print("A")
print("C")

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int,input().split())
m = {}
if a > 0:
    m['AB'] = 'B'
    m['AC'] = 'C'
elif a == 0:
    if b > 0:
        m['AB'] = 'A'
    if c > 0:
        m['AC'] = 'A'
if b > 0:
    m['BC'] = 'C'
elif b == 0:
    if c > 0:
        m['BC'] = 'B'
r = []
f = True
for i in range(n):
    s = input()
    if s in m:
        r.append(m[s])
    else:
        f = False
        print('No')
        break
if f:
    print('Yes')
    for s in r:
        print(s)

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int,input().split())
m = {}
# if a > 0:
#     m["AB"] = "B"
#     m["AC"] = "C"
# elif a == 0:
#     if b > 0:
#         m["AB"] = "A"
#     if c > 0:
#         m["AC"] = "A"
# if b > 0:
#     m["BC"] = "C"
# elif b == 0:
#     if c > 0:
#         m["BC"] = "B"
if c > 0:
    m["AC"] = "A"
    m["BC"] = "B"
elif c == 0:
    if b > 0:
        m["BC"] = "C"
    if a > 0:
        m["AC"] = "C"
if b > 0:
    m["AB"] = "A"
elif b == 0:
    if a > 0:
        m["AB"] = "B"
r = []
f = True
for i in range(n):
    s = input()
    if s in m:
        r.append(m[s])
    else:
        f = False
        print("No")
        break
if f:
    print("Yes")
    for s in r:
        print(s)

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int,input().split())
m = {}
if a > 0:
    m["AB"] = "B"
    m["AC"] = "C"
elif a == 0:
    if b > 0:
        m["AB"] = "A"
    if c > 0:
        m["AC"] = "A"
if b > 0:
    m["BC"] = "C"
elif b == 0:
    if c > 0:
        m["BC"] = "B"
r = []
f = True
for i in range(n):
    s = input()
    if s in m:
        r.append(m[s])
    else:
        f = False
        print("No")
        break
if f:
    print("Yes")
    for s in r:
        print(s)

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int,input().split())
m = {}
if a > 0:
    m["AB"] = "B"
    m["AC"] = "C"
elif a == 0:
    if b > 0:
        m["AB"] = "A"
    if c > 0:
        m["AC"] = "A"
if b > 0:
    m["BC"] = "C"
elif b == 0:
    if c > 0:
        m["BC"] = "B"
r = []
f = True
for i in range(n):
    s = input()
    if not f:
        continue
    if s in m:
        r.append(m[s])
    else:
        f = False
if f:
    print("Yes")
    for s in r:
        print(s)
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int,input().split())
m = {}
if a > 0:
    if b >= -1:
        m["AB"] = "B"
    if c >= -1:
        m["AC"] = "C"
elif a >= -1:
    if b > 0:
        m["AB"] = "A"
    if c > 0:
        m["AC"] = "A"
if b > 0:
    if c >= -1:
        m["BC"] = "C"
elif b >= -1:
    if c > 0:
        m["BC"] = "B"
r = []
f = True
for i in range(n):
    s = input()
    if not f:
        continue
    if s in m:
        r.append(m[s])
    else:
        f = False
if f:
    print("Yes")
    for s in r:
        print(s)
else:
    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int,input().split())
m = {}
if a > 0:
    if b >= -1:
        m["AB"] = "B"
    if c >= -1:
        m["AC"] = "C"
if a == 0:
    if b > 0:
        m["AB"] = "A"
    if c > 0:
        m["AC"] = "A"
if b > 0:
    if c >= -1:
        m["BC"] = "C"
if b == 0:
    if c > 0:
        m["BC"] = "B"
r = []
f = True
for i in range(n):
    s = input()
    if s in m:
        r.append(m[s])
    else:
        print("No")
        f = False
        break
if f:
    print("Yes")
    for s in r:
        print(s)

Submission status: Wrong Answer

Solution code:
n,a,b,c = map(int,input().split())
m = {}
if a > 0:
    if b >= 0:
        m["AB"] = "B"
    if c >= 0:
        m["AC"] = "C"
if a == 0:
    if b > 0:
        m["AB"] = "A"
    if c > 0:
        m["AC"] = "A"
if b > 0:
    if c >= 0:
        m["BC"] = "C"
if b == 0:
    if c > 0:
        m["BC"] = "B"
r = []
f = True
for i in range(n):
    s = input()
    if s in m:
        r.append(m[s])
    else:
        print("No")
        f = False
        break
if f:
    print("Yes")
    for s in r:
        print(s)

Submission status: Wrong Answer

Solution code:
import sys
n,a,b,c = map(int,input().split())
m = {}
if a > 0:
    if b >= 0:
        m["AB"] = "A"
    if c >= 0:
        m["AC"] = "A"
if a == 0:
    if b > 0:
        m["AB"] = "B"
    if c > 0:
        m["AC"] = "C"
if b > 0:
    if c >= 0:
        m["BC"] = "B"
if b == 0:
    if c > 0:
        m["BC"] = "C"
r = []
f = True
for i in range(n):
    s = input()
    if s in m:
        r.append(m[s])
    else:
        print("No")
        f = False
        break
if f:
    print("Yes")
    for s in r:
        print(s)

Submission status: Wrong Answer

Solution code:
n, a, b, c = list(map(int, input().split()))
s = [list(input()) for _ in range(n)]
d = {"A": a, "B": b, "C": c}
ans = []
su = a + b + c

def calc(add, sub):
    d[add] += 1
    d[sub] -= 1
    ans.append(add)
    
def simple(x, y):
    if d[x] > d[y]:
        calc(y, x)
    else:
        calc(x, y)
        
def disp():
    print("Yes")
    for i in ans:
        print(i)
        
if su == 0:
    print("No")
elif su == 1:
    for i, j in s:
        if d[i] == 0 and d[j] == 0:
            print("No")
            break
        else:
            simple(i, j)
    else:
        disp()
else:
    for i, [j, k] in enumerate(s):
        if d[j] == 0 and d[k] == 0:
            print("No")
            break
        elif su == 2 and d[j] == 1 and d[k] == 1 and i + 1 != n:
            if [j, k] == s[i + 1]:
                simple(j, k)
            elif s[i + 1][0] == j:
                calc(j, k)
            else:
                calc(k, j)
        else:
            simple(j, k)
    else:
        disp()