Buggy python submission (verdict: Runtime Error):
N,A,B,C=map(int,input().split())

S=['']*N
for i in range(N):
    S[i]=input()

result=[]
kekka=True


for i in range(N):
    if (A==0 and B==0 and S[i]=='AB') or (C==0 and B==0 and S[i]=='BC') or (A==0 and C==0 and S[i]=='AC'):
        kekka=False
        break
    else:
        if S[i]=='AB':
            if A==0:
                A += 1
                B -= 1
                result.append('A')
            elif B==0:
                A -=1
                B +=1
                result.append('B')
            elif A==1 and B==1 and C==0:
                if S[i+1]=='AC':
                    A += 1
                    B -= 1
                    result.append('A')
                else:
                    A -=1
                    B +=1
                    result.append('B')
            elif A>B:
                A -=1
                B +=1
                result.append('B')
            else:
                A +=1
                B -=1
                result.append('A')
        elif S[i]=='AC':
            if A==0:
                A += 1
                C -= 1
                result.append('A')
            elif C==0:
                A -=1
                C +=1
                result.append('C')
            elif A==1 and C==1 and B==0:
                if S[i+1]=='AB':
                    A += 1
                    C -= 1
                    result.append('A')
                else:
                    A -=1
                    C +=1
                    result.append('C')
            elif A>C:
                A -=1
                C +=1
                result.append('C')
            else:
                A +=1
                C -=1
                result.append('A') 
        elif S[i]=='BC':
            if B==0:
                B += 1
                C -= 1
                result.append('B')
            elif C==0:
                B -=1
                C +=1
                result.append('C')
            elif B==1 and C==1 and A==0:
                if S[i+1]=='AB':
                    B += 1
                    C -= 1
                    result.append('B')
                else:
                    B -=1
                    C +=1
                    result.append('C')
            elif B>C:
                B -=1
                C +=1
                result.append('C')
            else:
                B +=1
                C -=1
                result.append('B')

if kekka ==False:
    print('No')
else:
    print('Yes')
    for i in range(len(result)):
        print(result[i])            




Fixed submission:
N=int(input())
A=list(map(int,input().split()))

result=0

D={}

for j in range(N):
    if j+A[j] in D:
        D[j+A[j]] += 1
    else:
        D[j+A[j]]=1

for j in range(N):
    if j-A[j] in D:
        result += D[j-A[j]]

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

result=0

L_p=[j+A[j] for j in range(N)]
L_n=[j-A[j] for j in range(N)]

for j in range(N-1):
    result += L_n[j+1:].count(L_p[j])

print(result)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))

result=0

D={}

for j in range(N):
    if j+A[j] in D:
        D[j+A[j]] += 1
    else:
        D[j+A[j]]=1

for j in range(N):
    if j-A[j] in D:
        result += D[j-A[j]]

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

result=0

for j in range(N-1):
    for k in range(j+A[j]+1,N):
        if k-j==A[k]+A[j]:
            result +=1

print(result)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))

result=0

D={}

for j in range(N):
    if j+A[j] in D:
        D[j+A[j]] += 1
    else:
        D[j+A[j]]=1

for j in range(N):
    if j-A[j] in D:
        result += D[j-A[j]]

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

result=0

for j in range(N-1):
    for k in range(j+2,N):
        if k-j==A[k]+A[j]:
            result +=1

print(result)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))

result=0

D={}

for j in range(N):
    if j+A[j] in D:
        D[j+A[j]] += 1
    else:
        D[j+A[j]]=1

for j in range(N):
    if j-A[j] in D:
        result += D[j-A[j]]

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

result=0

for j in range(N-1):
    for k in range(j+1,N):
        if k-j==A[k]+A[j]:
            result +=1

print(result)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))

result=0

D={}

for j in range(N):
    if j+A[j] in D:
        D[j+A[j]] += 1
    else:
        D[j+A[j]]=1

for j in range(N):
    if j-A[j] in D:
        result += D[j-A[j]]

print(result)