Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
X ,Y ,A ,B ,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
p = p[:X]
q = q[:Y]
p.extend(q)
p.sort()
for i in range(C) :
    if p[i] < r[i]:
        p[i] = r[i]
    else:
        pass
print(sum(p))

Fixed submission:
X ,Y ,A ,B ,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
p = p[:X]
q = q[:Y]
p.extend(q)
p.sort()
if X+Y > C:
    for i in range(C) :
        if p[i] < r[i]:
            p[i] = r[i]
        else:
            pass
else:
    for i in range(X+Y) :
        if p[i] < r[i]:
            p[i] = r[i]
        else:
            pass
print(sum(p))
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
a = (N*(N-1))/2
b = (M*(M-1))/2
print(a+b

Fixed submission:
N, M = map(int,input().split())
a = (N*(N-1))/2
b = (M*(M-1))/2
print(int(a+b))

Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split()))
a = (N*(N-1))/2
b = (M*(M-1))/2
print(a+b

Fixed submission:
N, M = map(int,input().split())
a = (N*(N-1))/2
b = (M*(M-1))/2
print(int(a+b))
Buggy python submission (verdict: Runtime Error):
S = input()
cnt = 0
N = len(S)
for i in range(int((N-3)/2)):
    if S[i] == S[N-i-1]:
        cnt += 1
    else:
        pass
if cnt == (N-3)/2 and S % 4 != 1:
    print("Yes")
else:
    print("No")

Fixed submission:
S = input()
N = len(S)
cnt = 0
S1 = S[:int((N-1)/2)]
S2 = S[int((N+1)/2):]
if S == S[::-1] and S1 == S1[::-1] and S2 == S2[::-1]:
    print("Yes")
else :
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
nums = list(map(int,input().split()))
x = [0] * N
ans = 0
for i in range(N):
    x[nums[i] - 1] += 1
for u in  range(N):
    x[nums[u] - 1] -= 1
    for i in range(N):
        ans += (x[i]*(x[i]-1))/2
    print(int(ans))
    x[nums[u] - 1] += 1
    ans = 0

Fixed submission:
N = int(input())
nums = list(map(int,input().split()))
x = [0] * N
ans = 0
for i in range(N):
    x[nums[i] - 1] += 1
for i in range(N):
    ans += (x[i]*(x[i]-1))/2
ans = int(ans)    
for i in range(N):
    if x[nums[i] - 1] == 0 or x[nums[i] - 1] ==1:
        print(ans)
    else:
        print(ans - x[nums[i]-1] + 1)
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
if H % 2 == 1 and W % 2 ==1:
  print(int((H*W+1)/2))
elif H == 1 or W ==1:
    print(1)
elif H ==0 or W == 0:
    print(0)    
else:
  print(int((H*W)/2))

Fixed submission:
a =[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]
K = int(input())
print(a[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S = deque(input())
Q = int(input())
for i in range(Q):
    TFC = input()
    if TFC == "1":
        S.reverse()
    else:
        if TFC[:3]== "2 1":
            S.appendleft(TFC[4])
        else:
            S.append(TFC[4])
print("".join([i for i in S]))

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
cnt = 1
num = 0
for i in range(Q):
    TFC = input()
    if TFC == "1":
        cnt *= -1
        num += 1
    else:
        if TFC[:3]== "2 1":
            if cnt ==1:
                S.appendleft(TFC[4])
            else:
                S.append(TFC[4])
        else:
            if cnt ==1:
                S.append(TFC[4])
            else:
                S.appendleft(TFC[4])
if num % 2 ==1:
    print(("".join(reversed([i for i in S]))))
else:
    print(("".join([i for i in S])))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S = deque(input())
Q = int(input())
for i in range(Q):
    TFC = input()
    if TFC == "1":
        S.reverse()
    else:
        if TFC[:3]== "2 1":
            S.appendleft(TFC[4])
        else:
            S.append(TFC[4])
print("".join([i for i in S]))

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
cnt = 1
num = 0
for i in range(Q):
    TFC = input()
    if TFC == "1":
        cnt *= -1
        num += 1
    else:
        if TFC[:3]== "2 1":
            if cnt ==1:
                S.appendleft(TFC[4])
            else:
                S.append(TFC[4])
        else:
            if cnt ==1:
                S.append(TFC[4])
            else:
                S.appendleft(TFC[4])
if num % 2 ==1:
    print(("".join(reversed([i for i in S]))))
else:
    print(("".join([i for i in S])))
Buggy python submission (verdict: Runtime Error):
N ,M = map(int,input().split())
cnt = [0]*M
C = [0]*M
for i in range(M):
    s, c = map(int,input().split())
    if cnt == 1 and C[s-1] != c:
        cnt[s-1] += 1
    elif cnt[s-1] == 1 and C[s-1] == c:
        pass
    else:
        cnt[s-1] += 1
        C[s-1] = c
if max(cnt)>=2 or C[0] == 0 :
    print(-1)
else:
    print("".join(map(str,C)))

Fixed submission:
N ,M = map(int,input().split())
cnt = [0]*N
C = [0]*N
C[0] = 1
for i in range(M):
    s, c = map(int,input().split())
    if cnt == 1 and C[s-1] != c:
        cnt[s-1] += 1
    elif cnt[s-1] == 1 and C[s-1] == c:
        pass
    else:
        cnt[s-1] += 1
        C[s-1] = c
if N ==1 and C[0] == 0:
    print(0)
elif N ==1 and M == 0:
    print(0)
elif max(cnt)>=2 or C[0] == 0 :
    print(-1)
else:
    print("".join(map(str,C)))

Buggy python submission (verdict: Runtime Error):
N ,M = map(int,input().split())
cnt = [0]*M
C = [0]*M
for i in range(M):
    s, c = map(int,input().split())
    if c == C[s-1]:
        pass
    else:
        C[s-1] += c
        cnt[s-1] += 1

if max(cnt)>=2 or C[0] == 0   :
    print(-1)
else:
    print("".join(map(str,C)))

Fixed submission:
N ,M = map(int,input().split())
cnt = [0]*N
C = [0]*N
C[0] = 1
for i in range(M):
    s, c = map(int,input().split())
    if cnt == 1 and C[s-1] != c:
        cnt[s-1] += 1
    elif cnt[s-1] == 1 and C[s-1] == c:
        pass
    else:
        cnt[s-1] += 1
        C[s-1] = c
if N ==1 and C[0] == 0:
    print(0)
elif N ==1 and M == 0:
    print(0)
elif max(cnt)>=2 or C[0] == 0 :
    print(-1)
else:
    print("".join(map(str,C)))
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=int(input())
flag=1
for i in range(n):
    l=list(input().split())
    if len(l)==1:
        flag*=(-1)
    elif l[1]=="1" and flag==1 or l[1]=="2" and flag==-1:
        s=l[2]+s
    else:s+=l[2]
if flag==-1:print(s[::-1])
else:print(s)

Fixed submission:
s=input()
n=int(input())
flag=1
left=""
right=""
for i in range(n):
    l=list(input().split())
    if len(l)==1:
        flag*=(-1)
    elif l[1]=="1" and flag==1 or l[1]=="2" and flag==-1:
        left+=l[2]
    else:right+=l[2]
s=left[::-1]+s+right
if flag==-1:print(s[::-1])
else:print(s)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
ans=0
MOD=10**9+7
la=[0 for i in range(61)]
for i in range(61):
    la[60-i]=sum([j//2**(60-i) for j in l])
    l=[j%2**(60-i) for j in l]
for num,i in enumerate(la):
    ans+=2**num*i*(n-i)
    ans%=MOD
print(ans)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
l=[format(i,"b").zfill(61) for i in l]
ans=0
MOD=10**9+7
la=[0 for i in range(61)]
for i in l:
    for num,j in enumerate(str(i)):
        if j=="1":
            la[60-num]+=1
for num,i in enumerate(la):
    ans+=2**num*i*(n-i)
    ans%=MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
ans=0
MOD=10**9+7
for i in l:
    for j in l:
        ans+=i^j
print(ans//2%MOD)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
l=[format(i,"b").zfill(61) for i in l]
ans=0
MOD=10**9+7
la=[0 for i in range(61)]
for i in l:
    for num,j in enumerate(str(i)):
        if j=="1":
            la[60-num]+=1
for num,i in enumerate(la):
    ans+=2**num*i*(n-i)
    ans%=MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools
import math
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
ans=0
it=list(itertools.permutations(range(8),8))
for i in it:
    tmpx=l[i[0]][0]
    tmpy=l[i[0]][1]
    tmp=0
    for j in i[1:]:
        tmp+=math.sqrt((tmpx-l[j][0])**2+(tmpy-l[j][1])**2)
        tmpx=l[j][0]
        tmpy=l[j][1]
    ans+=tmp
print(ans/math.factorial(n))

Fixed submission:
import itertools
import math
n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
ans=0
it=list(itertools.permutations(range(n),n))
for i in it:
    tmpx=l[i[0]][0]
    tmpy=l[i[0]][1]
    tmp=0
    for j in i[1:]:
        tmp+=math.sqrt((tmpx-l[j][0])**2+(tmpy-l[j][1])**2)
        tmpx=l[j][0]
        tmpy=l[j][1]
    ans+=tmp
print(ans/math.factorial(n))
Buggy python submission (verdict: Time Limit Exceeded):
import math
def modpow(a,b,MOD):#a**b(MOD)
    if b == 0:
        return 1
    if b%2:
        return a*modpow(a**2%MOD,b//2,MOD)%MOD
    else:
        return modpow(a**2%MOD,b//2,MOD)
MOD=998244353
n=int(input())
l=list(map(int,input().split()))
if l[0]!=0:
    print(0)
    exit()
else:
    l=l[1:]
if 0 in l:
    print(0)
    exit()
ans=1
tmp=1
for i in range(1,max(l)+1):
    c=l.count(i)
    if c==0:
        print(0)
        exit()
    ans*=modpow(tmp,c,MOD)
    ans%=MOD
    tmp=c
print(ans)

Fixed submission:
import math
import collections
def modpow(a,b,MOD):#a**b(MOD)
    if b == 0:
        return 1
    if b%2:
        return a*modpow(a**2%MOD,b//2,MOD)%MOD
    else:
        return modpow(a**2%MOD,b//2,MOD)
MOD=998244353
n=int(input())
l=list(map(int,input().split()))
if l[0]!=0:
    print(0)
    exit()
else:
    l=l[1:]
if 0 in l:
    print(0)
    exit()
cl=collections.Counter(l)
ans=1
tmp=1
for i in range(1,max(l)+1):
    c=cl[i]
    if c==0:
        print(0)
        exit()
    ans*=modpow(tmp,c,MOD)
    ans%=MOD
    tmp=c
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
def modpow(a,b,MOD):#a**b(MOD)
    if b == 0:
        return 1
    if b%2:
        return a*modpow(a**2%MOD,b//2,MOD)%MOD
    else:
        return modpow(a**2%MOD,b//2,MOD)
def modinv(a,MOD):
    return modpow(a,MOD-2,MOD)
MOD=998244353
n=int(input())
l=list(map(int,input().split()))
if l[0]!=0:
    print(0)
    exit()
else:
    l=l[1:]
if 0 in l:
    print(0)
    exit()
ans=1
tmp=1
for i in range(1,max(l)+1):
    c=l.count(i)
    ans*=modpow(tmp,c,MOD)
    ans%=MOD
    tmp=c
print(ans)

Fixed submission:
import math
import collections
def modpow(a,b,MOD):#a**b(MOD)
    if b == 0:
        return 1
    if b%2:
        return a*modpow(a**2%MOD,b//2,MOD)%MOD
    else:
        return modpow(a**2%MOD,b//2,MOD)
MOD=998244353
n=int(input())
l=list(map(int,input().split()))
if l[0]!=0:
    print(0)
    exit()
else:
    l=l[1:]
if 0 in l:
    print(0)
    exit()
cl=collections.Counter(l)
ans=1
tmp=1
for i in range(1,max(l)+1):
    c=cl[i]
    if c==0:
        print(0)
        exit()
    ans*=modpow(tmp,c,MOD)
    ans%=MOD
    tmp=c
print(ans)
Buggy python submission (verdict: Runtime Error):
    n=int(input())
    for i in range(1,10):
        if n/i ==n//i and n//i<=9:
            print("Yes")
            exit()
    print("No")

Fixed submission:
n=int(input())
for i in range(1,10):
    if n/i ==n//i and n//i<=9:
        print("Yes")
        exit()
print("No")

Buggy python submission (verdict: Runtime Error):
n=int(input())
for i in range(1:9)n=int(input())
for i in range(1,9):
    if n/i ==n//i and n//i<=9:
        print("Yes")
        exit()
print("No")

Fixed submission:
n=int(input())
for i in range(1,10):
    if n/i ==n//i and n//i<=9:
        print("Yes")
        exit()
print("No")
Buggy python submission (verdict: Runtime Error):
import math
a,b,v=map(int,input().split())
theta1=0
theta2=math.pi/2
ans=10**9
if a*a*b/2>=v:
    while 1:
        tmp=math.tan((theta1+theta2)/2)-2*v/(a*b*b)
        if abs(tmp)<=10**(-6):
            ans=(theta1+theta2)/2
            break
        else:
            if tmp>0:
                theta2=(theta1+theta2)/2
            else:
                theta1=(theta1+theta2)/2
else:
    while 1:
        tmp=math.tan((theta1+theta2)/2)-(a**3)/(2*(a*a*b-v))
        if abs(tmp)<=10**(-6):
            ans=(theta1+theta2)/2
            break
        else:
            if tmp>0:
                theta2=(theta1+theta2)/2
            else:
                theta1=(theta1+theta2)/2
print(90-math.degrees(ans))

Fixed submission:
import math
a,b,v=map(int,input().split())
theta1=0
theta2=math.pi/2
ans=10**9
if a*a*b-v==0:
    print(0)
    exit()
if a*a*b/2>=v:
    while 1:
        tmp=math.tan((theta1+theta2)/2)-2*v/(a*b*b)
        if abs(tmp)<=10**(-6):
            ans=(theta1+theta2)/2
            break
        else:
            if tmp>0:
                theta2=(theta1+theta2)/2
            else:
                theta1=(theta1+theta2)/2
else:
    while 1:
        tmp=math.tan((theta1+theta2)/2)-(a**3)/(2*(a*a*b-v))
        if abs(tmp)<=10**(-6):
            ans=(theta1+theta2)/2
            break
        else:
            if tmp>0:
                theta2=(theta1+theta2)/2
            else:
                theta1=(theta1+theta2)/2
print(90-math.degrees(ans))
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(map(int,input().split()))
a=0
l,r=0,1
while 1:
    if s[r-1]>=s[r]:
        a=max(a,r-l)
        r+=1
    else:
        l=r
        r=l+1
    if r==n:break
print(a)

Fixed submission:
n=int(input())
if n==1:print(0);exit()
s=list(map(int,input().split()))
a=0
l,r=0,1
while 1:
    if s[r-1]>=s[r]:
        a=max(a,r-l)
        r+=1
    else:
        l=r
        r=l+1
    if r==n:break
print(a)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
la=list(map(int,input().split()))

flag=0
for m,i in enumerate(la):
  ans+=min(i,l[m])+l[m+1]-max(0,l[m+1]-i+min(i,l[m]))
  l[m+1]=max(0,l[m+1]-i+min(i,l[m]))
print(ans)


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

ans=0
for m,i in enumerate(la):
  ans+=min(i,l[m])+l[m+1]-max(0,l[m+1]-i+min(i,l[m]))
  l[m+1]=max(0,l[m+1]-i+min(i,l[m]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,input().split())
lst=[]
for i in range(l,l+min(4038,r-l+1)):
    lst.append(i%2019)
ans=2018
for i in range(len(lst)-1):
    for j in range(i+1,len(lst)):
        tmp=lst[i]*lst[j]%2019
        if tmp<ans:ans=tmp
print(ans)

Fixed submission:
l,r=map(int,input().split())
if r-l>2019:
    print(0)
    exit()
lst=[]
for i in range(l,l+min(4038,r-l+1)):
    lst.append(i%2019)
ans=2018
for i in range(len(lst)-1):
    for j in range(i+1,len(lst)):
        tmp=lst[i]*lst[j]%2019
        if tmp<ans:ans=tmp
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
  if l[i-1]<l[i]<l[i+1] or l[i+1]<l[i]<l[i-1]
   ans+=1 
 print(ans)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
  if l[i-1]<l[i]<l[i+1] or l[i+1]<l[i]<l[i-1]:
   ans+=1 
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
def modpow(a,b,MOD):
    if b == 0:
        return 1
    if b%2:
        return a*modpow(a**2%MOD,b//2,MOD)%MOD
    else:
        return modpow(a**2%MOD,b//2,MOD)
def modinv(a,MOD):
    return modpow(a,MOD-2,MOD)
def modcomb(n,r,MOD):
    return math.factorial(n)%MOD*modinv(math.factorial(r),MOD)%MOD*modinv(math.factorial(n-r),MOD)%MOD

MOD=10**9+7
n,k=map(int,input().split())
for i in range(1,k+1):
    print((modcomb(n-k+1,i,MOD)*modcomb(k-1,k-i,MOD))%MOD)

Fixed submission:
import math
def modpow(a,b,MOD):
    if b == 0:
        return 1
    if b%2:
        return a*modpow(a**2%MOD,b//2,MOD)%MOD
    else:
        return modpow(a**2%MOD,b//2,MOD)
def modinv(a,MOD):
    return modpow(a,MOD-2,MOD)
def modcomb(n,r,MOD):
    return math.factorial(n)%MOD*modinv(math.factorial(r),MOD)%MOD*modinv(math.factorial(n-r),MOD)%MOD

MOD=10**9+7
n,k=map(int,input().split())
for i in range(1,k+1):
    if n-k+1<i:print(0)
    else:print((modcomb(n-k+1,i,MOD)*modcomb(k-1,k-i,MOD))%MOD)
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
lcm = int(c*d/math.gcd(c,d))
def num(x):
    return(b//x-(a-1)//x)
ans = (b-a+1)-num(c)-num(d)+num(lcm)
print(int(ans))

Fixed submission:
def gcd(x, y):
    if y == 0: return x
    return gcd(y, x%y)

a,b,c,d = map(int,input().split())
lcm = int(c*d/gcd(c,d))
def num(x):
    return(b//x-(a-1)//x)
ans = (b-a+1)-num(c)-num(d)+num(lcm)
print(int(ans))
Buggy python submission (verdict: Runtime Error):
    l = sorted(list(map(int,input().split())))
    print(l[0]+l[1])

Fixed submission:
l = sorted(list(map(int,input().split())))
print(l[0]+l[1])

Buggy python submission (verdict: Runtime Error):
l = sorted.list(map(int,input().split()))
print(l[0]+l[1])

Fixed submission:
l = sorted(list(map(int,input().split())))
print(l[0]+l[1])
Buggy python submission (verdict: Runtime Error):
A,B = map(int(input().split()))
if A>=13:
  print(B)
elif A>=6:
  print(B/2)
else:
  print(0)

Fixed submission:
A,B = map(int,input().split())
if A>=13:
  print(B)
elif A>=6:
  print(int(B/2))
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
A,B = map(int(input().split()))
if A>=13:
  print(B)
elif A>=6
  print(B/2)
else
  print(0)

Fixed submission:
A,B = map(int,input().split())
if A>=13:
  print(B)
elif A>=6:
  print(int(B/2))
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
A,B = map(int(input().split()))
if A>=13:
  print(B)
elif A>=6
  print(B/2)
else
print(0)

Fixed submission:
A,B = map(int,input().split())
if A>=13:
  print(B)
elif A>=6:
  print(int(B/2))
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
for i in range(M):
    l,r = map(int,input().split())
    if i == 0:
        set_a = set(list(range(l,r+1)))
    set_b = set(list(range(l,r+1)))
    set_a = set_a & set_b
print(len(set_a))

Fixed submission:
N,M = map(int,input().split())
lst_l=[]
lst_r=[]
for i in range(M):
    l,r = map(int,input().split())
    lst_l.append(l)
    lst_r.append(r)
ans = min(lst_r)-max(lst_l)+1
if ans >=0:print(ans)
else:print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
c=[[] for i in range(n+1)]
d=[[float("inf")]*(n+1) for i in range(n+1)]
for i in range(n-1):
    x,y,z=map(int,input().split())
    c[x].append(y)
    c[y].append(x)
    d[x][y]=z%2
    d[y][x]=z%2
stack=[1]
color=[-1]*(n+1)
color[1]=0
parent=[None]*(n+1)
append=stack.append
while stack:
    i=stack.pop()
    for j in c[i]:
        if j==parent[i]:
            continue
        color[j]=(color[i]+d[i][j])%2
        parent[j]=i
        append(j)
print("\n".join(map(str,color[1:])))

Fixed submission:
n=int(input())
c=[[] for i in range(n+1)]
d={}
for i in range(n-1):
    x,y,z=map(int,input().split())
    c[x].append(y)
    c[y].append(x)
    d[x,y]=z
d[1,1]=0
stack=[1]
parent=[None]*(n+1)
while stack:
    i=stack.pop()
    for j in c[i]:
        if j==parent[i]:
            continue
        parent[j]=i
        d[1,j]=d[1,i]+d[tuple(sorted([i,j]))]
        stack.append(j)
for i in range(1,n+1):
    print(d[1,i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

################################
n = int(input())

cost = [[float("inf") for i in range(n)] for i in range(n)] 
#cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
for i in range(n-1):
    x,y,z = map(int,input().split())
    cost[x-1][y-1] = z
    cost[y-1][x-1] = z
dks=dijkstra(0,n,n-1,cost)
for i in dks:
    if i%2==0:print(0)
    else:print(1)

Fixed submission:
n=int(input())
c=[[] for i in range(n+1)]
d={}
for i in range(n-1):
    x,y,z=map(int,input().split())
    c[x].append(y)
    c[y].append(x)
    d[x,y]=z
d[1,1]=0
stack=[1]
parent=[None]*(n+1)
while stack:
    i=stack.pop()
    for j in c[i]:
        if j==parent[i]:
            continue
        parent[j]=i
        d[1,j]=d[1,i]+d[tuple(sorted([i,j]))]
        stack.append(j)
for i in range(1,n+1):
    print(d[1,i]%2)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=list(input())
l,tmpl,cnt0,tmp,flag=[],0,0,s[0],0
if tmp=="0":cnt0+=1;flag=1
for i in s:
    if i==tmp:tmpl+=1
    else:
        if i=="0":cnt0+=1
        tmp=i
        l.append(tmpl)
        tmpl=1
l.append(tmpl)
if cnt0<=k:print(n);exit()
ans=max(sum(l[:2*k]),sum(l[::-1][:2*k]))
suml,tmp=[0],0
if flag==1:l=l[1:]
for i in l:
    tmp+=i
    suml.append(tmp)
for i in range((len(suml)-2*k-1)//2+1):
    tmp=suml[2*k+2*i+1]-suml[2*i]
    if tmp>ans:ans=tmp
print(ans)

Fixed submission:
n,k=map(int,input().split())
s=list(input())
l,tmpl,cnt0,tmp,flag1,flag2=[],0,0,s[0],0,0
if tmp=="0":cnt0+=1;flag1=1
for i in s:
    if i==tmp:tmpl+=1
    else:
        if i=="0":cnt0+=1
        tmp=i
        l.append(tmpl)
        tmpl=1
if tmp=="0":flag2=1
l.append(tmpl)
if cnt0<=k:print(n);exit()
ans=max(sum(l[:2*k]),sum(l[::-1][:2*k]))
suml,tmp=[0],0
if flag1==1:l=l[1:]
if flag2==1:l=l[:len(l)-1]
for i in l:
    tmp+=i
    suml.append(tmp)
for i in range((len(suml)-2*k-1)//2+1):
    tmp=suml[2*k+2*i+1]-suml[2*i]
    if tmp>ans:ans=tmp
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=list(input())
l,tmpl,cnt0,tmp,flag=[],0,0,s[0],0
if tmp=="0":cnt0+=1;flag=1
for i in s:
    if i==tmp:tmpl+=1
    else:
        if i=="0":cnt0+=1
        tmp=i
        l.append(tmpl)
        tmpl=1
l.append(tmpl)
if cnt0<=k:print(n);exit()
ans=max(sum(l[:2*k]),sum(l[::-1][:2*k]))
suml,tmp=[0],0
if flag==1:l=l[1:]
for i in l:
    tmp+=i
    suml.append(tmp)
for i in range((len(suml)-2*k-1)//2+1):
    tmp=suml[2*k+2*i+1]-suml[2*i]
    print(tmp)
    if tmp>ans:ans=tmp
print(ans)

Fixed submission:
n,k=map(int,input().split())
s=list(input())
l,tmpl,cnt0,tmp,flag1,flag2=[],0,0,s[0],0,0
if tmp=="0":cnt0+=1;flag1=1
for i in s:
    if i==tmp:tmpl+=1
    else:
        if i=="0":cnt0+=1
        tmp=i
        l.append(tmpl)
        tmpl=1
if tmp=="0":flag2=1
l.append(tmpl)
if cnt0<=k:print(n);exit()
ans=max(sum(l[:2*k]),sum(l[::-1][:2*k]))
suml,tmp=[0],0
if flag1==1:l=l[1:]
if flag2==1:l=l[:len(l)-1]
for i in l:
    tmp+=i
    suml.append(tmp)
for i in range((len(suml)-2*k-1)//2+1):
    tmp=suml[2*k+2*i+1]-suml[2*i]
    if tmp>ans:ans=tmp
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = str(input())
lstr=[]
lstl=[]
for i in range(Q):
    r,l = map(int,input().split())
    snp = S[r-1:l]
    snp_new = snp.replace("AC",'')
    ans = (len(snp)-len(snp_new))/2
    print(int(ans))

Fixed submission:
n,q=map(int,input().split())
s=input()
l=[0]*n
tmp="hoge"
for i,j in enumerate(s):
    if j=="C" and tmp=="A":
        l[i]=1
    tmp=s[i]
ls=[0]
tmp=0
for i in l:
    tmp+=i
    ls.append(tmp)
for i in range(q):
    a,b=map(int,input().split())
    print(ls[b]-ls[a])
Buggy python submission (verdict: Runtime Error):
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = []
ans = 0
for i in range(n):
    arr = list(map(int,input().split()))
    a.append(arr)
for i in a:
    tmp = c
    for j in range(n+1):
        tmp += i[j]*b[j]
    if tmp > 0:ans+=1
print(ans)

Fixed submission:
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = []
ans = 0
for i in range(n):
    arr = list(map(int,input().split()))
    a.append(arr)
for i in a:
    tmp = c
    for j in range(m):
        tmp += i[j]*b[j]
    if tmp > 0:ans+=1
print(ans)