Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,H=list(map(int,input().split()))
a=[0]*N
b=[0]*N

for i in range(N):
    ta,tb=list(map(int,input().split()))
    a[i]=ta
    b[i]=tb

amax=max(a)
b.sort(reverse=True)

res=10**10

for i in range(N+1):
    cnt=i
    ch=H

    ch-=sum(b[:i]) if i>0 else 0
    if H>0:
        cnt+=(ch+amax-1)//amax

    res=min(res,cnt)

print(res)    


Fixed submission:
N,H=list(map(int,input().split()))
a=[0]*N
b=[0]*N

for i in range(N):
    ta,tb=list(map(int,input().split()))
    a[i]=ta
    b[i]=tb

amax=max(a)
b.sort(reverse=True)

res=10**10
csum=0
for i in range(N+1):
    cnt=i
    ch=H
    csum+=b[i-1] if i>0 else 0
    ch-=csum

    if ch>0:
        cnt+=-(-ch//amax)

    res=min(res,cnt)

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N,H=list(map(int,input().split()))
a,b=np.transpose([list(map(int,input().split())) for _ in range(N)])

amax=max(a)
b=sorted(b,reverse=True)
res=10**10

for i in range(N+1):
    cnt=i
    ch=H

    ch-=sum(b[:i]) if i>0 else 0
    if H>0:
        cnt+=int(np.ceil(ch/amax))

    res=min(res,cnt)

print(res)    


Fixed submission:
N,H=list(map(int,input().split()))
a=[0]*N
b=[0]*N

for i in range(N):
    ta,tb=list(map(int,input().split()))
    a[i]=ta
    b[i]=tb

amax=max(a)
b.sort(reverse=True)

res=10**10
csum=0
for i in range(N+1):
    cnt=i
    ch=H
    csum+=b[i-1] if i>0 else 0
    ch-=csum

    if ch>0:
        cnt+=-(-ch//amax)

    res=min(res,cnt)

print(res)
Buggy python submission (verdict: Runtime Error):
n=int(input())
mod=10**9+7

s1=input()
s2=input()

if n==1:
    print(3)
    exit(0)

if s1[0]==s1[1]:
    l=1
    ans=6
    i=2
else:
    l=0
    ans=3
    i=1

while True:
    if i==n-1:
        if l==0:
            ans*=2
            ans%=mod
        break

    if s1[i+1]==s1[i]:
        c=1
        i+=2
    else:
        c=0
        i+=1
    
    if l==0:
        ans*=2
    if l==1 and c==1:
        ans*=3
    
    ans%=mod
    
    l=c
    
print(ans)


Fixed submission:
n=int(input())
mod=10**9+7

s1=input()
s2=input()

if n==1:
    print(3)
    exit(0)

if s1[0]==s1[1]:
    l=1
    ans=6
    i=2
else:
    l=0
    ans=3
    i=1

while i<n:
    if i==n-1:
        if l==0:
            ans*=2
            ans%=mod
        break

    if s1[i+1]==s1[i]:
        c=1
        i+=2
    else:
        c=0
        i+=1
    
    if l==0:
        ans*=2
    if l==1 and c==1:
        ans*=3
    
    ans%=mod
    
    l=c
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
targetlist = [i+1 for i in range(n)]
cnt=0
import itertools
for i in itertools.product(targetlist,targetlist,targetlist):
    if (i[0]*i[1])+i[2] == n:
        cnt+=1
print(cnt)

Fixed submission:
n = int(input())
ans = 0
'''
A*B<=N-1となるAとBの組み合わせが何通りあるかを調べること
この考えを導きだせるかが、この問題を解くカギとなる
Cの最小値1を右辺に移項してN-1となっている
不等式となっている点がポイント
Cの最小値1としておけばAとBの組み合わせを全部考えることができる
次に、AとBどちらでも良いが、あるA（もしくはB）が1つの値を決めたときに、
それに対応するB（もしくはA）が何通りあるかを計算して、A（もしくはB）の値をn-1まで
計算して足してあげれば答えとなる
とてもシンプルなコードだけどこれでACとなるはず
'''

for i in range(1,n):
    #print(i, (n-1)//i)
    ans += (n-1)//i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
cnt = 0
for i in range(1, n+1):
    for j in range(1, n+1):
        for k in range(1, n+1):
            if (i * j) + k == n:
                cnt+=1
print(cnt)

Fixed submission:
n = int(input())
ans = 0
'''
A*B<=N-1となるAとBの組み合わせが何通りあるかを調べること
この考えを導きだせるかが、この問題を解くカギとなる
Cの最小値1を右辺に移項してN-1となっている
不等式となっている点がポイント
Cの最小値1としておけばAとBの組み合わせを全部考えることができる
次に、AとBどちらでも良いが、あるA（もしくはB）が1つの値を決めたときに、
それに対応するB（もしくはA）が何通りあるかを計算して、A（もしくはB）の値をn-1まで
計算して足してあげれば答えとなる
とてもシンプルなコードだけどこれでACとなるはず
'''

for i in range(1,n):
    #print(i, (n-1)//i)
    ans += (n-1)//i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = list(map(int, input().split()))

ans = 0
import itertools
for i in itertools.combinations(a_list, 2):
    ans += i[0] * i[1]
print(ans % (10**9 + 7))

Fixed submission:
n = int(input())
a_list = list(map(int, input().split()))

s_2 = 0
for i in a_list:
    s_2 += i**2

ans = (sum(a_list)**2 - s_2)//2  

ans = ans%(10**9+7)
print(ans)
Buggy python submission (verdict: Runtime Error):
cnt = 0
while red >= green:
    green *= 2
    cnt += 1
while green >= blue:
    blue *= 2
    cnt += 1

if cnt <= k:
    print('Yes')
else:
    print('No')

Fixed submission:
red, green, blue = map(int, input().split())
k = int(input())

ans_list = []
def doble_calc(value, num):
    if num == 1:
        return value
    elif num == 2:
        return value*2
    elif num == 3:
        return value*2*2
    elif num == 4:
        return value*2*2*2
    elif num == 5:
        return value*2*2*2*2
    elif num == 6:
        return value*2*2*2*2*2
    elif num == 7:
        return value*2*2*2*2*2*2
    
for i in range(1, k+2):
    for j in range(1, k+2):
        for l in range(1, k+2):
            if i + j + l == k+3:
                red_calc = doble_calc(red, i)
                green_calc = doble_calc(green, j)
                blue_calc = doble_calc(blue, l)
                ans_list.append([red_calc, green_calc, blue_calc])
            
for i in ans_list:
    if i[0] < i[1] < i[2]:
        print('Yes')
        break
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
#from tqdm import tqdm
for i in range(1, n+1):
    ans=0
    for x in range(1, 10):
        for y in range(1, 10):
            for z in range(1, 10):
                if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
                    ans+=1
                    #print(i, x,y,z)
    if ans != 0:
        print(ans)
    else:
        print(ans)

Fixed submission:
n = int(input())
#from tqdm import tqdm
ans=[0 for _ in range(10001)]
for x in range(1, 105):
    for y in range(1, 105):
        for z in range(1, 105):
            v = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if v < 10001:
                ans[v]+=1
                #print(i, x,y,z)
for i in range(n):
    print(ans[i+1])

Buggy python submission (verdict: Runtime Error):
from tqdm import tqdm
for i in range(1, 20+1):
    ans=0
    for x in range(1, 10):
        for y in range(1, 10):
            for z in range(1, 10):
                if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
                    ans+=1
                    #print(i, x,y,z)
    if ans != 0:
        print(ans)
    else:
        print(ans)

Fixed submission:
n = int(input())
#from tqdm import tqdm
ans=[0 for _ in range(10001)]
for x in range(1, 105):
    for y in range(1, 105):
        for z in range(1, 105):
            v = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if v < 10001:
                ans[v]+=1
                #print(i, x,y,z)
for i in range(n):
    print(ans[i+1])
Buggy python submission (verdict: Runtime Error):
n = input()
value = n[-3]+n[-2]+n[-1]
#print(value)
value_int = int(value)
if value == '000':
    print(0)
else:
    print(1000 - value_int)

Fixed submission:
n = input()
if len(n) < 3:
    print(1000- int(n))
else:   
    value = n[-3]+n[-2]+n[-1]
    #print(value)
    value_int = int(value)
    if value == '000':
        print(0)
    else:
        print(1000 - value_int)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [int(i) for i in input().split()]
work = 1
for a in A:
    work *= a
if work > 10**18:
    print('-1')
else:
    print(work)

Fixed submission:
n = int(input())
A = [int(i) for i in input().split()]
check = [i for i in A if i == 0]
if 0 in check:
    print(0)
else:   
    A.sort(reverse=True)
    work = 1
    for a in A:
        work *= a
        if work > 10**18:
            print('-1')
            break
    else:
        print(work)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [int(i) for i in input().split()]
work = 1
for a in A:
    work *= a
if work > 10**18:
    print(-1)
else:
    print(work)

Fixed submission:
n = int(input())
A = [int(i) for i in input().split()]
check = [i for i in A if i == 0]
if 0 in check:
    print(0)
else:   
    A.sort(reverse=True)
    work = 1
    for a in A:
        work *= a
        if work > 10**18:
            print('-1')
            break
    else:
        print(work)
Buggy python submission (verdict: Runtime Error):
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

# 購買する全パターンを回す
most_row_price = 10**10
for i in range(2**n):
    comb = str(bin(i)[2:]).zfill(n)
    
    # 購買パターン毎の購入金額と理解度を算出する
    money_per_pattern = [0] * n # 購買パターン毎の金額の初期化
    total_money = 0 # 合計購入金額の初期化
    for j in range(n):
        
        # 購入しないケースは除外する
        if comb[j] == '0':
            continue
            
        # 購入するケースだけ、金額算出する
        total_money += ca[j][0]
        
        # 当該パターンの理解度を算出する
        for k in range(m):
            understanding[k] += ca[j][k+1]           

    for j in range(m):
        if understanding[j] < x:
            break
    else:
        most_row_price = min(total_money, most_row_price)

if most_row_price == 10**10:
    print(-1)
else:
    print(most_row_price)

Fixed submission:
n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

# 購買する全パターンを回す
most_row_price = 10**10
for i in range(2**n):
    comb = str(bin(i)[2:]).zfill(n)
    
    # 購買パターン毎の購入金額と理解度を算出する
    money_per_pattern = [0] * n # 購買パターン毎の金額の初期化
    understanding = [0] * m # 理解度の初期化
    total_money = 0 # 合計購入金額の初期化
    for j in range(n):
        
        # 購入しないケースは除外する
        if comb[j] == '0':
            continue
            
        # 購入するケースだけ、金額算出する
        money_per_pattern[j] = ca[j][0]
        
        # 当該パターンの理解度を算出する
        for k in range(m):
            understanding[k] += ca[j][k+1]           
    total_money = sum(money_per_pattern)            

    judge_flg = 'ok'
    for j in range(m):
        if understanding[j] < x:
            judge_flg = 'ng'
    
    if judge_flg == 'ok':
        most_row_price = min(total_money, most_row_price)

if most_row_price == 10**10:
    print(-1)
else:
    print(most_row_price)
Buggy python submission (verdict: Runtime Error):
a = [int(i) for i in a.split()]
# N:参加回数　R:表示レーティング
N = a[0]
R = a[1]

# X:内部レーティング
#R = X - 100 * (10 - N)
if N >= 10:
    print(R)
else:
    print(R + 100 * (10 - N))

Fixed submission:
a = [int(i) for i in input().split()]
# N:参加回数　R:表示レーティング
N = a[0]
R = a[1]

# X:内部レーティング
#R = X - 100 * (10 - N)
if N >= 10:
    print(R)
else:
    print(R + 100 * (10 - N))
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = [int(input()) for _ in range(n)]
A_set = set(A)
if len(A_set) == n:
    print('YES')
else:
    print('NO')

Fixed submission:
n = int(input())
A = [int(a) for a in input().split()]
A_set = set(A)
if len(A_set) == n:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
from sympy import sieve
x = int(input())
sosuu = list(sieve.primerange(2, 1000000))
for i in sosuu:
    if i >= x:
        print(i)
        break

Fixed submission:
x = int(input())
flag = False
for i in range(x, 1000000):
    for j in range(2, i+1):
        #print(i, j)
        if j == i:
            print(i)
            flag = True
            break
        if i % j == 0:
            #print('*', i, j)
            break
    if flag:
        break

Buggy python submission (verdict: Runtime Error):
x = int(input())
sosuu = list(sieve.primerange(2, 1000000))
for i in sosuu:
    if i >= x:
        print(i)
        break

Fixed submission:
x = int(input())
flag = False
for i in range(x, 1000000):
    for j in range(2, i+1):
        #print(i, j)
        if j == i:
            print(i)
            flag = True
            break
        if i % j == 0:
            #print('*', i, j)
            break
    if flag:
        break
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = [int(input()) for _ in range(n)]

import copy

alist_copy = copy.copy(alist)
for i, v in enumerate(alist):
    alist_copy.pop(i)
    print(max(alist_copy))
    alist_copy = copy.copy(alist)

Fixed submission:
n = int(input())
alist = [int(input()) for _ in range(n)]

import copy
alist_copy = copy.copy(alist)

alist_copy.sort()
max_value = alist_copy[-1]
next_value = alist_copy[-2]
for a in alist:
    if a == max_value:
        print(next_value)
    else:
        print(max_value)
Buggy python submission (verdict: Runtime Error):
a,b=map(int, input().split())

if a+b=<16:
  print('Yay!')
else:
  print(':(')

Fixed submission:
a,b=map(int, input().split())
if a<=8 and b<=8:
  print('Yay!')
else:
  print(':(')
Buggy python submission (verdict: Runtime Error):
d, n = map(int, input().split())

if d = 0:
  if n <= 99:
    print(n)
  else:
    print(101)
elif d = 1:
  if n <= 99:
    print(100*n)
  else:
    print(10100)
else:
  if n <= 99:
    print(10000*n)
  else:
    print(1010000)
  

Fixed submission:
d, n = map(int, input().split())

if d == 0:
    if n <= 99:
        print(n)
    else:
        print(101)
elif d == 1:
    if n <= 99:
        print(n*100)
    else:
        print(10100)
elif d == 2:
    if n <= 99:
        print(n*10000)
    else:
        print(1010000)
Buggy python submission (verdict: Runtime Error):
N, M  = map(int, input().split())
S = []
for i in range(M):
    S.append(set(input().split()))

groups = [S[0]]

for j in range(1,len(S)-1):
    for k in range(len(groups)):
        if S[j] & groups[k] != set():
            groups[k] = S[j] | group
        else:
            groups.append(S[j])
lens = []
for group in groups:
    lens.append(len(group))
print(max(lens))

Fixed submission:
D, T, S  = map(int, input().split())

if D <= T*S:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))

ans = 0

for i in range(len(L)-1):
    ans += L[i] * sum(L[i+1:])
    
print(ans % (10**9 + 7))

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

ans = 0

S = sum(L)
for i in range(len(L)-1):
    ans += L[i] * (S- L[i])
    S -= L[i]
    
print(ans % (10**9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))
sum_L = []

for i in range(1,len(L)):
    sum_L.append(sum(L[i:]))

ans = 0

for i in range(len(L)-1):
    ans += L[i] * sum_L[i]

print(ans % (10**9 + 7))

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

ans = 0

S = sum(L)
for i in range(len(L)-1):
    ans += L[i] * (S- L[i])
    S -= L[i]
    
print(ans % (10**9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)

listS = []

N, K  = map(int, input().split())
A = list(map(int,input().split()))

for i in range(0,N-K):
    if prod(A[i:K+i]) < prod(A[i+1:K+i+1]):
        print("Yes")
    else:
        print("No")

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

for i in range(0,N-K):
    if A[i] < A[i+K]:
        print("Yes")
    else:
        print("No")

Buggy python submission (verdict: Runtime Error):
import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)

listS = []

N, K  = map(int, input().split())
A = list(map(int,input().split()))

for i in range(0,N-K+1):
    if prod(A[i:K+i]) < prod(A[i+1:K+i+1]):
        print("Yes")
    else:
        print("No")

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

for i in range(0,N-K):
    if A[i] < A[i+K]:
        print("Yes")
    else:
        print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)

listS = []

N, K  = map(int, input().split())
A = list(map(int,input().split()))

for i in range(0,N-K+1):
    listS.append(prod(A[i:K+i]))
    
for j in range(len(listS)-1):
    if listS[j] < listS[j+1]:
        print("Yes")
    else:
        print("No")

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

for i in range(0,N-K):
    if A[i] < A[i+K]:
        print("Yes")
    else:
        print("No")

Buggy python submission (verdict: Runtime Error):
import numpy as np

listS = []

N, K  = map(int, input().split())
A = list(map(int,input().split()))

for i in range(0,N-K+1):
    listS.append(np.prod(A[i:K+i]))
    
for j in range(len(listS)-1):
    if listS[j] < listS[j+1]:
        print("Yes")
    else:
        print("No")

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

for i in range(0,N-K):
    if A[i] < A[i+K]:
        print("Yes")
    else:
        print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)
listS = []

# N = 5 
# K = 3
# A = [96,98,95,100,20]

N, K  = map(int, input().split())
A = list(map(int,input().split()))

for i in range(0,N-K+1):
    listS.append(prod(A[i:K+i]))
    
for j in range(len(listS)-1):
    if listS[j] < listS[j+1]:
        print("Yes")
    else:
        print("No")

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

for i in range(0,N-K):
    if A[i] < A[i+K]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
print(sum(A)-min(A))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
if N % 2 == 0:
    d = int(N/2)
    print(A[0] + 2 * sum(A[1:d]))
else:
    b = int((N-1)/2)
    c = int((N-1)/2)
    print(A[0] + 2 * sum(A[1:b]) + A[c])
Buggy python submission (verdict: Runtime Error):
ls =list([2,4,5,7,9],[0,1,6,8],[3])
dic = dict{[2,4,5,7,9]:"hon" , [0,1,6,8]:"pon" , [3]:"bon"}
s=int(input())
for i in ls:
  if s%10 in i:
    print(dic[i])

Fixed submission:
ls =["24579" , "0168" , "3"]
dic = {"24579":"hon" , "0168":"pon" , "3":"bon"}
s=input()
for i in ls:
  if s[len(s)-1] in i:
    print(dic[i])
Buggy python submission (verdict: Runtime Error):
n = int(iniput())
sm = 0
for i in range(1,n+1,1):
  if i%3 and i%5:
    sm+=i
print(sm)

Fixed submission:
n = int(input())
sm = 0
for i in range(1,n+1,1):
  if i%3 and i%5:
    sm+=i
print(sm)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))

ok = max(a)
ng = 0
for _ in range(50):
    mid = (ok+ng)//2
    cnt = 0
    for ai in a:
        cnt += (ai-1)//mid
    if(cnt <= k):
        ok = mid
    else:
        ng = mid

print(ok)

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))

ok = max(a)
ng = 0
for _ in range(50):
    mid = (ok+ng)//2
    if(mid==0):
        print(1)
        exit()
    cnt = 0
    for ai in a:
        cnt += (ai-1)//mid
    if(cnt <= k):
        ok = mid
    else:
        ng = mid

print(ok)
Buggy python submission (verdict: Runtime Error):
x,y = map(int,input().split())
for i in range(x+1):
    num = i*2 + (x-i)*4
    if(num == y):
        print('Yes')
        exit()

print('No

Fixed submission:
x,y = map(int,input().split())
for i in range(x+1):
    num = i*2 + (x-i)*4
    if(num == y):
        print('Yes')
        exit()

print('No')
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n,a,b,c = map(int,input().split())
ans = []
abc = [a,b,c]

d = {'AB\n':(0,1),'AC\n':(0,2),'BC\n':(1,2)}

if(a+b+c >= 3)|(a+b+c==1):
    for _ in range(n):
        s = input()
        x,y = d[s]
        if(abc[x]==0)&(abc[y]==0):
            print('No')
            exit()
        if(abc[x] < abc[y]):
            x,y = y,x
        abc[x] -= 1
        abc[y] += 1
        ans.append(y)
else:
    ss = (input() for _ in range(n))
    if(max(abc)==2):
        #(2,0,0)
        case = True
    else:
        case = False

    for i in range(n):
        s = ss[i]
        x,y = d[s]
        if(case)|(i==n-1):
            if(abc[x]==0)&(abc[y]==0):
                print('No')
                exit()
            if(abc[x] < abc[y]):
                x,y = y,x
            abc[x] -= 1
            abc[y] += 1
            case = False
        else:
            if(abc[x]!=abc[y]):
                if(abc[x] < abc[y]):
                    x,y = y,x
                abc[x] -= 1
                abc[y] += 1
            else:
                sn = ss[i+1]
                if(x in d[sn]):
                    x,y = y,x
                abc[x] -= 1
                abc[y] += 1
            case = True
        ans.append(y)

print('Yes')
for i in ans:
    print(chr(i+ord('A')))

Fixed submission:
import sys
input = sys.stdin.readline

n,a,b,c = map(int,input().split())
ans = []
abc = [a,b,c]

d = {'AB\n':(0,1),'AC\n':(0,2),'BC\n':(1,2)}

if(a+b+c==0):
    print('No')
    exit()

if(a+b+c >= 3)|(a+b+c==1):
    for _ in range(n):
        s = input()
        x,y = d[s]
        if(abc[x]==0)&(abc[y]==0):
            print('No')
            exit()
        if(abc[x] < abc[y]):
            x,y = y,x
        abc[x] -= 1
        abc[y] += 1
        ans.append(y)

elif(a+b+c==2):
    ss = [input() for _ in range(n)]
    if(max(abc)==2):
        #(2,0,0)
        case = True
    else:
        case = False

    for i in range(n):
        s = ss[i]
        x,y = d[s]
        if(case)|(i==n-1):
            if(abc[x]==0)&(abc[y]==0):
                print('No')
                exit()
            if(abc[x] < abc[y]):
                x,y = y,x
            abc[x] -= 1
            abc[y] += 1
            case = False
        else:
            if(abc[x]!=abc[y]):
                if(abc[x] < abc[y]):
                    x,y = y,x
                abc[x] -= 1
                abc[y] += 1
                case = False
            else:
                sn = ss[i+1]
                if(x in d[sn]):
                    x,y = y,x
                abc[x] -= 1
                abc[y] += 1
                case = True
        ans.append(y)

print('Yes')
for i in ans:
    print(chr(i+ord('A')))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import deque
import bisect

n = int(input())
a = list(map(int,input().split()))

links = [[] for _ in range(n+1)]
for _ in range(n-1):
    v,w = map(int, input().split())
    links[v].append(w)
    links[w].append(v)

inf = 10**10
lis = [inf] * n
inf_ind = 0
parent = [-1]*(n+1)
operate = [0] * (n+1)
ans = [-1]*(n+1)
d = deque()
d.append(1)
while(d):
    print(d)
    now = d.popleft()
    if(operate[now]==0):
        p = parent[now]
        if(p!=-1):
            d.appendleft(now)
        for child in links[now]:
            if(child != p):
                parent[child] = now
                d.appendleft(child)

        a_now = a[now-1]
        ind = bisect.bisect_left(lis,a_now)
        operate[now] = (ind,lis[ind],a_now)
        lis[ind] = a_now
        if(inf_ind == ind):
            inf_ind += 1
        ans[now] = inf_ind
    else:
        ind,before,after = operate[now]
        lis[ind] = before
        if(before == inf):
            inf_ind -= 1
    # print(lis)

for i in ans[1:]:
    print(i)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque
import bisect

n = int(input())
a = list(map(int,input().split()))

links = [[] for _ in range(n+1)]
for _ in range(n-1):
    v,w = map(int, input().split())
    links[v].append(w)
    links[w].append(v)

inf = 10**10
lis = [inf] * n
inf_ind = 0
parent = [-1]*(n+1)
operate = [0] * (n+1)
ans = [-1]*(n+1)
d = deque()
d.append(1)
while(d):
    now = d.popleft()
    if(operate[now]==0):
        p = parent[now]
        if(p!=-1):
            d.appendleft(now)
        for child in links[now]:
            if(child != p):
                parent[child] = now
                d.appendleft(child)

        a_now = a[now-1]
        ind = bisect.bisect_left(lis,a_now)
        operate[now] = (ind,lis[ind],a_now)
        lis[ind] = a_now
        if(inf_ind == ind):
            inf_ind += 1
        ans[now] = inf_ind
    else:
        ind,before,after = operate[now]
        lis[ind] = before
        if(before == inf):
            inf_ind -= 1
    # print(lis)

for i in ans[1:]:
    print(i)