Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left as bl
x,n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    i = 0
    p.sort()
    a = bl(p, x)
    if a == n:
        print(x)
    elif p[a] != x:
        print(x)
    else:
        while(True):
            i += 1
            if p[bl(p, x-i)] != x-i:
                print(x-i)
                break
            elif p[bl(p, x+i)] != x+i:
                print(x+i)
                break

Fixed submission:
from bisect import bisect_left as bl
x,n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    i = 0
    p.sort()
    a = bl(p, x)
    if a == n:
        print(x)
    elif p[a] != x:
        print(x)
    else:
        while(True):
            i += 1
            if p[bl(p, x-i)] != x-i:
                print(x-i)
                break
            else:
                a = bl(p, x+i)
                if a == n:
                    print(x+i)
                    break
                elif p[a] != x+i:
                    print(x+i)
                    break

Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left as bl
x,n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    i = 0
    p.sort()
    if p[bl(p, x)] != x:
        print(x)
    else:
        while(True):
            i += 1
            if p[bl(p, x-i)] != x-i:
                print(x-i)
                break
            elif p[bl(p, x+i)] != x+i:
                print(x+i)
                break

Fixed submission:
from bisect import bisect_left as bl
x,n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    i = 0
    p.sort()
    a = bl(p, x)
    if a == n:
        print(x)
    elif p[a] != x:
        print(x)
    else:
        while(True):
            i += 1
            if p[bl(p, x-i)] != x-i:
                print(x-i)
                break
            else:
                a = bl(p, x+i)
                if a == n:
                    print(x+i)
                    break
                elif p[a] != x+i:
                    print(x+i)
                    break
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
import operator
n = int(input())
a = list(map(int, input().split()))
ans = reduce(operator.mul, a, 1)
if ans <= 10**18:
    print(ans)
else:
    print(str(-1))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 1;
for i in range(n):
    if ans > 10**18:
        break
    ans *= a[i]
if 0 in a:
    print(0)
elif ans <= 10**18:
    print(ans)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n):
    ans *= a[i]
if ans <= 10**18:
    print(ans)
else:
    print(-1)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 1;
for i in range(n):
    if ans > 10**18:
        break
    ans *= a[i]
if 0 in a:
    print(0)
elif ans <= 10**18:
    print(ans)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
import math
a,b = map(str, input().split())
a = int(a)
b = b.replace(".","")
if len(b) == 2:
    b = b + '0'
b = int(b)
ans = a*b
if ans == 0:
    print(0)
else:
    print(int(str(ans)[:-2]))

Fixed submission:
import math
a,b = map(str, input().split())
a = int(a)
b = b.replace(".","")
if len(b) == 2:
    b = b + '0'
b = int(b)
ans = a*b
if len(str(ans)) <= 2:
    print(math.floor(ans/100))
else:
    print(int(str(ans)[:-2]))

Buggy python submission (verdict: Runtime Error):
import math
a,b = map(str, input().split())
a = int(a)
b = b.replace(".","")
if len(b) == 2:
    b = b + '0'
b = int(b)
ans = a*b
print(int(str(ans)[:-2]))

Fixed submission:
import math
a,b = map(str, input().split())
a = int(a)
b = b.replace(".","")
if len(b) == 2:
    b = b + '0'
b = int(b)
ans = a*b
if len(str(ans)) <= 2:
    print(math.floor(ans/100))
else:
    print(int(str(ans)[:-2]))
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, input().split())
print(f'{c} {a} {b}')

Fixed submission:
a,b,c = map(int, input().split())
print(str(c)+' '+str(a)+' '+str(b))

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, input().split())
print(f'{c} {a} {b}')

Fixed submission:
a,b,c = map(int, input().split())
print(str(c)+' '+str(a)+' '+str(b))
Buggy python submission (verdict: Runtime Error):
s = input()
def is_kaibun(s):
  for i in range(len(s)//2):
    if s[i] != s[-i-1]:
      return False
  return True
n = len(s)
s1 = s[:(n-1)/2]
s2 = s[(n+1)/2:]
if is_kaibun(s) & is_kaibun(s1) & is_kaibun(s2):
  print('Yes')
else:
  print('No')


Fixed submission:
s = input()
def is_kaibun(s):
  for i in range(len(s)//2):
    if s[i] != s[-i-1]:
      return False
  return True
n = len(s)
s1 = s[:(n-1)//2]
s2 = s[(n+1)//2:]
if is_kaibun(s) & is_kaibun(s1) & is_kaibun(s2):
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
for i in range(n+1):
  if a <= sum(list(map(int, list(str(i))))) <= b:
    ans += 1
print(ans)

Fixed submission:
n, a, b = map(int, input().split())
ans = 0
for i in range(n+1):
  if a <= sum(list(map(int, list(str(i))))) <= b:
    ans += i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
a = [int(i) for i in input().split()]

a.sort()
b = set()
c = 0
for i, v in enumerate(a):
    flag = True
    for j in range(1, int(math.sqrt(v))+1):
        if v % j == 0 and (j in b or v/j in b):
            flag = False
            break
    if flag == True:
        b.add(v)
        if i+1 >= len(a):
            c += 1
        elif a[i+1] != v:
            c += 1
  
print(c)

Fixed submission:
import math
n = int(input())
a = [int(i) for i in input().split()]

a.sort()
b = [0 for _ in range(a[-1])]
c = 0
for i in a:
    x = i-1
    while len(b) > x:
        b[x] += 1
        x += i 
for i in a:
    if b[i-1] == 1:
        c += 1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
a = [int(i) for i in input().split()]

a.sort()
b = []
c = 0
r = []
for i, v in enumerate(a):
    flag = True
    for j in range(1, int(math.sqrt(v))+1):
        if v % j == 0 and (j in b or v/j in b):
            flag = False
            break
    if flag == True:
        b.append(v)
        if i+1 >= len(a):
            c += 1
        elif a[i+1] != v:
            c += 1
print(c)

Fixed submission:
import math
n = int(input())
a = [int(i) for i in input().split()]

a.sort()
b = [0 for _ in range(a[-1])]
c = 0
for i in a:
    x = i-1
    while len(b) > x:
        b[x] += 1
        x += i 
for i in a:
    if b[i-1] == 1:
        c += 1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]

a.sort()
b = []
c = 0
for i, v in enumerate(a):
    flag = True
    for j in b:          
        if v % j == 0:
            flag = False
            break
        elif v / 2 <= j:
            if a[i-1] == v:
                flag = False
            break
    if flag == True:
        b.append(v)
        if i+1 >= len(a):
            c += 1
        elif a[i+1] != v:
            c += 1
     
print(c)

Fixed submission:
import math
n = int(input())
a = [int(i) for i in input().split()]

a.sort()
b = [0 for _ in range(a[-1])]
c = 0
for i in a:
    x = i-1
    while len(b) > x:
        b[x] += 1
        x += i 
for i in a:
    if b[i-1] == 1:
        c += 1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
# from scipy.misc import comb
# from scipy.special import comb
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def banned(al):
    d = {}
    for a in al:
        if a in d.keys():
            d[a] += 1
        else:
            d[a] = 1
    # print(d)
    for k, v in d.items():
        if v > 1:
            d[k] = [v, comb(v, 2)]
        else:
            d[k] = [v, 0]
    for a in al:
        ans = 0
        for k, v in d.items():
            if k == a:
                if v[0] > 2:
                    ans += comb(v[0]-1, 2)
            else:
                ans += v[1]
        print(int(ans))

n = int(input())
al = [int(i) for i in input().split()]

banned(al)

Fixed submission:
# from scipy.misc import comb
# from scipy.special import comb
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def banned(al):
    d = {}
    for a in al:
        if a in d.keys():
            d[a] += 1
        else:
            d[a] = 1
    # print(d)
    ans = 0
    for k, v in d.items():
        if v > 1:
            ans += comb(v, 2)
            # d[k] = [v, comb(v, 2)]
        # else:
            # d[k] = [v, 0]
    # print(ans)
    for a in al:
        # for k, v in d.items():
        #     if k == a:
        #         if v[0] > 2:
        #             ans += comb(v[0]-1, 2)
        #     else:
        #         ans += v[1]
        print(int(ans-(d[a]-1)))

n = int(input())
al = [int(i) for i in input().split()]

banned(al)
Buggy python submission (verdict: Time Limit Exceeded):
def distinct_or_not(a_list):
    tmp_list = []
    for a in a_list:
        if len(tmp_list) == 0:
            tmp_list.append(a)
        else:
            left = 0
            right = len(tmp_list) - 1
            while left <= right:
                mid = (left + right) // 2
                if tmp_list[mid] == a:
                    return 'NO'
                elif tmp_list[mid] > a:
                    right = mid - 1
                else:
                    left = mid + 1
            tmp_list.insert(right+1, a)
    return 'YES'

n = int(input())
a_list = [int(a) for a in input().split()]

print(distinct_or_not(a_list))

Fixed submission:
def distinct_or_not_2(a_list):
    a_list.sort()
    for i in range(len(a_list)-1):
        if a_list[i] == a_list[i+1]:
            return 'NO'
    return 'YES'

n = int(input())
a_list = [int(a) for a in input().split()]

print(distinct_or_not_2(a_list))

Buggy python submission (verdict: Time Limit Exceeded):
def distinct_or_not(a_list):
    tmp_list = []
    for a in a_list:
        if a not in tmp_list:
            tmp_list.append(a)
        else:
            return 'NO'
    return 'YES'

n = int(input())
a_list = [int(a) for a in input().split()]

print(distinct_or_not(a_list))

Fixed submission:
def distinct_or_not_2(a_list):
    a_list.sort()
    for i in range(len(a_list)-1):
        if a_list[i] == a_list[i+1]:
            return 'NO'
    return 'YES'

n = int(input())
a_list = [int(a) for a in input().split()]

print(distinct_or_not_2(a_list))
Buggy python submission (verdict: Time Limit Exceeded):
def handstand2(n):
    c = 0
    for i in range(10):
        for j in range(10):
            c_i_j = 0
            c_j_i = 0
            for k in range(n):
                if str(k+1)[0] == str(i) and str(k+1)[-1] == str(j):
                    c_i_j += 1
                if str(k+1)[0] == str(j) and str(k+1)[-1] == str(i):
                    c_j_i += 1
            c += c_i_j * c_j_i
    return c

n = int(input())

print(handstand2(n))

Fixed submission:
def handstand2(n):
    c = 0
    c_list = [[0 for j in range(10)] for i in range(10)]

    for k in range(n):
        c_list[int(str(k+1)[0])][int(str(k+1)[-1])] += 1

    for i, _ in enumerate(c_list):
        for j, c_i_j in enumerate(_):
            c += c_i_j*c_list[j][i]
    return c

n = int(input())

print(handstand2(n))
Buggy python submission (verdict: Time Limit Exceeded):
def xor_sum(a):
    sum = 0
    d = 10**9+7
    for i in range(60):
        n_0 = 0
        n_1 = 0
        for j in a:
            if str(format(j, 'b')).zfill(60)[i] == '0':
                n_0 += 1
            else:
                n_1 += 1
        sum += (pow(2, 59-i)*(n_0*n_1))%d
    print(sum%d)

n = int(input())
a = [int(i) for i in input().split()]

xor_sum(a)

Fixed submission:
def xor_sum(a):
    sum = 0
    d = 10**9+7
    new_a = []
    for j in a:
        new_a.append(str(format(j, 'b')).zfill(60))
    for i in range(60):
        n_0 = 0
        n_1 = 0
        for j in new_a:
            if j[i] == '0':
                n_0 += 1
            else:
                n_1 += 1
        sum += (pow(2, 59-i)*(n_0*n_1))%d
    print(sum%d)

n = int(input())
a = [int(i) for i in input().split()]

xor_sum(a)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())

poypoyo = 'po'
for i in range(1000):
    for j in range(100000):
        if i**5 - j**5 == x:
            print(i,j)
            quit()
            break
        if i**5 - (-j)**5 ==x:
            print(i,-j)
            quit()
            break
        po = 'po'
        poypoyo += po



Fixed submission:
x = int(input())
for i in range(1000):
    for j in range(1000):
        if i**5 - j**5 == x:
            print(i,j)
            quit()
            break
        if i**5 - (-j)**5 ==x:
            print(i,-j)
            quit()
            break
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = []
for i in range(n):
    s = input()
    if s not in l:
        l.append(s)
print(len(l))


Fixed submission:
n = int(input())
l = set()
for i in range(n):
    s = input()
    if s not in l:
        l.add(s)
print(len(l))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = []
for i in range(n):
    s = input()
    if s not in l:
        l.append(s)
print(len(l))

Fixed submission:
n = int(input())
l = set()
for i in range(n):
    s = input()
    if s not in l:
        l.add(s)
print(len(l))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

divisor = [N]
ans = 0

#Nの約数の列挙
for i in range(2,N+1,1):
    if i*i <= N:
        if N % i == 0:
            divisor.append(i)
            divisor.append(N//i)
    else:
        break

#N-1の約数の列挙
yakusuuu = [N-1]
for i in range(2,N,1):
    if i*i <= N:
        if N % i == 1:
            yakusuuu.append(i)
            yakusuuu.append((N-1)//i)

for i in yakusuuu:
    if N % i == 1:
        ans += 1

#print(divisor)
#print(yakusuuu)

n=N

for K in divisor:
    #print(K)
    for i in range(N):
        if n % K == 0:
            n = n//K#ここで全部N==1になっちゃう
        else:
            break
    

    if N == 1:
        ans += 1
        
    else:
        n %= K
        if n == 1:
            ans += 1 
    n =N
    
        




print(ans)


Fixed submission:
N = int(input())

divisor = [N]
ans = 0

#Nの約数の列挙
for i in range(2,N+1,1):
    if i*i < N:
        if N % i == 0:
            divisor.append(i)
            divisor.append(N//i)
    elif i*i == N:
        divisor.append(i)
    else:
        break

#N-1の約数の列挙
yakusuuu = [N-1]
for i in range(2,N,1):
    if i*i < (N-1):
        if (N - 1)% i == 0:
            yakusuuu.append(i)
            yakusuuu.append((N-1)//i)
    elif i*i == (N-1):
        yakusuuu.append(i)
    else:
        break

for i in yakusuuu:
    if N % i == 1:
        ans += 1

#print(divisor)
#print(yakusuuu)

M = N

for K in divisor:
    #print(K)
    while M % K == 0:
        M = M//K

    

    if M == 1:
        ans += 1
        
    else:
        M =  M % K
        if M == 1:
            ans += 1 
    
    M = N
        




print(ans)
Buggy python submission (verdict: Runtime Error):
h, W = map(int,input().split())
if h % 2 != 0:
    if W % 2 != 0:
        ans = ((h-1)*W//2)+(W//2+1)
else:
    ans = (h*W)//2
print(ans)

Fixed submission:
K = int(input())
list_k =1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51

print(list_k[K-1])
Buggy python submission (verdict: Runtime Error):
h, W = map(int,input().split())
if W <= 0:
    print(0)
elif h == 1:
    print(1)
elif W == 1:
    print(0)
else:
    if h % 2 != 0:
        if W % 2 != 0:
            ans = ((h-1)*W//2)+(W//2+1)
    else:
        ans = (h*W)//2
    print(ans)

Fixed submission:
h, W = map(int,input().split())
if W <= 0:
    print(0)
elif h == 1:
    print(1)
elif W == 1:
    print(1)
else:
    if h % 2 != 0:
        if W % 2 != 0:
            ans = ((h-1)*W//2)+(W//2+1)
        else:
            ans = (h*W)//2
    else:
        ans = (h*W)//2
    print(ans)

Buggy python submission (verdict: Runtime Error):
h, W = map(int,input().split())
if W <= 0:
    print(0)
else:
    if h % 2 != 0:
        if W % 2 != 0:
            ans = ((h-1)*W//2)+(W//2+1)
    else:
        ans = (h*W)//2
    print(ans)

Fixed submission:
h, W = map(int,input().split())
if W <= 0:
    print(0)
elif h == 1:
    print(1)
elif W == 1:
    print(1)
else:
    if h % 2 != 0:
        if W % 2 != 0:
            ans = ((h-1)*W//2)+(W//2+1)
        else:
            ans = (h*W)//2
    else:
        ans = (h*W)//2
    print(ans)

Buggy python submission (verdict: Runtime Error):
h, W = map(int,input().split())
if h % 2 != 0:
    if W % 2 != 0:
        ans = ((h-1)*W//2)+(W//2+1)
else:
    ans = (h*W)//2
print(ans)

Fixed submission:
h, W = map(int,input().split())
if W <= 0:
    print(0)
elif h == 1:
    print(1)
elif W == 1:
    print(1)
else:
    if h % 2 != 0:
        if W % 2 != 0:
            ans = ((h-1)*W//2)+(W//2+1)
        else:
            ans = (h*W)//2
    else:
        ans = (h*W)//2
    print(ans)

Buggy python submission (verdict: Runtime Error):
h, W = map(int,input().split())
if h % 2 != 0:
    if W % 2 != 0:
        ans = (h-1)*W//2+(W//2+1)
else:
    ans = (h*W)//2
print(ans)

Fixed submission:
h, W = map(int,input().split())
if W <= 0:
    print(0)
elif h == 1:
    print(1)
elif W == 1:
    print(1)
else:
    if h % 2 != 0:
        if W % 2 != 0:
            ans = ((h-1)*W//2)+(W//2+1)
        else:
            ans = (h*W)//2
    else:
        ans = (h*W)//2
    print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, M = list(map(int,input().split()))
list_a = list(map(int,input().split()))
list_b = list(map(int,input().split()))
for i in range(M):
    x, y, c = list(map(int,input().split()))
buy = []
buy.append(min(list_a) + min(list_b))
buy.append(list_a[x] + list_b[y] - c)
answer = min(buy)
print(answer)


Fixed submission:
A, B, M = list(map(int,input().split()))
list_a = list(map(int,input().split()))
list_b = list(map(int,input().split()))
buy = []
buy.append(min(list_a) + min(list_b))
for i in range(M):
    x, y, c = list(map(int,input().split()))
    buy.append(list_a[x-1] + list_b[y-1] - c)
answer = min(buy)
print(answer)

Buggy python submission (verdict: Runtime Error):
A, B, M = list(map(int,input().split()))
list_a = list(map(int,input().split()))
list_b = list(map(int,input().split()))
for i in range(M):
    x, y, c = list(map(int,input().split()))
buy = []
buy.append(min(list_a) + min(list_b))
buy.append(list_a[x] + list_b[y] - c)
answer = min(buy)
print(answer, buy)


Fixed submission:
A, B, M = list(map(int,input().split()))
list_a = list(map(int,input().split()))
list_b = list(map(int,input().split()))
buy = []
buy.append(min(list_a) + min(list_b))
for i in range(M):
    x, y, c = list(map(int,input().split()))
    buy.append(list_a[x-1] + list_b[y-1] - c)
answer = min(buy)
print(answer)
Buggy python submission (verdict: Runtime Error):
N, K, S = map(int,input().split())
ans = []
if N == K:
    for i in range(s):
        ans.append(K)
    print(ans)
    quit()

if S % 2 == 0:
    for i in range(K+1):
        ans.append(S//2)
    for i in range(N-K-1):
        ans.append(S+1)
    print(' '.join(map(str,ans)))
else:
    for i in range((K+1)//2):
        ans.append(S//2+1)
        ans.append(S//2)
    if K % 2 == 0:
        ans.append(S//2+1)
        for j in range(N-((K+1)//2+1)-1):
            ans.append(S+1)
    else:
        for j in range(N-((K+1)//2)-1):
            ans.append(S+1)
    print(' '.join(map(str,ans)))


Fixed submission:
N, K, S = map(int,input().split())
ans = []


for i in range(K):
    ans.append(S)
if S == 10**9:
    for j in range(N-K):
        ans.append(7)
else:
    for j in range(N-K):
        ans.append(S+1)
print(' '.join(map(str,ans)))
Buggy python submission (verdict: Runtime Error):

K, X = input().strip().split()
K, X = [int(K), int(X)]
sougaku = 500*K
if sougaku >= X:
    print('Yes')
    else:
        print('No')

Fixed submission:

K, X =  map(int, input(). split())
sougaku = 500*K
if sougaku >= X:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):

K, X = input().strip().strip()
sougaku = 500*K
if sougaku >= X
    print('Yes')
    else
    print('No')

Fixed submission:

K, X =  map(int, input(). split())
sougaku = 500*K
if sougaku >= X:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l_s = list(map(int,input().split()))
l_s.append(0)
l_s.sort()
ans = 0
#一番長い辺を選ぶ
#print(l_s)
for j in range(2,n):
    for i in range(j+1,n+1):
        if l_s[i] < l_s[j] + l_s[j-1]:
            
            OK = j-1
            NG = 0
            while (OK - NG) > 1:
                mid = (OK+NG)//2
                if l_s[i] < l_s[j] + l_s[mid]:
                    OK = mid
                else:
                    NG = mid
            ans = ans + j - OK 
print(ans)



Fixed submission:
n = int(input())
l_s = list(map(int,input().split()))
l_s.append(0)
l_s.sort()
ans = 0
#一番長い辺を選ぶ
#print(l_s)
for j in range(2,n):
    for i in range(j+1,n+1):
        if l_s[i] < l_s[j] + l_s[j-1]:
            
            OK = j-1
            NG = 0
            while (OK - NG) > 1:
                mid = (OK+NG)//2
                if l_s[i] < l_s[j] + l_s[mid]:
                    OK = mid
                else:
                    NG = mid
            ans = ans + j - OK 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l_s = list(map(int,input().split()))
l_s.append(0)
l_s.sort()
ans = 0
#一番長い辺を選ぶ
#print(l_s)
for i in range(3,n+1):
    for j in range(2,i):
        if l_s[i] < l_s[j] + l_s[j-1]:
            
            OK = j-1
            NG = 0
            while (OK - NG) > 1:
                mid = (OK+NG)//2
                if l_s[i] < l_s[j] + l_s[mid]:
                    OK = mid
                else:
                    NG = mid
            ans = ans + j - OK 
print(ans)



Fixed submission:
n = int(input())
l_s = list(map(int,input().split()))
l_s.append(0)
l_s.sort()
ans = 0
#一番長い辺を選ぶ
#print(l_s)
for j in range(2,n):
    for i in range(j+1,n+1):
        if l_s[i] < l_s[j] + l_s[j-1]:
            
            OK = j-1
            NG = 0
            while (OK - NG) > 1:
                mid = (OK+NG)//2
                if l_s[i] < l_s[j] + l_s[mid]:
                    OK = mid
                else:
                    NG = mid
            ans = ans + j - OK 
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
#頂点iのindexは[i-1]
tree = []
for i in range(N):
    tree.append([])

#Wが0なら偶数、1なら奇数
for i in range(N-1):
    u, v, w = map(int,input().split())
    tree[v-1].append([u-1,w % 2])
    tree[u-1].append([v-1,w % 2])
    
#print(tree)

    
color = []
for i in range(N):
    color.append(0)
    color[0] = 1
#白=-1、黒=1、無色=0

distance = 0

def poyo(x):
    global tree
    global color
    for i in tree[x]:#その頂点から行ける頂点を一覧
        if color[i[0]] == 0:#iもリスト([0]が行ける頂点、[1]が距離)
            if i[1] == 0:
                color[i[0]] = color[x]
            else:
                color[i[0]] = color[x] * (-1)
            
            poyo(i[0])


poyo(0)

for i in color:
    if i == -1:
        i = 0
        
    print(i)







Fixed submission:
import sys
sys.setrecursionlimit(10**6)


N = int(input())
#頂点iのindexは[i-1]
tree = []
for i in range(N):
    tree.append([])

#Wが0なら偶数、1なら奇数
for i in range(N-1):
    u, v, w = map(int,input().split())
    tree[v-1].append([u-1,w % 2])
    tree[u-1].append([v-1,w % 2])
    
#print(tree)

    
color = []
for i in range(N):
    color.append(0)
    color[0] = 1
#白=-1、黒=1、無色=0

distance = 0

def poyo(x):
    global tree
    global color
    for i in tree[x]:#その頂点から行ける頂点を一覧
        if color[i[0]] == 0:#iもリスト([0]が行ける頂点、[1]が距離)
            if i[1] == 0:
                color[i[0]] = color[x]
            else:
                color[i[0]] = color[x] * (-1)
            
            poyo(i[0])


poyo(0)

for i in color:
    if i == -1:
        i = 0
        
    print(i)