Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
input_n = input()
n = str(input_n)

listN = list(n)
#listN = n.split(' ')

if listN[len(listN) - 1] = "s":
    listN.append("e")
    listN.append("s")
else:
    listN.append("s")

for i in range(len(listN) - 1):
    print(listN[i], end = "")


Fixed submission:
input_n = input()
n = str(input_n)

listN = list(n)
#listN = n.split(' ')

if listN[len(listN) - 1] == "s":
    listN.append("e")
    listN.append("s")
else:
    listN.append("s")

for i in range(len(listN)):
    print(listN[i], end = "")

Buggy python submission (verdict: Runtime Error):
input_n = input()
n = str(input_n)

listN = list(n)
#listN = n.split(' ')

if listN[len(listN)] = "s":
    listN.append("e")
    listN.append("s")
else:
    listN.append("s")

for i in range(len(listN)):
    print(listN[i], end = "")


Fixed submission:
input_n = input()
n = str(input_n)

listN = list(n)
#listN = n.split(' ')

if listN[len(listN) - 1] == "s":
    listN.append("e")
    listN.append("s")
else:
    listN.append("s")

for i in range(len(listN)):
    print(listN[i], end = "")
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
c=a*b
print(c)

Fixed submission:
a, b = map(int, input().split())
print(a*b)
Buggy python submission (verdict: Runtime Error):
def main():
  n=int(input())
  a=list(map(int, input().split()))
  if 0 in A:
    print(0)
    return
  p=1
  for a in A:
    p*=a
    if p>1000000000000000000:
      print(-1)
      return
  print(p)
main()
  


Fixed submission:
def main ():
  N = int(input())
  A = list(map(int,input().split()))
  if 0 in A:
    print (0)
    return
  prod = 1 
  for a in A:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
  print(prod) 
main ()

Buggy python submission (verdict: Runtime Error):
def main():
  n=int(input())
  a=list(map(int, input().split()))
  if 0 in A:
    print(0)
    return
  p=1
  for a in A:
    p=*=a
    if(a>1000000000000000000):
      print(-1)
      return
  print(p)
  


Fixed submission:
def main ():
  N = int(input())
  A = list(map(int,input().split()))
  if 0 in A:
    print (0)
    return
  prod = 1 
  for a in A:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
  print(prod) 
main ()

Buggy python submission (verdict: Runtime Error):
def main():
  n=int(input())
  a=list(map(int().split()))
  if 0 in A:
    print(0)
    return
  p=1
  for a in A:
    p=*=a
    if(a>1000000000000000000):
      print(-1)
      return
  print(p)
  

Fixed submission:
def main ():
  N = int(input())
  A = list(map(int,input().split()))
  if 0 in A:
    print (0)
    return
  prod = 1 
  for a in A:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
  print(prod) 
main ()
Buggy python submission (verdict: Time Limit Exceeded):
_ = input()
nums = [int(x) for x in input().split(" ")]
res = 0
sums = [sum(nums[i:]) for i in range(1, len(nums))]
for i, ni in enumerate(nums[:-1]):
    res += ni*sums[i]
    res %= 10**9 + 7
print(res)

Fixed submission:
_ = input()
nums = [int(x) for x in input().split(" ")]
res = 0
sums = []
for n in nums[1:][::-1]:
    if sums:
        sums.append(sums[-1]+n)
    else:
        sums.append(n)
sums.reverse()
#print(sums)
for i, ni in enumerate(nums[:-1]):
    res += ni*sums[i]
    res %= 10**9 + 7
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
_ = input()
nums = [int(x) for x in input().split(" ")]
res = 0
for i, ni in enumerate(nums):
    for nj in nums[i+1:]:
        res += ni*nj
        res %= 10**9 + 7
print(res)


Fixed submission:
_ = input()
nums = [int(x) for x in input().split(" ")]
res = 0
sums = []
for n in nums[1:][::-1]:
    if sums:
        sums.append(sums[-1]+n)
    else:
        sums.append(n)
sums.reverse()
#print(sums)
for i, ni in enumerate(nums[:-1]):
    res += ni*sums[i]
    res %= 10**9 + 7
print(res)
Buggy python submission (verdict: Runtime Error):
n = int(input())
def numOfDigits(num):
    return len(str(num))
ans += 1
while n > 0:
    if numOfDigits(n)%2 == 1:
        ans += 1
print(ans)


Fixed submission:
n = int(input())
def numOfDigits(num):
    return len(str(num))
ans = 0
while n > 0:
    if numOfDigits(n)%2 == 1:
        ans += 1
    n -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d=map(int,input().split())

XY=[]

for i in range(a,b+1):
    for j in range(c,d+1):
        xy=i*j
        XY.append(xy)
        
print(max(XY))

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

XY=[]

XY.append(a*c)
XY.append(a*d)
XY.append(b*c)
XY.append(b*d)

print(max(XY))
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())

if N==K:
  print(0)

elif N<K:
  lis1=[N,abs(N-K)]
  print(min(lis))
  
else:
  lis2=[N%K,abs(N%K-K)]
  print(min(lis2))
  

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

if N==K:
  print(0)

elif N<K:
  lis1=[N,abs(N-K)]
  print(min(lis1))
  
else:
  lis2=[N%K,abs(N%K-K)]
  print(min(lis2))
Buggy python submission (verdict: Runtime Error):
N=int(input())
d=list(map(int,input().split()))

d.sort()
ans=d[N//2+1]-d[N//2]
print(ans)


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

d.sort()
ans=d[N//2]-d[N//2-1]
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
d=[int(i) for i in input().split()]

d.sort()
ans=d[N/2+1]-d[N/2]
print(ans)


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

d.sort()
ans=d[N//2]-d[N//2-1]
print(ans)
Buggy python submission (verdict: Runtime Error):
is=list(map(int,input().split()))
print(sorted(lis)[0]+sorted(lis)[1])

Fixed submission:
lis=list(map(int,input().split()))
print(sorted(lis)[0]+sorted(lis)[1])
Buggy python submission (verdict: Runtime Error):
A,P=map(int,input().split())
print((3A+P)//2)


Fixed submission:
A,P=map(int,input().split())
print((3*A+P)//2)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()
from collections import defaultdict
d = defaultdict(list)
for i, e in enumerate(s):
  d[e].append(i)

for e in t:
  if e not in d:
    print(-1)
    exit()
cur = -1
loop = 0
for e in t:
  found = False
  for idx in d[e]:
    if (loop*len(s))+idx>cur:
      cur = (loop*len(s))+idx
      found = True
      break
  if not found:
    loop += 1
    for idx in d[e]:
      if (loop*len(s))+idx>cur:
        cur = (loop*len(s))+idx
        found = True
        break
print(cur+1)

Fixed submission:
s = input()
t = input()
from collections import defaultdict
from bisect import bisect_left
d = defaultdict(list)
for i, e in enumerate(s):
  d[e].append(i)

for e in t:
  if e not in d:
    print(-1)
    exit()
cur = -1
loop = 0
for e in t:
  idxt = bisect_left(d[e], cur-loop*len(s)+1)
  #print(d[e], idxt)
  if len(d[e])>idxt:
    #print(11, idxt, d[e][idxt])
    idx = d[e][idxt]
    cur = (loop*len(s))+idx
    #print(12, idx)
  else:
    loop += 1
    idxt = bisect_left(d[e], cur-loop*len(s)+1)
    #print(d[e], idxt)
    idx = d[e][idxt]
    cur = (loop*len(s))+idx
  #(idx, loop)
print(cur+1)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
MOD = 10**9+7

dp = [[0 for i in range(13)] for i in range(len(s)+1)]
dp[0][0] = 1

for i in range(len(s)):
  if s[i]=='?':
    for k in range(10):
      for j in range(13):
        dp[i+1][(j*10+k)%13] = (dp[i+1][(j*10+k)%13] + dp[i][j])%MOD
  else:
    t = int(s[i])
    for j in range(13):
      dp[i+1][(j*10+t)%13] = (dp[i+1][(j*10+t)%13] + dp[i][j])%MOD
print(dp[len(s)][5])

Fixed submission:
s = input()
MOD = 10**9+7

dp = [[0 for i in range(13)] for i in range(len(s)+1)]
dp[0][0] = 1

for i in range(len(s)):
  if s[i]=='?':
    for k in range(10):
      for j in range(13):
        dp[i+1][(j*10+k)%13] = (dp[i+1][(j*10+k)%13] + dp[i][j])%MOD
  else:
    t = int(s[i])
    for j in range(13):
      dp[i+1][(j*10+t)%13] = (dp[i+1][(j*10+t)%13] + dp[i][j])%MOD
print(dp[len(s)][5])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import bisect_right, insort_left

def I(): return int(sys.stdin.readline())

def main():
  n = int(input())
  a = [I() for i in range(n)]
  b = []

  for i in range(n-1, -1, -1):
    #print(a[i])
    t = bisect_right(b, a[i])
    if len(b)-1<t or b[t]==a[i]:
      insort_left(b, a[i])
    else:
      b[t] = a[i]
    #print(b)
  print(len(b))

if __name__ == '__main__':
  main()

Fixed submission:
import sys
from bisect import bisect_right, insort

def I(): return int(sys.stdin.readline())

def main():
  n = I()
  a = [I() for i in range(n)]
  b = []

  for i in range(n-1, -1, -1):
    t = bisect_right(b, a[i])
    if len(b)-1<t or b[t]==a[i]:
      insort(b, a[i])
    else:
      b[t] = a[i]
  print(len(b))

if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))

MAX = 2*10**5+1
MOD = 10**9+7
fact = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
invfact = [0 for i in range(MAX)]

def comb_build(n):
  fact[0] = inv[0] = invfact[0] = 1
  fact[1] = inv[1] = invfact[1] = 1
  for i in range(2, n):
    fact[i] = fact[i-1]*i%MOD
    inv[i] = inv[MOD%i]*(MOD-MOD//i)%MOD
    invfact[i] = invfact[i-1]*inv[i]%MOD

def nCk(n, k):
  if n<k or n<0 or k<0:
    return 0
  return (((fact[n]*invfact[k])%MOD)*invfact[n-k])%MOD

comb_build(2010)

t = nCk(n, n-k)
for i in range(1, k+1):
  if i>n-k+1:
    print(0)
  else:
    print((nCk(k-1, i-1)*nCk(n-(k-1), i))%MOD)
print(s%MOD == t%MOD)

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

MAX = 2*10**5+1
MOD = 10**9+7
fact = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
invfact = [0 for i in range(MAX)]

def comb_build(n):
  fact[0] = inv[0] = invfact[0] = 1
  fact[1] = inv[1] = invfact[1] = 1
  for i in range(2, n):
    fact[i] = fact[i-1]*i%MOD
    inv[i] = inv[MOD%i]*(MOD-MOD//i)%MOD
    invfact[i] = invfact[i-1]*inv[i]%MOD

def nCk(n, k):
  if n<k or n<0 or k<0:
    return 0
  return (((fact[n]*invfact[k])%MOD)*invfact[n-k])%MOD

comb_build(2010)

for i in range(1, k+1):
  if i>n-k+1:
    print(0)
  else:
    print((nCk(k-1, i-1)*nCk(n-(k-1), i))%MOD)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
MOD = 10**9+7
dp = [[0 for i in range(2010)] for i in range(2010)]
for i in range(2010):
  dp[i][0] = 1
  dp[0][i] = 1
s = list(map(int, input().split()))
t = list(map(int, input().split()))
for i in range(1, n+1):
  for j in range(1, m+1):
    dp[i][j] = (dp[i][j]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%MOD
    if s[i-1]==t[j-1]:
      dp[i][j] = (dp[i][j]+dp[i-1][j-1])%MOD
print(dp[n][m])

Fixed submission:
n, m = list(map(int, input().split()))
MOD = 10**9+7
dp = [[0 for i in range(2010)] for i in range(2010)]
for i in range(2010):
  dp[i][0] = 1
  dp[0][i] = 1
s = list(map(int, input().split()))
t = list(map(int, input().split()))
for i in range(1, n+1):
  for j in range(1, m+1):
    dp[i][j] = (dp[i][j]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%MOD
    if s[i-1]==t[j-1]:
      dp[i][j] = (dp[i][j]+dp[i-1][j-1])%MOD
print(dp[n][m])
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
xy.sort()
s = defaultdict(int)
for i in range(n-1):
  s[(xy[i+1][0]-xy[i][0], xy[i+1][1]-xy[i][1])] += 1
m = max(s.values())
ans = 1 + (n-m-1)
print(ans)

Fixed submission:
n = int(input())
xy = [tuple(map(int, input().split())) for i in range(n)]
ans = n

for i in range(n):
  for j in range(n):
    if i==j:
      continue
    xt = xy[i][0]-xy[j][0]
    yt = xy[i][1]-xy[j][1]
    tmp = n
    for k in range(n):
      if (xy[k][0]+xt, xy[k][1]+yt) in xy:
        tmp -= 1
    ans = min(ans, tmp)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h, w = list(map(int, input().split()))
s = [input() for i in range(h)]
visited = [[0 for i in range(w)] for i in range(h)]

ans = 0
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


def dfs(x, y):
  cur = 1
  if s[y][x]=="#":
    return 0

  for dxt, dyt in zip(dx, dy):
    xx, yy = x, y
    while True:
      nx = xx+dxt
      ny = yy+dyt
      if 0<=ny<h and 0<=nx<w and s[ny][nx]==".":
        cur += 1
      else:
        break
      xx, yy = nx, ny

  return cur


for i in range(h):
  for j in range(w):
    ans = max(ans, dfs(j, i))
print(ans)

Fixed submission:
h, w = list(map(int, input().split()))
s = [input() for i in range(h)]
yoko = [[0 for i in range(w)] for i in range(h)]
tate = [[0 for i in range(w)] for i in range(h)]

ans = 0
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


for i in range(h):
  cur = 0
  b = 0
  e = 0
  flag = 0
  for j in range(w):
    if s[i][j]=="." and j==w-1:
      cur += 1
      e = j
      for k in range(b, e+1):
        yoko[i][k] = cur
      cur = 0
    elif flag and s[i][j]==".":
      cur += 1
    elif not flag and s[i][j]==".":
      cur = 1
      flag = 1
      b = j
    elif flag and s[i][j]=="#":
      flag = 0
      e = j-1
      for k in range(b, e+1):
        yoko[i][k] = cur
      cur = 0
      b = j+1
    elif s[i][j]=="." and j==w-1:
      cur += 1
      e = j-1
      for k in range(b, e+1):
        yoko[i][k] = cur
      cur = 0
    else:
      b = j+1


for j in range(w):
  cur = 0
  b = 0
  e = 0
  flag = 0
  for i in range(h):
    if s[i][j]=="." and i==h-1:
      cur += 1
      e = i
      for k in range(b, e+1):
        tate[k][j] = cur
      cur = 0
    if flag and s[i][j]==".":
      cur += 1
    elif not flag and s[i][j]==".":
      cur = 1
      flag = 1
      b = i
    elif flag and s[i][j]=="#":
      flag = 0
      e = i-1
      for k in range(b, e+1):
        tate[k][j] = cur
      cur = 0
      b = i+1
    elif s[i][j]=="." and i==h-1:
      cur += 1
      e = i-1
      for k in range(b, e+1):
        tate[k][j] = cur
      cur = 0
    else:
      b = i+1

ans = 0
for i in range(h):
  for j in range(w):
    if yoko[i][j]>0 and tate[i][j]>0:
      ans = max(ans, yoko[i][j]+tate[i][j]-1)
    else:
      ans = max(ans, yoko[i][j]+tate[i][j])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, x = list(map(int, input().split()))
B = 0
blu = []

for i in range(n):
  b, l, u = list(map(int, input().split()))
  blu.append((b, l, u, x*u-b*u+b*l))
  B += b*l
blu.sort(key=lambda x: x[3], reverse=True)

ans = n*x
for i in range(n):
  ok = n*x
  ng = -1
  while ok-ng>1:
    A = 0
    tB = B
    mid = (ok+ng)//2
    k = mid//x
    t = mid%x
    for j in range(n):
      if j!=i and k>0:
        A += x*blu[j][2]
        tB += blu[j][0]*(blu[j][2]-blu[j][1])
        k -= 1
      elif k<=0:
        break
    if t!=0:
      if t<=blu[i][0]:
        A += t*blu[i][1]
      else:
        A += t*blu[i][2]
        tB += blu[i][0]*(blu[i][2]-blu[i][1])
    if A>=tB:
      ok = mid
    else:
      ng = mid
  ans = min(ans, ok)

print(ans)

Fixed submission:
n, x = list(map(int, input().split()))
B = 0
blu = []
s = [0 for i in range(n)]

for i in range(n):
  b, l, u = list(map(int, input().split()))
  blu.append((b, l, u, x*u-b*u+b*l))
  B += b*l
blu.sort(key=lambda x: x[3], reverse=True)

for i in range(n):
  if i==0:
    s[i] = blu[i][3]
  else:
    s[i] = s[i-1] + blu[i][3]

ok = n*x
ng = -1
while ok-ng>1:
  A = 0
  mid = (ok+ng)//2
  k = mid//x
  t = mid%x
  for i in range(n):
    if t<=blu[i][0]:
      rm = t*blu[i][1]
    else:
      rm = t*blu[i][2] - blu[i][0]*(blu[i][2]-blu[i][1])
    if k==0:
      A = max(A, rm)
    elif i<k:
      A = max(A, s[k]-blu[i][3]+rm)
    else:
      A = max(A, s[k-1]+rm)
  if A>=B:
    ok = mid
  else:
    ng = mid

print(ok)
Buggy python submission (verdict: Runtime Error):
n = int(input())
from collections import defaultdict
graph = defaultdict(list)
edge = []
for i in range(n-1):
  a, b = list(map(int, input().split()))
  edge.append((a, b))
  graph[a].append(b)
  graph[b].append(a)
c = list(map(int, input().split()))
c.sort(reverse=True)
visited = [0 for i in range(n+1)]
ans = [0 for i in range(n+1)]
score = 0

def dfs(x):
  visited[x] = 1
  for next_ in graph[x]:
    if visited[next_]:
      continue
    dfs(next_)
  if all(visited[i] for i in graph[x]):
    ans[x] = c.pop()
    return
  visited[x] = 0

dfs(1)
for a, b in edge:
  score += min(ans[a], ans[b])
print(score)
print(*ans[1:])

Fixed submission:
n = int(input())
from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)
graph = defaultdict(list)
edge = []
for i in range(n-1):
  a, b = list(map(int, input().split()))
  edge.append((a, b))
  graph[a].append(b)
  graph[b].append(a)
c = list(map(int, input().split()))
c.sort(reverse=True)
visited = [0 for i in range(n+1)]
ans = [0 for i in range(n+1)]
score = 0

def dfs(x):
  visited[x] = 1
  for next_ in graph[x]:
    if visited[next_]:
      continue
    dfs(next_)
  if all(visited[i] for i in graph[x]):
    ans[x] = c.pop()
    return
  visited[x] = 0

dfs(1)
for a, b in edge:
  score += min(ans[a], ans[b])
print(score)
print(*ans[1:])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
ans = 0

from heapq import heappush, heappop
for i in range(1, k+1):
  for j in range(1, i+1):
    for k in range(0, j+1):
      minus = []
      l = min(n, k)
      r = min(n-l, j-l)
      cur = 0
      for ll in range(l):
        cur += v[ll]
        if v[ll]<0:
          heappush(minus, v[ll])
      for rr in range(r):
        cur += v[n-rr-1]
        if v[n-rr-1]<0:
          heappush(minus, v[n-rr-1])
      rm = i-l-r
      while rm>0 and len(minus)>=rm:
        rm -= 1
        t = heappop(minus)
        cur -= t
      ans = max(ans, cur)
print(ans)

Fixed submission:
n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
ans = 0
ls = [0 for i in range(n+1)]
rs = [0 for i in range(n+1)]
for i in range(n):
  ls[i+1] = ls[i]+v[i]
  rs[i+1] = rs[i]+v[n-i-1]

from heapq import heappush, heappop
for i in range(1, k+1):
  for j in range(1, i+1):
    for k in range(0, j+1):
      menus = []
      l = min(n, k)
      r = min(n-l, j-l)
      for ll in range(l):
        if v[ll]<0:
          heappush(menus, v[ll])
      for rr in range(r):
        if v[n-rr-1]<0:
          heappush(menus, v[n-rr-1])
      cur = ls[l] + rs[r]
      rm = i-l-r
      while rm>0 and len(menus)>=rm:
        rm -= 1
        t = heappop(menus)
        cur -= t
      ans = max(ans, cur)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
from bisect import bisect_left
b = []
for i in range(m):
  b.append(list(map(int, input().split())))
b.sort(key=lambda x: x[1], reverse=True)
cur = 0
ans = 0
for e in b:
  t = bisect_left(a[cur:], e[1])
  ans += min(t, e[0])*e[1]
  cur += min(t, e[0])
while cur<len(a):
  ans += a[cur]
  cur += 1
print(ans)

Fixed submission:
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
from bisect import bisect_left
b = [list(map(int, input().split())) for i in range(m)]
b.sort(key=lambda x: x[1], reverse=True)
cur = 0
ans = 0
for e in b:
  t = bisect_left(a, e[1])
  if t>=cur:
    ans += min(t-cur, e[0])*e[1]
    cur += min(t-cur, e[0])
while cur<len(a):
  ans += a[cur]
  cur += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5-1)

n = int(input())
if n==1:
  print(0)
  exit()
from collections import defaultdict
edge = defaultdict(list)
for i in range(n-1):
  u, v, w = list(map(int, input().split()))
  edge[u].append((v, w))
  edge[v].append((u, w))
graph = [-1 for i in range(n+1)]

def dfs(x, c):
  nexts = edge.get(x)
  if nexts is None:
    return
  if graph[x]!=-1:
    return
  else:
    graph[x] = c
  for y, w in nexts:
    if w%2:
      dfs(y, not c)
    else:
      dfs(y, c)

dfs(1, 0)
for i in range(1, n+1):
  print(int(graph[i]))

Fixed submission:
n, k = list(map(int, input().split()))
s = input()
ans = s[:k-1]+s[k-1].lower()+s[k:]
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**4)

n = int(input())
if n==1:
  print(0)
  exit()
from collections import defaultdict
edge = defaultdict(list)
for i in range(n-1):
  u, v, w = list(map(int, input().split()))
  edge[u].append((v, w))
  edge[v].append((u, w))
graph = [-1 for i in range(n+1)]

def dfs(x, c):
  nexts = edge.get(x)
  if nexts is None:
    return
  if graph[x]!=-1:
    return
  else:
    graph[x] = c
  for y, w in nexts:
    if w%2:
      dfs(y, not c)
    else:
      dfs(y, c)

dfs(1, 0)
for i in range(1, n+1):
  print(int(graph[i]))

Fixed submission:
import sys
sys.setrecursionlimit(10**5+1)
n = int(input())
if n==1:
  print(0)
  exit()
from collections import defaultdict
edge = defaultdict(list)
for i in range(n-1):
  u, v, w = list(map(int, input().split()))
  edge[u].append((v, w))
  edge[v].append((u, w))
graph = [-1 for i in range(n+1)]

def dfs(x, c):
  nexts = edge.get(x)
  if nexts is None:
    return
  if graph[x]!=-1:
    return
  else:
    graph[x] = c
  for y, w in nexts:
    if w%2:
      dfs(y, not c)
    else:
      dfs(y, c)

dfs(1, 0)
for i in range(1, n+1):
  print(int(graph[i]))

Buggy python submission (verdict: Runtime Error):
n = int(input())
if n==1:
  print(0)
  exit()
from collections import defaultdict
edge = defaultdict(list)
for i in range(n-1):
  u, v, w = list(map(int, input().split()))
  edge[u].append((v, w))
  edge[v].append((u, w))
graph = [-1 for i in range(n+1)]

def dfs(x, c):
  nexts = edge.get(x)
  if graph[x]!=-1:
    return
  else:
    graph[x] = c
  for y, w in nexts:
    if w%2:
      dfs(y, not c)
    else:
      dfs(y, c)

dfs(1, 0)
for i in range(1, n+1):
  print(int(graph[i]))

Fixed submission:
import sys
sys.setrecursionlimit(10**5+1)
n = int(input())
if n==1:
  print(0)
  exit()
from collections import defaultdict
edge = defaultdict(list)
for i in range(n-1):
  u, v, w = list(map(int, input().split()))
  edge[u].append((v, w))
  edge[v].append((u, w))
graph = [-1 for i in range(n+1)]

def dfs(x, c):
  nexts = edge.get(x)
  if nexts is None:
    return
  if graph[x]!=-1:
    return
  else:
    graph[x] = c
  for y, w in nexts:
    if w%2:
      dfs(y, not c)
    else:
      dfs(y, c)

dfs(1, 0)
for i in range(1, n+1):
  print(int(graph[i]))
Buggy python submission (verdict: Time Limit Exceeded):
r, g, b, n = list(map(int, input().split()))
ans = 0
for i in range(n//r+1):
  for j in range(n//b+1):
    ij = i*r + j*b
    k = (n-ij)//g
    if not (i==k==j==0) and (k>=0 and (n-ij)%g==0):
      ans += 1
print(ans)

Fixed submission:
r, g, b, n = list(map(int, input().split()))
ans = 0
for i in range(n//r+1):
  for j in range(n//b+1):
    ij = i*r + j*b
    k = (n-ij)//g
    if not (i==k==j==0) and (k>=0 and (n-ij)%g==0):
      ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(1, int(n**(1/2))+2):
  if (n-i)%i==0:
    ans += (n-i)//i
if (n-1)%(n-1)==0:
    ans += 1
print(ans)

Fixed submission:
n = int(input())
ans = 0
if n==1 or n==2:
  print(0)
  exit()
elif n<6:
  print(n-1)
  exit()
for i in range(1, int(n**(1/2))+2):
  k = (n-i)//i
  if n%k == n//k:
    ans += k
print(ans)
Buggy python submission (verdict: Runtime Error):
x, y, z, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

d = [e1+e2 for e1 in a for e2 in b]
d.sort(reverse=True)
d = d[:k]

e = [e1+e2 for e1 in d for e2 in c]
e.sort(reverse=True)

for i in range(k):
  print(e[i])

Fixed submission:
a = []
for i in range(5):
  a.append(int(input()))
k = int(input())
if a[4]-a[0]<=k:
  print("Yay!")
else:
  print(":(")