Buggy python submission (verdict: Runtime Error):
n,a,b,c = map(int,input().split())
ss = [input()for i in range(n)]
ok = True
ans = []
for i in range(n):
    s = ss[i]
    if s == 'AB':
        if a == 1 and b == 1 and c == 0:
            if  i+1 < n and ss[i+1] == 'AC':
                ans.append('A')
                a += 1
                b -= 1
                continue
            if ss[i+1] == 'BC':
                ans.append('B')
                b += 1
                a -= 1
                continue
            
            
        if a == 0 and b == 0:
            ok = False
            break
        
        if a > b:
            b +=1
            a -= 1
            ans.append('B')
        else:
            b -= 1
            a += 1
            ans.append('A')
            
    elif s == 'AC':
        if a == 1 and b == 0 and c == 1:
            if  i+1 < n and ss[i+1] == 'AB':
                ans.append('A')
                a += 1
                c -= 1
                continue
            if ss[i+1] == 'BC':
                ans.append('C')
                c += 1
                a -= 1
                continue
            
        if a == 0 and c == 0:
            ok = False
            break
        
        if a > c:
            c +=1
            a -= 1
            ans.append('C')
        else:
            c -= 1
            a += 1
            ans.append('A')
            
        
    else:
        if a == 0 and b == 1 and c == 1:
            if i+1 < n and  ss[i+1] == 'AC':
                ans.append('C')
                c += 1
                b -= 1
                continue
            if ss[i+1] == 'AB':
                ans.append('B')
                b += 1
                c -= 1
                continue
        if c == 0 and b == 0:
            ok = False
            break
        
        if c > b:
            b +=1
            c -= 1
            ans.append('B')
        else:
            b -= 1
            c += 1
            ans.append('C')
if ok:
    print('Yes')
    for x in ans:
        print(x)
else:print('No')


Fixed submission:
n,a,b,c = map(int,input().split())
ss = [input()for i in range(n)]
ok = True
ans = []
for i in range(n):
    s = ss[i]
    if s == 'AB':
        if a == 1 and b == 1 and c == 0:
            if  i+1 < n and ss[i+1] == 'AC':
                ans.append('A')
                a += 1
                b -= 1
                continue
            if i + 1 < n and ss[i+1] == 'BC':
                ans.append('B')
                b += 1
                a -= 1
                continue
            
            
        if a == 0 and b == 0:
            ok = False
            break
        
        if a > b:
            b +=1
            a -= 1
            ans.append('B')
        else:
            b -= 1
            a += 1
            ans.append('A')
            
    elif s == 'AC':
        if a == 1 and b == 0 and c == 1:
            if  i+1 < n and ss[i+1] == 'AB':
                ans.append('A')
                a += 1
                c -= 1
                continue
            if i + 1 < n and ss[i+1] == 'BC':
                ans.append('C')
                c += 1
                a -= 1
                continue
            
        if a == 0 and c == 0:
            ok = False
            break
        
        if a > c:
            c +=1
            a -= 1
            ans.append('C')
        else:
            c -= 1
            a += 1
            ans.append('A')
            
        
    else:
        if a == 0 and b == 1 and c == 1:
            if i+1 < n and  ss[i+1] == 'AC':
                ans.append('C')
                c += 1
                b -= 1
                continue
            if  i+ 1 < n and ss[i+1] == 'AB':
                ans.append('B')
                b += 1
                c -= 1
                continue
        if c == 0 and b == 0:
            ok = False
            break
        
        if c > b:
            b +=1
            c -= 1
            ans.append('B')
        else:
            b -= 1
            c += 1
            ans.append('C')
if ok:
    print('Yes')
    for x in ans:
        print(x)
else:print('No')

Buggy python submission (verdict: Runtime Error):
n,a,b,c = map(int,input().split())
ss = [input()for i in range(n)]
ok = True
ans = []
for i in range(n):
    s = ss[i]
    if s == 'AB':
        if a == 1 and b == 1 and c == 0:
            if  ss[i+1] == 'AC':
                ans.append('A')
                a += 1
                b -= 1
                continue
            if ss[i+1] == 'BC':
                ans.append('B')
                b += 1
                a -= 1
                continue
            
            
        if a == 0 and b == 0:
            ok = False
            break
        
        if a > b:
            b +=1
            a -= 1
            ans.append('B')
        else:
            b -= 1
            a += 1
            ans.append('A')
            
    elif s == 'AC':
        if a == 1 and b == 0 and c == 1:
            if  ss[i+1] == 'AB':
                ans.append('A')
                a += 1
                c -= 1
                continue
            if ss[i+1] == 'BC':
                ans.append('C')
                c += 1
                a -= 1
                continue
            
        if a == 0 and c == 0:
            ok = False
            break
        
        if a > c:
            c +=1
            a -= 1
            ans.append('C')
        else:
            c -= 1
            a += 1
            ans.append('A')
            
        
    else:
        if a == 0 and b == 1 and c == 1:
            if  ss[i+1] == 'AC':
                ans.append('C')
                c += 1
                b -= 1
                continue
            if ss[i+1] == 'AB':
                ans.append('B')
                b += 1
                c -= 1
                continue
        if c == 0 and b == 0:
            ok = False
            break
        
        if c > b:
            b +=1
            c -= 1
            ans.append('B')
        else:
            b -= 1
            c += 1
            ans.append('C')
if ok:
    print('Yes')
    for x in ans:
        print(x)
else:print('No')


Fixed submission:
n,a,b,c = map(int,input().split())
ss = [input()for i in range(n)]
ok = True
ans = []
for i in range(n):
    s = ss[i]
    if s == 'AB':
        if a == 1 and b == 1 and c == 0:
            if  i+1 < n and ss[i+1] == 'AC':
                ans.append('A')
                a += 1
                b -= 1
                continue
            if i + 1 < n and ss[i+1] == 'BC':
                ans.append('B')
                b += 1
                a -= 1
                continue
            
            
        if a == 0 and b == 0:
            ok = False
            break
        
        if a > b:
            b +=1
            a -= 1
            ans.append('B')
        else:
            b -= 1
            a += 1
            ans.append('A')
            
    elif s == 'AC':
        if a == 1 and b == 0 and c == 1:
            if  i+1 < n and ss[i+1] == 'AB':
                ans.append('A')
                a += 1
                c -= 1
                continue
            if i + 1 < n and ss[i+1] == 'BC':
                ans.append('C')
                c += 1
                a -= 1
                continue
            
        if a == 0 and c == 0:
            ok = False
            break
        
        if a > c:
            c +=1
            a -= 1
            ans.append('C')
        else:
            c -= 1
            a += 1
            ans.append('A')
            
        
    else:
        if a == 0 and b == 1 and c == 1:
            if i+1 < n and  ss[i+1] == 'AC':
                ans.append('C')
                c += 1
                b -= 1
                continue
            if  i+ 1 < n and ss[i+1] == 'AB':
                ans.append('B')
                b += 1
                c -= 1
                continue
        if c == 0 and b == 0:
            ok = False
            break
        
        if c > b:
            b +=1
            c -= 1
            ans.append('B')
        else:
            b -= 1
            c += 1
            ans.append('C')
if ok:
    print('Yes')
    for x in ans:
        print(x)
else:print('No')

Buggy python submission (verdict: Runtime Error):
n,a,b,c = map(int,input().split())
ss = [input()for i in range(n)]
ok = True
ans = []
for i in range(n):
    s = ss[i]
    if s == 'AB':
        if a == 1 and b == 1 and c == 0:
            if  ss[i+1] == 'AC':
                ans.append('A')
                a += 1
                b -= 1
                continue
            elif ss[i+1] == 'BC':
                ans.append('B')
                b += 1
                a -= 1
                continue
            
            
        if a == 0 and b == 0:
            ok = False
            break
        
        if a > b:
            b +=1
            a -= 1
            ans.append('B')
        else:
            b -= 1
            a += 1
            ans.append('A')
            
    elif s == 'AC':
        if a == 1 and b == 0 and c == 1:
            if  ss[i+1] == 'AB':
                ans.append('A')
                a += 1
                c -= 1
                continue
            elif ss[i+1] == 'BC':
                ans.append('C')
                c += 1
                a -= 1
                continue
            
        if a == 0 and c == 0:
            ok = False
            break
        
        if a > c:
            c +=1
            a -= 1
            ans.append('C')
        else:
            c -= 1
            a += 1
            ans.append('A')
            
        
    else:
        if a == 0 and b == 1 and c == 1:
            if  ss[i+1] == 'AC':
                ans.append('C')
                c += 1
                b -= 1
                continue
            elif ss[i+1] == 'AB':
                ans.append('B')
                b += 1
                c -= 1
                continue
        if c == 0 and b == 0:
            ok = False
            break
        
        if c > b:
            b +=1
            c -= 1
            ans.append('B')
        else:
            b -= 1
            c += 1
            ans.append('C')
if ok:
    print('Yes')
    for x in ans:
        print(x)
else:print('No')


Fixed submission:
n,a,b,c = map(int,input().split())
ss = [input()for i in range(n)]
ok = True
ans = []
for i in range(n):
    s = ss[i]
    if s == 'AB':
        if a == 1 and b == 1 and c == 0:
            if  i+1 < n and ss[i+1] == 'AC':
                ans.append('A')
                a += 1
                b -= 1
                continue
            if i + 1 < n and ss[i+1] == 'BC':
                ans.append('B')
                b += 1
                a -= 1
                continue
            
            
        if a == 0 and b == 0:
            ok = False
            break
        
        if a > b:
            b +=1
            a -= 1
            ans.append('B')
        else:
            b -= 1
            a += 1
            ans.append('A')
            
    elif s == 'AC':
        if a == 1 and b == 0 and c == 1:
            if  i+1 < n and ss[i+1] == 'AB':
                ans.append('A')
                a += 1
                c -= 1
                continue
            if i + 1 < n and ss[i+1] == 'BC':
                ans.append('C')
                c += 1
                a -= 1
                continue
            
        if a == 0 and c == 0:
            ok = False
            break
        
        if a > c:
            c +=1
            a -= 1
            ans.append('C')
        else:
            c -= 1
            a += 1
            ans.append('A')
            
        
    else:
        if a == 0 and b == 1 and c == 1:
            if i+1 < n and  ss[i+1] == 'AC':
                ans.append('C')
                c += 1
                b -= 1
                continue
            if  i+ 1 < n and ss[i+1] == 'AB':
                ans.append('B')
                b += 1
                c -= 1
                continue
        if c == 0 and b == 0:
            ok = False
            break
        
        if c > b:
            b +=1
            c -= 1
            ans.append('B')
        else:
            b -= 1
            c += 1
            ans.append('C')
if ok:
    print('Yes')
    for x in ans:
        print(x)
else:print('No')

Buggy python submission (verdict: Runtime Error):
n,a,b,c = map(int,input().split())
ss = [input()for i in range(n)]
ok = True
ans = []
for i in range(n):
    s = ss[i]
    if s == 'AB':
        if a == 1 and b == 1 and c == 0:
            if  ss[i+1] == 'AC':
                ans.append('A')
                a += 1
                b -= 1
                continue
            elif ss[i+1] == 'BC':
                ans.append('B')
                b += 1
                a -= 1
                continue
            
            
        if a == 0 and b == 0:
            ok = False
            break
        
        if a > b:
            b +=1
            a -= 1
            ans.append('B')
        else:
            b -= 1
            a += 1
            ans.append('A')
            
    elif s == 'AC':
         if a == 1 and b == 0 and c == 1:
            if  ss[i+1] == 'AB':
                ans.append('A')
                a += 1
                c -= 1
                continue
            elif ss[i+1] == 'BC':
                ans.append('C')
                c += 1
                a -= 1
                continue
            
        if a == 0 and c == 0:
            ok = False
            break
        
        if a > c:
            c +=1
            a -= 1
            ans.append('C')
        else:
            c -= 1
            a += 1
            ans.append('A')
            
        
    else:
        if a == 0 and b == 1 and c == 1:
            if  ss[i+1] == 'AC':
                ans.append('C')
                c += 1
                b -= 1
                continue
            elif ss[i+1] == 'AB':
                ans.append('B')
                b += 1
                c -= 1
                continue
        if c == 0 and b == 0:
            ok = False
            break
        
        if c > b:
            b +=1
            c -= 1
            ans.append('B')
        else:
            b -= 1
            c += 1
            ans.append('C')
if ok:
    print('Yes')
    for x in ans:
        print(x)
else:print('No')


Fixed submission:
n,a,b,c = map(int,input().split())
ss = [input()for i in range(n)]
ok = True
ans = []
for i in range(n):
    s = ss[i]
    if s == 'AB':
        if a == 1 and b == 1 and c == 0:
            if  i+1 < n and ss[i+1] == 'AC':
                ans.append('A')
                a += 1
                b -= 1
                continue
            if i + 1 < n and ss[i+1] == 'BC':
                ans.append('B')
                b += 1
                a -= 1
                continue
            
            
        if a == 0 and b == 0:
            ok = False
            break
        
        if a > b:
            b +=1
            a -= 1
            ans.append('B')
        else:
            b -= 1
            a += 1
            ans.append('A')
            
    elif s == 'AC':
        if a == 1 and b == 0 and c == 1:
            if  i+1 < n and ss[i+1] == 'AB':
                ans.append('A')
                a += 1
                c -= 1
                continue
            if i + 1 < n and ss[i+1] == 'BC':
                ans.append('C')
                c += 1
                a -= 1
                continue
            
        if a == 0 and c == 0:
            ok = False
            break
        
        if a > c:
            c +=1
            a -= 1
            ans.append('C')
        else:
            c -= 1
            a += 1
            ans.append('A')
            
        
    else:
        if a == 0 and b == 1 and c == 1:
            if i+1 < n and  ss[i+1] == 'AC':
                ans.append('C')
                c += 1
                b -= 1
                continue
            if  i+ 1 < n and ss[i+1] == 'AB':
                ans.append('B')
                b += 1
                c -= 1
                continue
        if c == 0 and b == 0:
            ok = False
            break
        
        if c > b:
            b +=1
            c -= 1
            ans.append('B')
        else:
            b -= 1
            c += 1
            ans.append('C')
if ok:
    print('Yes')
    for x in ans:
        print(x)
else:print('No')

Buggy python submission (verdict: Runtime Error):
n,a,b,c = map(int,input().split())
ss = [input()for i in range(n)]
ok = True
ans = []
cnt = [[0]*3 for i in range(n)]
for i in range(n-1,-1,-1):
    
    s = ss[i]
    p = s[0]
    q = s[1]
    cnt[i][ord(p) - ord('A')] +=1
    cnt[i][ord(q) - ord('A')] +=1
    if i == 0:continue
    cnt[i-1][0] = cnt[i][0]
    cnt[i-1][1] = cnt[i][1]
    cnt[i-1][2] = cnt[i][2]

    
for s in ss:
    if s == 'AB':
        if a == 0 and b == 0:
            ok = False
            break
        
        if a == 0:
            ans.append('A')
            a += 1
            b -= 1
        elif b == 0:
            ans.append('B')
            b += 1
            a -= 1
        else:
            if cnt[0] > cnt[1]:
                a += 1
                b -= 1
                ans.append('A')
            else:
                ans.append('B')
                a -= 1
                b += 1
    elif s == 'AC':
        if a == 0 and c == 0:
            ok = False
            break
        if a == 0:
            ans.append('A')
            a += 1
            c -= 1
        elif c == 0:
            ans.append('C')
            c += 1
            a -= 1
        else:
            if cnt[0] > cnt[2]:
                a += 1
                c -= 1
                ans.append('A')
            else:
                ans.append('C')
                a -= 1
                c += 1
    else:
        if c == 0 and b == 0:
            ok = False
            break
        
        if b == 0:
            ans.append('B')
            c -= 1
            b += 1
        elif c == 0:
            ans.append('C')
            c += 1
            b -= 1
        else:
            if cnt[2] > cnt[1]:
                c += 1
                b -= 1
                ans.append('C')
            else:
                ans.append('B')
                c -= 1
                b += 1
if ok:
    print('Yes')
    for x in ans:
        print(x)
else:
    print('No')

Fixed submission:
n,a,b,c = map(int,input().split())
ss = [input()for i in range(n)]
ok = True
ans = []
for i in range(n):
    s = ss[i]
    if s == 'AB':
        if a == 1 and b == 1 and c == 0:
            if  i+1 < n and ss[i+1] == 'AC':
                ans.append('A')
                a += 1
                b -= 1
                continue
            if i + 1 < n and ss[i+1] == 'BC':
                ans.append('B')
                b += 1
                a -= 1
                continue
            
            
        if a == 0 and b == 0:
            ok = False
            break
        
        if a > b:
            b +=1
            a -= 1
            ans.append('B')
        else:
            b -= 1
            a += 1
            ans.append('A')
            
    elif s == 'AC':
        if a == 1 and b == 0 and c == 1:
            if  i+1 < n and ss[i+1] == 'AB':
                ans.append('A')
                a += 1
                c -= 1
                continue
            if i + 1 < n and ss[i+1] == 'BC':
                ans.append('C')
                c += 1
                a -= 1
                continue
            
        if a == 0 and c == 0:
            ok = False
            break
        
        if a > c:
            c +=1
            a -= 1
            ans.append('C')
        else:
            c -= 1
            a += 1
            ans.append('A')
            
        
    else:
        if a == 0 and b == 1 and c == 1:
            if i+1 < n and  ss[i+1] == 'AC':
                ans.append('C')
                c += 1
                b -= 1
                continue
            if  i+ 1 < n and ss[i+1] == 'AB':
                ans.append('B')
                b += 1
                c -= 1
                continue
        if c == 0 and b == 0:
            ok = False
            break
        
        if c > b:
            b +=1
            c -= 1
            ans.append('B')
        else:
            b -= 1
            c += 1
            ans.append('C')
if ok:
    print('Yes')
    for x in ans:
        print(x)
else:print('No')