Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())
if abs(a-b)<=1:
  print(a+b)
else:
  if a>b:
    print(a*2-1)
  else:
    print(b*2-1)
    

Fixed submission:
a,b = map(int,input().split())
if abs(a-b)<=1:
  print(a+b)
else:
  if a>b:
    print((a*2)-1)
  else:
    print((b*2)-1)
Buggy python submission (verdict: Runtime Error):
h = int(input())
mount = [int(_) for _ in input().split()]
count = 0
for i in range(h):
  if i == 0
    count += 1
  else:
    for j in range(i):
      if mount[i]<mount[j]:
        break
    else:
      count += 1
print (count)

Fixed submission:
h = int(input())
mount = [int(_) for _ in input().split()]
count = 0
for i in range(h):
  if i == 0:
    count += 1
  else:
    for j in range(i):
      if mount[i]<mount[j]:
        break
    else:
      count += 1
print (count)

Buggy python submission (verdict: Runtime Error):
h = int(input())
mount = [int(_) for _ in input().split()]
count = 0
for i in range(h):
  if i = 0:
    count += 1
  else:
    if mount[i]>mount[i-1]:
      count += 1
print (count)

Fixed submission:
h = int(input())
mount = [int(_) for _ in input().split()]
count = 0
for i in range(h):
  if i == 0:
    count += 1
  else:
    for j in range(i):
      if mount[i]<mount[j]:
        break
    else:
      count += 1
print (count)

Buggy python submission (verdict: Runtime Error):
h = int(input())
mount = [int(_) for _ in input().split()]
count = 0
for i in range(len):
  if i = 0:
    count += 1
  else:
    if mount[i]>mount[i-1]:
      count += 1
print (count)

Fixed submission:
h = int(input())
mount = [int(_) for _ in input().split()]
count = 0
for i in range(h):
  if i == 0:
    count += 1
  else:
    for j in range(i):
      if mount[i]<mount[j]:
        break
    else:
      count += 1
print (count)
Buggy python submission (verdict: Runtime Error):
order = [int(input()) for _ in range(5)]
min_digit = 0
time = 0
for i in range(len(order)):
  if order[i]%10!=0:
    time+=(order[i]//10+1)*10
  else:
    time+=order[i]

order_digit = [i%10 for i in order]
if order_digit == [0,0,0,0,0]:
  print (time-10+min_digit)
else:
  for i in range(len(order)):
    digit = order[i]%10
    if min_digit>=digit and digit!=0:
    min_digit=digit

Fixed submission:
order = [int(input()) for _ in range(5)]
min_digit = 9
time = 0
for i in range(len(order)):
  if order[i]%10!=0:
    time+=(order[i]//10+1)*10
  else:
    time+=order[i]

for i in range(len(order)):
  digit = order[i]%10
  if min_digit>=digit and digit!=0:
    min_digit=digit
    
order_digit = [i%10 for i in order]
if order_digit == [0,0,0,0,0]:
  print (time)
else:
  print (time-10+min_digit)

Buggy python submission (verdict: Runtime Error):
order = [int(input()) for _ in range(5)]

for i in range(len(order)):
  time = 0
  for j in range(len(order)-i):
    if order[j+i]%10 == 0:
    	time += order[j]
  	else:
    	time += (order[j]//10+1)*10

Fixed submission:
order = [int(input()) for _ in range(5)]
min_digit = 9
time = 0
for i in range(len(order)):
  if order[i]%10!=0:
    time+=(order[i]//10+1)*10
  else:
    time+=order[i]

for i in range(len(order)):
  digit = order[i]%10
  if min_digit>=digit and digit!=0:
    min_digit=digit
    
order_digit = [i%10 for i in order]
if order_digit == [0,0,0,0,0]:
  print (time)
else:
  print (time-10+min_digit)
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
capacity = min([int(input()) for i in range(6)])

print(math.ceil(N/capacity)+4)

Fixed submission:
import math
N = int(input())
capacity = min([int(input()) for i in range(5)])

print(math.ceil(N/capacity)+4)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, input().split())

if a=b and b=c and a=c:
  print('Yes')
else:
  print('No')

Fixed submission:
a,b,c = map(int, input().split())

if a==b and b==c and a==c:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, input().split())

if a=b and b=c and a=c:
  print('Yes')
else:
  print('No')

Fixed submission:
a,b,c = map(int, input().split())

if a==b and b==c and a==c:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, input().split())

if a=b and b=c a=c:
  print('Yes')
else:
  print('No')

Fixed submission:
a,b,c = map(int, input().split())

if a==b and b==c and a==c:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, input().split())

if a=b=c:
  print('Yes')
else:
  print('No')

Fixed submission:
a,b,c = map(int, input().split())

if a==b and b==c and a==c:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = [i for i in input().split()]

red = count('R')
blue = count('B')

if red > blue:
  print('Yes')
else:
  print ('No')

Fixed submission:
n = int(input())
s = [i for i in input()]

red = s.count('R')
blue = s.count('B')

if red > blue:
  print('Yes')
else:
  print ('No')
Buggy python submission (verdict: Runtime Error):
b = input()

if b=='A':
  print "T"
if b=='c':
  print "G"
if b=='G':
  print "C"
if b=='T':
  print "A"

Fixed submission:
b = input()

if b=='A':
  print ('T')
if b=='C':
  print ('G')
if b=='G':
  print ('C')
if b=='T':
  print ('A')
Buggy python submission (verdict: Runtime Error):
S = input()

ans = 0
ACGT = set('A','C','G','T')
for i in range(1,len(S+1)):
  j = 1
  while j*i <= len(S):
    if set(S[j:j*i]) <= ACGT:
      ans = len(S[j:j*i])
    j += 1
print (ans)

Fixed submission:
s = input()

ans=0
base = set(['A','C','G','T'])
i = 1
while i <= len(s):
    j = 0
    while j+i <= len(s):
        word = set(s[j:j+i])
        if word <= base:
            ans = len(s[j:j+i])
        j += 1
    i += 1
print (ans)

Buggy python submission (verdict: Runtime Error):
S = input()

ans = 0
ACGT = set('A','C','G','T')
for i in range(1,len(S+1)):
  j = 1
  while j*i <= S:
    if set(S[j:j*i]) <= ACGT:
      ans = len(S[j:j*i])
    j += 1
print (ans)

Fixed submission:
s = input()

ans=0
base = set(['A','C','G','T'])
i = 1
while i <= len(s):
    j = 0
    while j+i <= len(s):
        word = set(s[j:j+i])
        if word <= base:
            ans = len(s[j:j+i])
        j += 1
    i += 1
print (ans)

Buggy python submission (verdict: Runtime Error):
S = input()

ans = 0
ACGT = set('A','C','G','T')
for i in len(1,S+1):
  j = 1
  while j*i <= S:
    if set(S[j:j*i]) <= ACGT:
      ans = len(S[j:j*i])
    j += 1
print (ans)

Fixed submission:
s = input()

ans=0
base = set(['A','C','G','T'])
i = 1
while i <= len(s):
    j = 0
    while j+i <= len(s):
        word = set(s[j:j+i])
        if word <= base:
            ans = len(s[j:j+i])
        j += 1
    i += 1
print (ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()

cnt=[]
for i in range(Q):
    ans=0
    l,r = map(int,input().split())
    s = S[l-1:r]
    j = 0
    while j+2 <= len(s):
        if s[j:j+2] == 'AC':
            ans += 1
        j += 1
    cnt.append(ans)

for answer in cnt:
    print (answer)

Fixed submission:
from itertools import accumulate

N,Q = map(int,input().split())
S = input()
A = [list(map(int,input().split())) for i in range(Q)]

flg=[]
for i in range(N-1):
    s = S[i:i+2] 
    if s == 'AC':
        flg.append(1)
    else:
        flg.append(0)

flg2 = list(accumulate([0]+flg))

for a in A:
    print (flg2[a[1]-1]-flg2[a[0]-1])
Buggy python submission (verdict: Runtime Error):
N,M,C = map(int, input().split())
B = [int(_) for _ in input().split()]

count = 0
for i in range(len(N)):
  A = [int(_) for _ in input().split()] 
  sum = 0
  for j in range(M):
    sum = B[j]*A[j]
  if sum-C > 0:
    count += 1

print(count)

Fixed submission:
N,M,C = map(int, input().split())
B = [int(_) for _ in input().split()]

count = 0
for i in range(N):
  A = [int(_) for _ in input().split()] 
  sum = 0
  for j in range(M):
    sum += B[j]*A[j]
  if sum+C > 0:
    count += 1

print(count)

Buggy python submission (verdict: Runtime Error):
N,M,C = map(int, input().split())
B = [int(_) for _ in input().split()]

count = 0
for i in range(len(N)):
  A = [_ for _ in input().split()] 
  sum = 0
  for j in range(M):
    sum = B[j]*A[j]
  if sum-C > 0:
    count += 1

print(count)

Fixed submission:
N,M,C = map(int, input().split())
B = [int(_) for _ in input().split()]

count = 0
for i in range(N):
  A = [int(_) for _ in input().split()] 
  sum = 0
  for j in range(M):
    sum += B[j]*A[j]
  if sum+C > 0:
    count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp=[0]*N

for i in range(1,N):
    dp[i] = min(
        dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
    )

print(dp[N-1])

Fixed submission:
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp=[0]*N

    for i in range(1,N):
        dp[i] = min(
            dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
        )
    print(dp[N-1])
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp=[0]*N

    for i in range(1,N):
        dp[i] = min(
            dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
        )
    print(dp[N-1])
main()

Fixed submission:
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp=[0]*N

    for i in range(1,N):
        dp[i] = min(
            dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
        )
    print(dp[N-1])
main()

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

dp=[0]*N

for i in range(1,N):
    dp[i] = min(
        dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
    )

print(dp[N-1])

Fixed submission:
def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))

    dp=[0]*N

    for i in range(1,N):
        dp[i] = min(
            dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
        )
    print(dp[N-1])
main()
Buggy python submission (verdict: Runtime Error):
N=int(input())

l=list(map(int,input().split()))
l[0]-=1
switch=True

for i in range(N-1):

    if l[i+1]==l[i]:
        pass
    elif l[i+1]>l[i]:
        l[i+1]-=1
    else:
        print("No")
        Switch=False
        break
    if i==N-2:
        print("Yes")
        Switch=False
    
if Switch:
    print("No")



Fixed submission:
N=int(input())

l=list(map(int,input().split()))
l[0]-=1
Switch=True

for i in range(N-1):

    if l[i+1]==l[i]:
        pass
    elif l[i+1]>l[i]:
        l[i+1]-=1
    else:
        print("No")
        Switch=False
        break
    if i==N-2:
        print("Yes")
        Switch=False
    
if Switch:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
def resolve():
    n = int(input())
    a = list(map(int,input().split()))
    sa = list(set(a))
    num = {}

    if sum(sa)==0:
        print("Yes")
        exit(0)
    if (n%3)!=0:
        print("No")
        exit(0)
    for i in a:
        num[i] = num.get(i,0) + 1
    
    OK = False
    if len(num)>=3 and len(num)%3==0:
        i,j,k = num.values()
        if i==j and j==k and sa[0]==sa[1]^sa[2]:
            OK = True
    if(OK):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    resolve()

Fixed submission:
def resolve():
    n = int(input())
    a = list(map(int,input().split()))
    sa = list(set(a))
    num = {}

    if sum(sa)==0:
        print("Yes")
        exit(0)
    if (n%3)!=0:
        print("No")
        exit(0)
    for i in a:
        num[i] = num.get(i,0) + 1
    
    OK = False
    if len(num)==3:
        i,j,k = num.values()
        if i==j and j==k and sa[0]==(sa[1]^sa[2]):
            OK = True
    elif len(num)==2:
        i,k = num.keys()
        j,l = num.values()
        if i==0 and j*2==l:
            OK = True
        elif k==0 and l*2==j:
            OK = True
    if(OK):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
s = input()
l = list(s)
c1 = s.count(l[0])
c2 = s.count(l[1])
c3 = s.count(l[2])
c4 = s.count(l[3])
if c1 == 2 and c2 == 2 and c3 == 2 and c4 == 2:
  print('Yes')
  else:
    print('No')

Fixed submission:
s = input()
l = list(s)
c1 = s.count(l[0])
c2 = s.count(l[1])
c3 = s.count(l[2])
c4 = s.count(l[3])
if c1 == 2 and c2 == 2 and c3 == 2 and c4 == 2:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)
m = 100005
visited = [False]*(m*2)
cnt = [0,0]
def dfs(i):
    visited[i] = True
    cnt[i//m] = cnt[i//m]+1
    for j in to[i]:
        if not visited[j]:
            dfs(j)
 
input = sys.stdin.readline
n = int(input())
to = [[] for _ in range(m*2)]
for _ in range(n):
    x,y = map(int,input().split())
    y = y+m
    to[x].append(y)
    to[y].append(x)
 
ans = 0
for i in range(m):
    if not visited[i]:
        cnt = [0,0]
        dfs(i)
        ans = ans + cnt[0]*cnt[1]
 
print(ans-n)

Fixed submission:
s=input()
ans = 'Good'
last = s[0]
for i in s[1:]:
    if last==i:
        ans = 'Bad'
        break
    last = i
print(ans)

Buggy python submission (verdict: Runtime Error):
s=input()
ans = 'Good'
last = s[0]
for i in s[1:]:
    if last==i:
        ans = 'Bad'
        reak
    last = i
print(ans)

Fixed submission:
s=input()
ans = 'Good'
last = s[0]
for i in s[1:]:
    if last==i:
        ans = 'Bad'
        break
    last = i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def napzak(w,v,limit):
    dp = [0]*(limit+1)
    for i in range(1,limit+1):
        for j,value in zip(w,v):
            if value<=j:
                continue
            if (i-j)>=0:
                dp[i] = max(dp[i],dp[i-j]+value-j)
    return dp[limit]+limit

n = int(input())
wa = list(map(int,input().split()))
wb = list(map(int,input().split()))

m = napzak(wa,wb,n)
ans = napzak(wb,wa,m)

print(ans)

Fixed submission:
def napzak(w,v,limit):
    dp = [0]*(limit+1)
    wv = [(weight,value) for weight,value in zip(w,v) if value>weight]
    if wv == []:
        return limit
    for i in range(1,limit+1):
        for j,value in wv:
            if (i-j)>=0 and dp[i]<(dp[i-j]+value-j):
                dp[i] = dp[i-j]+value-j
    return dp[limit]+limit

n = int(input())
wa = list(map(int,input().split()))
wb = list(map(int,input().split()))

m = napzak(wa,wb,n)
ans = napzak(wb,wa,m)

print(ans)
Buggy python submission (verdict: Runtime Error):
result = 99999
for i in range(1,N):
    s = abs(sum(w[:i]) - sum(w[i:]))
    if s<result:
        result = s
print(result)

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

result = 99999
for i in range(1,N):
    s = abs(sum(w[:i]) - sum(w[i:]))
    if s<result:
        result = s
print(result)
Buggy python submission (verdict: Runtime Error):
def mulmod(x,y,p):
    return x*y % p

def fib_memo(n):
    memo = [0]*(n+1)

    def _fib(n):
        if n <= 1:
            return n
        if memo[n] != 0:
            return memo[n]
        memo[n] = (_fib(n-1) + _fib(n-2))%1000000007
        return memo[n]

    return _fib(n)

n,m = map(int,input().split())
a =[]
pos = 0
result = 1
last = -1
for i in range(m):
    x = int(input())
    if (last+1) == x:
        print(0)
        exit(0)
    last = x
    a.append(x)

for i in a:
    result = mulmod(fib_memo(i-pos),result,1000000007)
    pos = i+1

result = mulmod(fib_memo(n-pos+1),result,1000000007)

print(result)


Fixed submission:
def fib_memo(n,broken):
    memo = [0]*(n+1)
    memo[0] = 1
    for x in range(1,n+1):
        if x < 1:
            continue
        if broken[x]==1:
            continue
        memo[x] = (memo[x-1] + memo[x-2])%1000000007

    return memo[n]

n,m = map(int,input().split())
a =[]
pos = 0
result = 1
last = -1
broken = [0]*(n+1)
for i in range(m):
    x = int(input())
    if (last+1) == x:
        print(0)
        exit(0)
    last = x
    a.append(x)
    broken[x] = 1

result = fib_memo(n,broken)

print(result)

Buggy python submission (verdict: Runtime Error):
def mulmod(x,y,p):
    return x*y % p

def fib_memo(n):
    memo = [0]*(n+1)

    def _fib(n):
        if n <= 1:
            return n
        if memo[n] != 0:
            return memo[n]
        memo[n] = _fib(n-1) + _fib(n-2)
        return memo[n]

    return _fib(n)

n,m = map(int,input().split())
a =[]
pos = 0
result = 1
last = -1
for i in range(m):
    x = int(input())
    if (last+1) == x:
        print(0)
        exit(0)
    last = x
    a.append(x)

for i in a:
    result = mulmod(fib_memo(i-pos),result,1000000007)
    pos = i+1

result = mulmod(fib_memo(n-pos+1),result,1000000007)

print(result)

Fixed submission:
def fib_memo(n,broken):
    memo = [0]*(n+1)
    memo[0] = 1
    for x in range(1,n+1):
        if x < 1:
            continue
        if broken[x]==1:
            continue
        memo[x] = (memo[x-1] + memo[x-2])%1000000007

    return memo[n]

n,m = map(int,input().split())
a =[]
pos = 0
result = 1
last = -1
broken = [0]*(n+1)
for i in range(m):
    x = int(input())
    if (last+1) == x:
        print(0)
        exit(0)
    last = x
    a.append(x)
    broken[x] = 1

result = fib_memo(n,broken)

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))

for i in range(m):
    b,c = map(int,input().split())
    a.extend([c]*b)    

a.sort(reverse=True)
print(sum(a[:n]))

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

bc =[]
for i in range(m):
    b,c = map(int,input().split())
    bc.append((b,c))

bc.sort(key=lambda x:x[1],reverse=True)
newcard=[]
for b,c in bc:
    newcard.extend([c]*b)
    if(len(newcard)>=n):
        break

size = min(n,len(newcard))
a.sort()
for i in range(size):
    if(newcard[i]>a[i]):
        a[i]=newcard[i]
    else:
        break
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))

for i in range(m):
    b,c = map(int,input().split())
    a.extend([c]*b)    

a.sort(reverse=True)
print(sum(a[:n]))

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

bc =[]
for i in range(m):
    b,c = map(int,input().split())
    bc.append((b,c))

bc.sort(key=lambda x:x[1],reverse=True)
newcard=[]
for b,c in bc:
    newcard.extend([c]*b)
    if(len(newcard)>=n):
        break

size = min(n,len(newcard))
a.sort()
for i in range(size):
    if(newcard[i]>a[i]):
        a[i]=newcard[i]
    else:
        break
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
for i in range(m):
    b,c = map(int,input().split())
    index = 0
    for j in range(b):
        if a[j]<c:
            a[j]=c
    a.sort()

print(sum(a))

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

bc =[]
for i in range(m):
    b,c = map(int,input().split())
    bc.append((b,c))

bc.sort(key=lambda x:x[1],reverse=True)
newcard=[]
for b,c in bc:
    newcard.extend([c]*b)
    if(len(newcard)>=n):
        break

size = min(n,len(newcard))
a.sort()
for i in range(size):
    if(newcard[i]>a[i]):
        a[i]=newcard[i]
    else:
        break
print(sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop,heappush
def resolve():
    N = int(input())
    b = 0
    left = []
    right = []
    sumleft = sumright = mid = 0
    for _ in range(N):
        q = list(map(int,input().split()))
        if q[0]==1:#登録
            a = q[1]
            b = b + q[2]
            if not left or -left[0]>a:
                heappush(left,-a)
                sumleft = sumleft + a
                if (len(left)-len(right))>=2:
                    move = -heappop(left)
                    heappush(right,move)
                    sumleft = sumleft-move
                    sumright = sumright+move
            else:
                heappush(right,a)
                sumright = sumright + a
                if len(left)<len(right):
                    move = heappop(right)
                    heappush(left,-move)
                    sumright = sumright-move
                    sumleft = sumleft+move
            mid = -left[0]
        else:#表示
            ans = (len(left)-len(right))*mid-sumleft+sumright + b
            print(mid,ans)


if __name__ == "__main__":
    resolve()

Fixed submission:
from heapq import heappop,heappush
import sys
input = sys.stdin.readline
def resolve():
    N = int(input())
    b = 0
    left = []
    right = []
    sumleft = sumright = mid = 0
    for _ in range(N):
        q = list(map(int,input().split()))
        if q[0]==1:#登録
            a = q[1]
            b = b + q[2]
            if not left or -left[0]>a:
                heappush(left,-a)
                sumleft = sumleft + a
                if (len(left)-len(right))>=2:
                    move = -heappop(left)
                    heappush(right,move)
                    sumleft = sumleft-move
                    sumright = sumright+move
            else:
                heappush(right,a)
                sumright = sumright + a
                if len(left)<len(right):
                    move = heappop(right)
                    heappush(left,-move)
                    sumright = sumright-move
                    sumleft = sumleft+move
            mid = -left[0]
        else:#表示
            ans = (len(left)-len(right))*mid-sumleft+sumright + b
            print(mid,ans)


if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
MAX=10**5+5
tree=[[] for _ in range(MAX)]
ans = [-1]*(MAX)
def dfs(x,weight):
    if(ans[x]>=0):
        return
    ans[x]=weight&1
    for i,w in tree[x]:
        dfs(i,weight+w)

def resolve():
    n =int(input())
    for i in range(n-1):
        u,v,w = map(int,input().split())
        tree[u].append((v,w))
        tree[v].append((u,w))
    dfs(1,0)
    
    for i in range(1,n+1):
        print(ans[i])


if __name__ == "__main__":
    resolve()

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
MAX=10**5+5
tree=[[] for _ in range(MAX)]
ans = [-1]*(MAX)
def dfs(x,weight):
    if(ans[x]>=0):
        return
    ans[x]=weight&1
    for i,w in tree[x]:
        dfs(i,weight+w)

def resolve():
    n =int(input())
    for i in range(n-1):
        u,v,w = map(int,input().split())
        tree[u].append((v,w))
        tree[v].append((u,w))
    dfs(1,0)
    
    for i in range(1,n+1):
        print(ans[i])


if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):
ef resolve():
    n = int(input())
    v = map(int,input().split())
    c = map(int,input().split())
    s = [x-y for x,y in zip(v,c) if (x-y)>0]
    ans = 0
    if s:
        ans = sum(s)
    print(ans)

if __name__ == "__main__":
    resolve()

Fixed submission:
def resolve():
    n = int(input())
    v = map(int,input().split())
    c = map(int,input().split())
    s = [x-y for x,y in zip(v,c) if (x-y)>0]
    ans = 0
    if s:
        ans = sum(s)
    print(ans)

if __name__ == "__main__":
    resolve()