Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = input() 
day = ['SUN','MON','TUE','WED','THU','FRI','SAT'][::-1]
dic = {d:i+1 in i,d zip(range(len(day),day))}
print(dic[s])

Fixed submission:
day = ['SUN','MON','TUE','WED','THU','FRI','SAT'][::-1]
dic = {d:i+1 for i,d in zip(range(len(day)),day)}
print(dic[input()])
Buggy python submission (verdict: Runtime Error):
n = int(input())
es = [[] for _ in range(n)]

for i in range(n-1):
  a,b = map(int,input().split())
  if a > b:
    a,b = b,a
  es[a-1].append((b-1,i))

ans = [0] * (n-1) 

def coloring(vi,prev_color):
  color = 1    
  for to,i in es[vi] :
    if color == prev_color:
      color += 1        
    ans[i] = color     
    coloring(to,color)
    color += 1
    
coloring(0,0)

print(max(ans))
print(*ans,sep='\n')

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

n = int(input())
es = [[] for _ in range(n)]

for i in range(n-1):
  a,b = map(int,input().split())
  if a > b:
    a,b = b,a
  es[a-1].append((b-1,i))

ans = [0] * (n-1) 

def coloring(vi,prev_color):
  color = 1    
  for to,i in es[vi] :
    if color == prev_color:
      color += 1        
    ans[i] = color     
    coloring(to,color)
    color += 1
    
coloring(0,0)

print(max(ans))
print(*ans,sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ll = list(map(int,input().split()))

sl = sorted(ll,reverse=True)
count=0

for i1 in range(len(sl)-2):
  for i2 in range(i1+1,len(sl)-1):
    for i3 in range(i2+1,len(sl)):
      if sl[i1] < sl[i2] + sl[i3]:        
        count+=1

print(count)        

Fixed submission:
from bisect import bisect_left
n = int(input())
ll = list(map(int,input().split()))

ls = sorted(ll)
count = 0
for i in range(n-1):
  for j in range(i+1,n-1):
    x = bisect_left(ls,ls[i]+ls[j])
    count += x-j-1
    
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import math

a,b = map(int,input().split())

def common_divisor(n):
  if n == 1:
    return [1]
  ret = []
  for i in range(1,math.ceil(math.sqrt(n))+1):
    if n%i==0:
      ret.append(i)
      ret.append(n//i)      
  return list(set(ret))

ca = common_divisor(a)
cb = common_divisor(b)

sa = set(ca)
c = sa.intersection(cb)

count = 0
for ci in c:
  if len(common_divisor(ci))<=2:
    count+=1    

print(count)

Fixed submission:
import math

a,b = map(int,input().split())

def common_divisor(n):
  if n == 1:
    return [1]
  ret = []
  for i in range(1,math.ceil(math.sqrt(n))+1):
    if n%i==0:
      ret.append(i)
      ret.append(n//i)      
  return list(set(ret))

def trial_division(n):
    if n == 2:
        return True
    if n < 2 or n % 2 == 0:
        return False
    for i in range(3, int(math.ceil(math.sqrt(n))) + 1, 2):
        if n % i == 0:
            return False
    return True

ca = common_divisor(a)
cb = common_divisor(b)

sa = set(ca)
c = sa.intersection(cb)

count = 1
for ci in c:
  if trial_division(ci):
    count+=1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import math

a,b = map(int,input().split())

def common_divisor(n):
  if n == 1:
    return [1]
  ret = []
  for i in range(1,math.ceil(math.sqrt(n))):
    if n%i==0:
      ret.append(i)
      ret.append(n//i)      
  return sorted(ret)

ca = common_divisor(a)
cb = common_divisor(b)

sa = set(ca)
c = sa.intersection(cb)

primes = lambda n:[i for i in range(1,n+1) if len([j for j in range(1,i+1) if i%j==0]) ==2]

sp = primes(max(c))
sp.append(1)

print(len(c.intersection(sp)))

Fixed submission:
import math

a,b = map(int,input().split())

def common_divisor(n):
  if n == 1:
    return [1]
  ret = []
  for i in range(1,math.ceil(math.sqrt(n))+1):
    if n%i==0:
      ret.append(i)
      ret.append(n//i)      
  return list(set(ret))

def trial_division(n):
    if n == 2:
        return True
    if n < 2 or n % 2 == 0:
        return False
    for i in range(3, int(math.ceil(math.sqrt(n))) + 1, 2):
        if n % i == 0:
            return False
    return True

ca = common_divisor(a)
cb = common_divisor(b)

sa = set(ca)
c = sa.intersection(cb)

count = 1
for ci in c:
  if trial_division(ci):
    count+=1

print(count)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_right
from collections import deque

n,m = map(int,input().split())
aa = list(map(int,input().split()))
q = deque()
q.extend(sorted(aa))

for i in range(m):
  tmp = q.pop()//2  
  pos = bisect_right(q,tmp)
  q.insert(pos,tmp)
  
print(sum(q))  

Fixed submission:
# dequeにinsert追加されたのは 3.5 から
from heapq import heappop,heappush,heapify
n,m = map(int,input().split())
aa = list(map(int,input().split()))
aa = list(map(lambda x:-x,aa))

heapify(aa)
for i in range(m):
  tmp = heappop(aa)  
  heappush(aa,-(-tmp//2))

print(-sum(aa))

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_right

n,m = map(int,input().split())
aa = list(map(int,input().split()))
aa = sorted(aa)

for i in range(m):
  tmp = aa[-1]//2
  aa.pop()
  pos = bisect_right(aa,tmp)
  aa.insert(pos,tmp)
  
print(sum(aa))  

Fixed submission:
# dequeにinsert追加されたのは 3.5 から
from heapq import heappop,heappush,heapify
n,m = map(int,input().split())
aa = list(map(int,input().split()))
aa = list(map(lambda x:-x,aa))

heapify(aa)
for i in range(m):
  tmp = heappop(aa)  
  heappush(aa,-(-tmp//2))

print(-sum(aa))
Buggy python submission (verdict: Runtime Error):
a,b = input().split()
i = 1
while i<500:
  if a*i - i + 1 >= b:
    break

print(i)    

Fixed submission:
a,b = map(int,input().split())
n = (b-1)/(a-1)
print(-int((-n)//1))
Buggy python submission (verdict: Time Limit Exceeded):
print(sum([i for i in range(int(input()))]))

Fixed submission:
n=int(input())
print(n*(n-1)//2)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
print(sum([i for i in range(1,n)]))

Fixed submission:
n=int(input())
print(n*(n-1)//2)
Buggy python submission (verdict: Runtime Error):
ab = sorted(ab, key= lambda x:(x[0]))

from heapq import heappush,heappop

n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]

hq = []
j = 0
ans = 0

for i in range(m):
  while j<n and ab[j][0] <= i+1:
    heappush(hq,-ab[j][1])
    j+=1
  if len(hq)>0:
    ans += -heappop(hq)
    
print(ans)    

Fixed submission:
from heapq import heappush,heappop

n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab = sorted(ab, key= lambda x:(x[0]))

hq = []
j = 0
ans = 0

for i in range(m):
  while j<n and ab[j][0] <= i+1:
    heappush(hq,-ab[j][1])
    j+=1
  if len(hq)>0:
    ans += -heappop(hq)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))

ans = 'Yes'
for i in range(n-1):
  diff = h[i+1]-h[i]
  if diff <= -1:
    if flag:
      ans='No'
      break        
    
    if diff <= -2:
      ans = 'No'
      break
        
    flag = True          
    
  else:
    if diff >= 1:
      flag = False

print(ans)      

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

ans = 'Yes'
flag = False
for i in range(n-1):
  diff = h[i+1]-h[i]
  if diff <= -1:
    if flag:
      ans='No'
      break        
    
    if diff <= -2:
      ans = 'No'
      break
        
    flag = True          
    
  else:
    if diff >= 1:
      flag = False

print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int,input().split()))

ans = 'Yes'
level = h[0]
for i in range(n-1):
  diff = h[i+1]-h[i]
  if diff <= -1:
    if flag:
      ans='No'
      break        
    
    if diff <= -3:
      ans = 'No'
      break
        
    flag = True      
    level = h[i+1] 
    
    if i == n-2 and diff <= -2:
      ans ='No'
    
  else:
    if diff >= 1:
      flag = False

print(ans)      

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

ans = 'Yes'
flag = False
for i in range(n-1):
  diff = h[i+1]-h[i]
  if diff <= -1:
    if flag:
      ans='No'
      break        
    
    if diff <= -2:
      ans = 'No'
      break
        
    flag = True          
    
  else:
    if diff >= 1:
      flag = False

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9+7

s = input()
n = len(s)

dp = [0]*13
dp[0] = 1

for i in range(n):
  dp2 = [0]*13  
  for j in range(10):
    if s[i] == '?' or s[i] == str(j):
      for k in range(13):
        dp2[(k*10 + j)%13] += dp[k]
        dp2[(k*10 + j)%13] %= mod
        
  dp = dp2

print(dp[5])

Fixed submission:
mod = 10**9+7

s = input()
n = len(s)

dp = [0]*13
dp[0] = 1

for i in range(n):
  dp2 = [0]*13  
  for j in range(10):
    if s[i] == '?' or s[i] == str(j):
      for k in range(13):
        dp2[(k*10 + j)%13] += dp[k]
        dp2[(k*10 + j)%13] %= mod
        
  dp = dp2

print(dp[5])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

a = sorted(a,reverse=True)

for ai in a[1:]:
  gen = [a[0]]
  gen.append(ai)
  for j in range(2,n):   
    gen.append(gen[j-2]^gen[j-1])

if (set(gen)==set(a)):
  print('Yes')
else:
  print('No')    

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

A = sorted(A, reverse=True)
xor = A[0]
for a in A[1:]:
  xor ^= a 
if (xor == 0):
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
mod = 10**9+7

def dfs(v,pr,k):
  if len(G[v]) > k:
    return 0
  
  kc = k-2
  if pr == -1:
    kc = k-1  
  
  ret = 1
  
  for vi in G[v]:
    if vi == pr:
      continue
    ret *= kc
    ret %= mod
    kc -= 1
    
  for vi in G[v]:
    if vi == pr:
      continue
    ret *= dfs(vi,v,k)
    ret %= mod
  
  return ret


n,k = map(int,input().split())
G = [[] for i in range(n)]
for i in range(n-1):
  a,b = map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)      
  
print(dfs(0,-1,k) * k % mod )

Fixed submission:
import sys
sys.setrecursionlimit(410000)

mod = 10**9+7

def dfs(v,pr,k):
  if len(G[v]) > k:
    return 0
  
  kc = k-2
  if pr == -1:
    kc = k-1  
  
  ret = 1
  
  for vi in G[v]:
    if vi == pr:
      continue
    ret *= kc
    ret %= mod
    kc -= 1
    
  for vi in G[v]:
    if vi == pr:
      continue
    ret *= dfs(vi,v,k)
    ret %= mod
  
  return ret


n,k = map(int,input().split())
G = [[] for i in range(n)]
for i in range(n-1):
  a,b = map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)      
  
print(dfs(0,-1,k) * k % mod )
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
al = b-a+1
# cで割り切れる個数
x = int(b/c) -int((a-1)/c)
# dで割り切れる個数
y = int(b/d) -int((a-1)/d)
# cdの最小公倍数
lcm_xy = int(c*d/math.gcd(c,d))
# cdの最小公倍数で割り切れる個数
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)
#print(x,y,xy,al)
print(al-(x+y-xy))

Fixed submission:
s = input()
if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print('Bad')
else:
  print('Good')

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
r_ab=range(a,b+1)
count=0
for i in r_ab:
  if i%c!=0 and i%d!=0:
    count+=1
print(count)

Fixed submission:
s = input()
if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print('Bad')
else:
  print('Good')
Buggy python submission (verdict: Runtime Error):
n = int(input())
X = [0]*n
Y = [0]*n
for i in range(n):
  X[i],Y[i] = map(int,input().split())  
  
dic = {}
for i in range(n):
  for j in range(i+1,n):
    x = X[i]-X[j]
    y = Y[i]-Y[j]
    dic[(x,y)] = dic.get((x,y),0) + 1
    
print(n-max(dic.values()))

Fixed submission:
n = int(input())
X = [0]*n
Y = [0]*n
for i in range(n):
  X[i],Y[i] = map(int,input().split())  
  
dic = {}
for i in range(n):
  for j in range(n):
    if i!=j:
      x = X[i]-X[j]
      y = Y[i]-Y[j]
      dic[(x,y)] = dic.get((x,y),0) + 1

if n == 1:
  print(1)
else:  
  print(n-max(dic.values()))
Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
F = [input() for _ in range(h)]

MW = [[0]*w for _ in range(h)]
MH = [[0]*w for _ in range(h)]


for i in range(h):
  l = 0
  c = 0
  for r in range(w):    
    if F[i][r] == '#':
      for k in range(l,r):
        MW[i][k] = c
      l = r+1
      c = 0      
    else:
      c += 1
  for k in range(l,r+1):
    MW[i][k] = c  
    
for i in range(w):
  u = 0
  c = 0
  for b in range(h):    
    if F[b][i] == '#':
      for k in range(u,b):
        MH[k][i] = c
      u = b+1
      c = 0      
    else:
      c += 1
  for k in range(u,b+1):
    MH[k][i] = c      
    
ans = 0    
for i in range(h):
  for j in range(w):
    tmp = 0
    if F[i][j] != '#':
      tmp = MH[i][j]+MW[i][j] -1 
    ans = max(ans,tmp)
    
print(ans)

Fixed submission:
h,w = map(int,input().split())
F = [input() for _ in range(h)]

MW = [[0]*w for _ in range(h)]
MH = [[0]*w for _ in range(h)]


for i in range(h):
  l = 0
  c = 0
  for r in range(w):    
    if F[i][r] == '#':
      for k in range(l,r):
        MW[i][k] = c
      l = r+1
      c = 0      
    else:
      c += 1
  for k in range(l,r+1):
    MW[i][k] = c  
    
for i in range(w):
  u = 0
  c = 0
  for b in range(h):    
    if F[b][i] == '#':
      for k in range(u,b):
        MH[k][i] = c
      u = b+1
      c = 0      
    else:
      c += 1
  for k in range(u,b+1):
    MH[k][i] = c      
    
ans = 0    
for i in range(h):
  for j in range(w):
    tmp = 0
    if F[i][j] != '#':
      tmp = MH[i][j]+MW[i][j] -1 
    ans = max(ans,tmp)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
import heapq
from collections import deque
from copy import deepcopy

n,k = map(int,input().split())
V = list(map(int,input().split()))

dq = deque()
dq.extend(V)

ans = - 10**9
for i in range(k+1):
  for j in range(k+1-i):           
    que = deepcopy(dq)
    a = []    
    for l in range(i):      
      heapq.heappush(a,que.popleft())
    for r in range(j):
      heapq.heappush(a,que.pop())    
    
    for ki in range((k+1-i-j)//2+1):            
      ans = max(ans,sum(a))        
      if len(a) > 0:
        heapq.heappop(a)
        
print(ans)        

Fixed submission:
import heapq
from collections import deque
from copy import deepcopy

n,k = map(int,input().split())
V = list(map(int,input().split()))

dq = deque()
dq.extend(V)
INF = 10**10

ans = -INF
for i in range(k+1):
  for j in range(k+1-i):           
    que = deepcopy(dq)
    a = []    
    
    if i+j <= n:
      for l in range(i):      
        heapq.heappush(a,que.popleft())
      for r in range(j):
        heapq.heappush(a,que.pop())    
      
      ans = max(ans,sum(a))        
      for ki in range(k-i-j):   
        if len(a) > 0:
          heapq.heappop(a)
        ans = max(ans,sum(a))        
        
if ans != -INF:          
  print(ans)
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
import heapq
from collections import deque

n,k = map(int,input().split())
V = list(map(int,input().split()))

dq = deque()
dq.extend(V)

ans = - 10**9
for i in range(k+1):
  for j in range(k+1-i):           
    que = dq.copy()        
    a = []    
    for l in range(i):      
      heapq.heappush(a,que.popleft())
    for r in range(j):
      heapq.heappush(a,que.pop())    
    
    for ki in range((k+1-i-j)//2+1):            
      ans = max(ans,sum(a))        
      if len(a) > 0:
        heapq.heappop(a)
        
print(ans)        

Fixed submission:
import heapq
from collections import deque
from copy import deepcopy

n,k = map(int,input().split())
V = list(map(int,input().split()))

dq = deque()
dq.extend(V)
INF = 10**10

ans = -INF
for i in range(k+1):
  for j in range(k+1-i):           
    que = deepcopy(dq)
    a = []    
    
    if i+j <= n:
      for l in range(i):      
        heapq.heappush(a,que.popleft())
      for r in range(j):
        heapq.heappush(a,que.pop())    
      
      ans = max(ans,sum(a))        
      for ki in range(k-i-j):   
        if len(a) > 0:
          heapq.heappop(a)
        ans = max(ans,sum(a))        
        
if ans != -INF:          
  print(ans)
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for _ in range(m)]

bc = sorted(bc,key=lambda x:(x[1]))
count=0
for b,c in bc:
  count += b
  a.extend([c]*b)
  if b > n:
    break
    
print(sum(sorted(a,reverse=True)[:n]))

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

bc = sorted(bc,key=lambda x:(x[1]),reverse=True)
count=0
for b,c in bc:
  count += b
  a.extend([c]*b)
  if count >= n:
    break
    
print(sum(sorted(a,reverse=True)[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for _ in range(m)]

bc2 = sum([[c]*b for b,c in bc],[])
a.extend(sorted(bc2)[-n:])
print(sum(sorted(a,reverse=True)[:n]))

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

bc = sorted(bc,key=lambda x:(x[1]),reverse=True)
count=0
for b,c in bc:
  count += b
  a.extend([c]*b)
  if count >= n:
    break
    
print(sum(sorted(a,reverse=True)[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for _ in range(m)]

a.extend(sum([[c]*b for b,c in bc],[]))
  
print(sum(sorted(a,reverse=True)[:n]))

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

bc = sorted(bc,key=lambda x:(x[1]),reverse=True)
count=0
for b,c in bc:
  count += b
  a.extend([c]*b)
  if count >= n:
    break
    
print(sum(sorted(a,reverse=True)[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for _ in range(m)]

for b,c in bc:
  a += [c]*b  
  
print(sum(sorted(a,reverse=True)[:n]))

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

bc = sorted(bc,key=lambda x:(x[1]),reverse=True)
count=0
for b,c in bc:
  count += b
  a.extend([c]*b)
  if count >= n:
    break
    
print(sum(sorted(a,reverse=True)[:n]))
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
s = list(input())
s[k-1]= str.lower(s[k-1])
"".join(s)uu

Fixed submission:
n,k = map(int,input().split())
s = list(input())
s[k-1]= str.lower(s[k-1])
print("".join(s))
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())

pi = 0
for i in range(1,n+1):
  need = math.ceil(math.log(k/i,2))  
  if need > 0:
    pi += (1/2) ** need
  else :
    pi +=1      
print(pi/n)    

Fixed submission:
import math
n,k = map(int,input().split())
 
pi = 0
for i in range(1,n+1):
  need = math.ceil(math.log(k/i,2))  
  if need > 0:
    pi += (1/2) ** need
  else :
    pi +=1      
print(pi/n)
Buggy python submission (verdict: Runtime Error):
n = int(input())
uvw = [list(map(int,input().split())) for _ in range(n-1)]

uvw =sorted(uvw,key = lambda x:(x[0],x[1]))
tree={}
tree[uvw[0][0]]=0  

for i in range(n-1):
  # treeと一致しているやつ
  if uvw[i][0] in tree:
    left = uvw[i][1]
    right = uvw[i][0]
  else:
    left = uvw[i][0]
    right = uvw[i][1]    
      
  if uvw[i][2]%2==0:
    tree[left] = tree[right]
  else:
    tree[left] = abs(tree[right]-1) 

if sum(tree.values())==0:
  tree[uvw[0][0]]=1

for item in sorted(tree.items()):
  print(item[1])

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

n = int(input())
uvw = [list(map(int,input().split())) for _ in range(n-1)]

e =[[] for _ in range(n)]
color = [-1]*n
dw = {}

for u,v,w in uvw:
  e[u-1].append(v-1)
  e[v-1].append(u-1)
  dw[(u-1,v-1)] = dw[(v-1,u-1)] = w

def dfs(i,c)  :
  color[i] = c
  for ei in e[i]:
    if color[ei] != -1:
      continue
    dfs(ei, c+dw[(i,ei)])

dfs(0,0)   

for c in color:
  print(c%2)

Buggy python submission (verdict: Runtime Error):
n = int(input())
uvw = [list(map(int,input().split())) for _ in range(n-1)]

uvw =sorted(uvw,key = lambda x:(x[0],x[1]))
tree={}
tree[uvw[0][0]]=0  

for i in range(n-1):
  # treeと一致しているやつ
  if uvw[i][0] in tree:
    left = uvw[i][1]
    right = uvw[i][0]
  else:
    left = uvw[i][0]
    right = uvw[i][1]    
      
  if uvw[i][2]%2==0:
    tree[left] = tree[right]
  else:
    tree[left] = abs(tree[right]-1) 

if sum(tree.values())==0:
  tree[1]=1

for item in sorted(tree.items()):
  print(item[1])

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

n = int(input())
uvw = [list(map(int,input().split())) for _ in range(n-1)]

e =[[] for _ in range(n)]
color = [-1]*n
dw = {}

for u,v,w in uvw:
  e[u-1].append(v-1)
  e[v-1].append(u-1)
  dw[(u-1,v-1)] = dw[(v-1,u-1)] = w

def dfs(i,c)  :
  color[i] = c
  for ei in e[i]:
    if color[ei] != -1:
      continue
    dfs(ei, c+dw[(i,ei)])

dfs(0,0)   

for c in color:
  print(c%2)
Buggy python submission (verdict: Runtime Error):
import re
count_ab = 0
b_a = 0
__a = 0
b__ = 0

for si in ss:
  count_ab += len(re.findall('AB',si))
  if si[0]=='B' and si[-1]=='A':
    b_a += 1
  elif si[0]=='B':
    b__ += 1
  elif si[-1]=='A':
    __a += 1
  else:
    pass

count_ab += min(__a, b__)
if abs(__a - b__) > 0 and b_a > 0:
  count_ab +=1

if b_a > 0:  
  count_ab += b_a - 1

print(count_ab)

Fixed submission:
import re

n = int(input())
ss = [input() for _ in range(n)]

count_ab = 0
b_a = 0
__a = 0
b__ = 0

for si in ss:
  count_ab += len(re.findall('AB',si))
  if si[0]=='B' and si[-1]=='A':
    b_a += 1
  elif si[0]=='B':
    b__ += 1
  elif si[-1]=='A':
    __a += 1
  else:
    pass

if b_a == 0:
  print(count_ab + min(__a,b__))
else:
  if __a == 0 and b__ == 0:
    print(count_ab + b_a - 1)
  else:
    print(count_ab + b_a + min(__a,b__))
Buggy python submission (verdict: Time Limit Exceeded):
import fractions

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

ans = 0

for i in range(n): # 無効にする
  cd = -1
  for j in range(n):
    if i==j:
      continue
    if cd < 0:
      cd = a[j]
    else :
      cd = fractions.gcd(cd,a[j])      
  if ans < cd:
    ans = cd
print(ans)

Fixed submission:
import fractions

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

ans = 0

ls = [0]*n
rs = [0]*n

for i in range(1,n):
  ls[i] = fractions.gcd(ls[i-1],a[i-1])
  rs[i] = fractions.gcd(rs[i-1],a[-i])

ans = 0
for i in range(n):        
    ans = max(ans,fractions.gcd(ls[i],rs[-i-1]))

print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
d = {}
for i in range(n):
  for ri in ret_dividable(a[i]):
    if ri in d.keys():
      d[ri]+=1
    else:
      d[ri]=1 

# 出現数が1番目に多い値を取得(二段階で並べ替え)
tmp = sorted(d.items(),key = lambda x:(x[1],x[0]) ,reverse=True)


# 全ての ai が同じ場合、答えは ai
issame = (sum([1 for ai in a if ai==a[0]]) == n)
if issame:
  print(a[0])
else:  
  # 出現数が2番目に多いものだけ抜き取る
  freq_2 = [t for t in tmp if t[1]==n-1]
  if len(freq_2)>0:
    print(freq_2[0][0])
  else:
    print(1)

Fixed submission:
import fractions

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

ans = 0

ls = [0]*n
rs = [0]*n

for i in range(1,n):
  ls[i] = fractions.gcd(ls[i-1],a[i-1])
  rs[i] = fractions.gcd(rs[i-1],a[-i])

ans = 0
for i in range(n):        
    ans = max(ans,fractions.gcd(ls[i],rs[-i-1]))

print(ans)