Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02715 (python)

Fixed submission:
MOD = 10**9+7
n,k = map(int,input().split())

L = [0]*(k+1)

for i in range(k,0,-1):    
  L[i] = pow(k//i,n,MOD)
  for j in range(2,k//i+1):        
    L[i] -= L[i*j]
  
ans = 0
for i in range(1,k+1):  
  ans = (ans + i*L[i]) % MOD
  
print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 10**9+7
n,k = map(int,input().split())

L = [0]*(k+1)

for i in range(k,0,-1):    
  L[i] = pow(k//i,n,mod)
  for j in range(2,k//i+1):        
    L[i] -= L[i*j]
  
ans = 0
for i in range(1,k+1):  
  ans = (ans + i*L[i]) % MOD
  
print(ans)
Problem p02760 (python)

Fixed submission:
A = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
B = [int(input()) for _ in range(n)]

F = [0]*101
for b in B:
  F[b]=1

ans = 'No'  
for i in range(3):
  c = 0
  d = 0
  for j in range(3):    
    c += F[A[i][j]]
    d += F[A[j][i]]
  if c==3 or d==3:
    ans ='Yes'
if F[A[0][0]]+F[A[1][1]]+F[A[2][2]] == 3 or F[A[0][2]]+F[A[1][1]]+F[A[2][0]] == 3:
  ans ='Yes'
  
print(ans)

Buggy submission (verdict: Runtime Error):
A = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
B = [int(input()) for _ in range(n)]

F = [0]*100
for b in B:
  F[b]=1

ans = 'No'  
for i in range(3):
  c = 0
  d = 0
  for j in range(3):    
    c += F[A[i][j]]
    d += F[A[j][i]]
  if c==3 or d==3:
    ans ='Yes'
if F[A[0][0]]+F[A[1][1]]+F[A[2][2]] == 3 or F[A[0][2]]+F[A[1][1]]+F[A[2][0]] == 3:
  ans ='Yes'
  
print(ans)

Buggy submission (verdict: Runtime Error):
A = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
B = [int(input()) for _ in range(n)]

F = [0]*100
for b in B:
  F[b]=1

ans = 'No'  
for i in range(3):
  c = 0
  d = 0
  for j in range(3):    
    c += F[A[i][j]]
    c += F[A[j][i]]
  if c==3 or d==3:
    ans ='Yes'
if F[A[0][0]]+F[A[1][1]]+F[A[2][2]] == 3 or F[A[0][2]]+F[A[1][1]]+F[A[2][0]] == 3:
  ans ='Yes'
  
print(ans)
Problem p02768 (python)

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

MOD = 10**9+7

def cmb(n,r,mod):        
    ret=1
    div = min(r,n-r)
    for i in range(div):        
        ret=ret*(n-i)*pow(div-i,mod-2,mod)%mod
        
    return ret % mod

ans = 1
ans = ans * pow(2,n,MOD)
ans = (ans - 1) % MOD

ans = (ans - cmb(n,a,MOD))%MOD
ans = (ans - cmb(n,b,MOD))%MOD

print(ans)

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

MOD = 10**9 + 7
m = 2*10**5
mm = 2** m

ans = 1
for _ in range(n // m):
  ans = (ans * mm) % MOD

ans = (ans * 2**(n % m)) % MOD  
    
ans = (ans - 1) % MOD

ans = (ans - cmb(n,a,MOD))%MOD
ans = (ans - cmb(n,b,MOD))%MOD

print(ans)
Problem p02780 (python)

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

P = [(v+1)/2 for v in P]

acum = [0]*(n+1)
for i in range(n):
  acum[i+1] = acum[i] + P[i]
  
total = [0]*(n-k+1)
for i in range(n-k+1):
  total[i] = acum[i+k]-acum[i]  
  
print(max(total))

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

P = [(v+1)/2 for v in P]

acum = [0]*(n+1)
for i in range(n):
  acum[i+1] = acum[i] + P[i]
  
total = [0]*k
for i in range(k):
  total[i] = acum[i+k]-acum[i]  
  
print(max(total))
Problem p02814 (python)

Fixed submission:
from math import ceil
def gcd(a,b):
  while b:
    a,b = b,a%b  
  return a

def lcm(a,b):
  return a*b//gcd(a,b)  
  
n,m = map(int,input().split())
A = list(map(int,input().split()))

A = [a//2 for a in A]

pre = None
for a in A:
  c = 0
  while a % 2 ==0:
    a //= 2 
    c += 1    
  if pre is None:    
    pre = c
  elif pre != c:
    print(0)
    exit()

if n == 1:
  ans = A[0]
else:
  ans = lcm(A[0],A[1])  
  for i in range(n-2):  
    if ans > m:
      print(0)
      exit()
    ans = lcm(ans,A[i+2])  

print(ceil((m//ans)/2))

Buggy submission (verdict: Runtime Error):
from math import ceil
def gcd(a,b):
  while b:
    a,b = b,a%b  
  return a

def lcm(a,b):
  return a*b//gcd(a,b)  
  
n,m = map(int,input().split())
A = list(map(int,input().split()))

A = [a//2 for a in A]

pre = None
for a in A:
  c = 0
  while a % 2 ==0:
    a //= 2 
    c += 1    
  if pre is None:    
    pre = c
  elif pre != c:
    print(0)
    exit()
  
ans = lcm(A[0],A[1])  
for i in range(n-2):  
  if ans > m:
    print(0)
    exit()
  ans = lcm(ans,A[i+2])  

print(ceil((m//ans)/2))

Buggy submission (verdict: Runtime Error):
from math import ceil
def gcd(a,b):
  while b:
    a,b = b,a%b  
  return a

def lcm(a,b):
  return a*b//gcd(a,b)  
  
n,m = map(int,input().split())
A = list(map(int,input().split()))

A = [a//2 for a in A]

pre = None
for a in A:
  c = 0
  while a % 2 ==0:
    a //= 2 
    c += 1    
  if pre is None:    
    pre = c
  elif pre != c:
    print(0)
    exit()
  
ans = lcm(A[0],A[1])  
for i in range(n-2):  
  if ans > m:
    print(0)
    exit()
  for i in range(len(A)-2):
    ans = lcm(ans,A[i+2])  

print(ceil((m//ans)/2))

Buggy submission (verdict: Runtime Error):
from math import ceil
def gcd(a,b):
  while b:
    a,b = b,a%b  
  return a

def lcm(a,b):
  return a*b//gcd(a,b)  
  
n,m = map(int,input().split())
A = list(map(int,input().split()))

A = [a//2 for a in A]

pre = None
for a in A:
  c = 0
  while a % 2 ==0:
    a //= 2 
    c += 1    
  if pre is None:    
    pre = c
  elif pre != c:
    print(0)
    exit()
  
ans = lcm(A[0],A[1])  
for i in range(n-2):  
  if ans > m:
    ans = 0
    break
  for i in range(len(A)-2):
    ans = lcm(ans,A[i+2])  

print(ceil((m//ans)/2))
Problem p02818 (python)

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

ans_t = max(a-k,0)
if a-k < 0:
  b = max(b-(k-a),0)
print(ans_t,b)

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

ans_t = max(a-k,0)
if a-k < 0:
  ans_a = max(b-(k-a),0)
print(ans_t,ans_a)
Problem p02850 (python)

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 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')
Problem p02922 (python)

Fixed submission:
a,b = map(int,input().split())
n = (b-1)/(a-1)
print(-int((-n)//1))

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

print(i)
Problem p02936 (python)

Fixed submission:
from collections import deque

n,q = map(int,input().split())
cnt = [0]*(n+1)
g=[[] for _ in range(n+1)]

for _ in range(n-1):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
  
for _ in range(q): 
  v,val=map(int,input().split())
  cnt[v]+=val    
  
q = deque()
q.append(1)
checked = [0]*(n+1) 
while q:
  v = q.pop()
  checked[v] = 1
  for vc in g[v]:
    if checked[vc] == 1:
      continue
    else:
      cnt[vc] += cnt[v]
      q.append(vc)
    
print(*cnt[1:])

Buggy submission (verdict: Runtime Error):
n,q = map(int,input().split())
dic = {i:[] for i in range(n)}
for i in range(n-1):  
  a,b = map(int,input().split())
  dic[a-1].append(b-1)
  dic[b-1].append(a-1)

P = [0]*n
for i in range(q):
  p,x = map(int,input().split())
  P[p-1] += x
     
visited = [0]*n
ans = [0]*n

def dfs(v,p):
  ans[v] = p + P[v]
  visited[v] = 1
  
  for nv in dic[v]:
    if visited[nv] == 0:
      dfs(nv,ans[v])
        
dfs(0,0)
print(*ans)

Buggy submission (verdict: Runtime Error):
def dfs(v):
  checked[v] = 1  
  for u in g[v]:    
    if checked[u]:
      continue
    ab.append([v,u])
    dfs(u)   

n,q = map(int,input().split())
cnt = [0]*(n+1)
g=[[] for _ in range(n+1)]

for _ in range(n-1):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)

ab = []
checked = [0]*(n+1)
dfs(1)

cnt = [0]*(n+1)    
for i in range(q):
  p,x = map(int,input().split())
  cnt[p] += x
  
for a,b in ab:
  cnt[b] += cnt[a]      
  
print(*cnt[1:])

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

dic = {i+1:[] for i in range(n)}
for a,b in ab:
  dic[a].append(b)
  
vs=[0]*n

def plus(v,p):
  vs[v-1]+=p
  for nv in dic[v]:
    plus(nv,p)  

for p,x in px:    
  plus(p,x)    

print(' '.join(map(str,vs)))
Problem p02953 (python)

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 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)

Buggy 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)
Problem p02985 (python)

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 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 )
Problem p02993 (python)

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 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))

Buggy 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)
Problem p02995 (python)

Fixed submission:
def gcd(a,b):
  while b:
    a,b = b,a % b    
  return a

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

a_c = (a-1)//c
a_d = (a-1)//d
a_cd = (a-1)//(c*d//gcd(c,d))

b_c = b//c
b_d = b//d
b_cd = b//(c*d//gcd(c,d))

bb = b - (b_c + b_d - b_cd) 
aa = (a-1) - (a_c + a_d - a_cd)

print(bb - aa)

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

a_c = (a-1)//c
a_d = (a-1)//d
a_cd = (a-1)//(c*d//gcd(c,d))

b_c = b//c
b_d = b//d
b_cd = b//(c*d//gcd(c,d))

bb = b - (b_c + b_d - b_cd) 
aa = (a-1) - (a_c + a_d - a_cd)

print(bb - aa)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
  while b:
    a,b = b,a%b
  return a

a,b,c,d=map(int,input().split())
al = b-a+1

x = int(b/c) -int((a-1)/c)
y = int(b/d) -int((a-1)/d)
lcm_xy = int(c*d/math.gcd(c,d))
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)

print(al-(x+y-xy))

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d=map(int,input().split())
al = b-a+1

x = int(b/c)
y = int(b/d)
lcm_xy = int(c*d/math.gcd(c,d))
xy = int(b/lcm_xy)
bb = x+y-xy

x = int(a/c)
y = int(a/d)
xy = int(a/lcm_xy)
aa = x+y-xy
print(al - (bb -aa))

Buggy submission (verdict: Runtime Error):
import math
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/gcd(c,d))
# cdの最小公倍数で割り切れる個数
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)
#print(x,y,xy,al)
print(al-(x+y-xy))

Buggy 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))

Buggy submission (verdict: Runtime Error):
import math
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))

Buggy submission (verdict: Runtime Error):
import math

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))

Buggy submission (verdict: Runtime Error):
import math

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))

Buggy submission (verdict: Runtime Error):
import math

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(a*b/math.gcd(a,b))
# cdの最小公倍数で割り切れる個数
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)
#print(x,y,xy,al)
print(al-(x+y-xy))
Problem p03006 (python)

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 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()))
Problem p03032 (python)

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 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)

Buggy 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)
Problem p03043 (python)

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 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)
Problem p03044 (python)

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 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])

Buggy 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])
Problem p03049 (python)

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 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)
Problem p03061 (python)

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 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)
Problem p03074 (python)

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

sp = []
if s[0]=='0':
  sp.append(0)

count=0
for si in s:
  if count==0:
    flag = si
    count=1
  elif flag == si:
    count+=1
  else:        
    sp.append(count)
    flag = si
    count=1
if count>0:
  sp.append(count)
if s[-1]=='0':
  sp.append(0)

ss=[0]
ss.append(sp[0])
count = 0
for spi in sp[1:]:
  ss.append(ss[-1]+spi)  

ans = 0
for left in range(0,len(ss),2):
  right = left+2*k+1
  if right >= len(ss): #!!
    right = len(ss)-1
  ans = max(ans,ss[right]-ss[left])    

print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
s = input()

sp = []
if s[0]=='1':
  sp.append(0)

count=0
for si in s:
  if count==0:
    flag = si
    count=1
  elif flag == si:
    count+=1
  else:        
    sp.append(count)
    flag = si
    count=1
if count>0:
  sp.append(count)
if s[-1]=='1' and flag=='1':
  sp.append(0)
  
ss=[]
for i in range(len(sp)-2*k+1):
  if i%2==0:    
    ss.append(sum(sp[i:i+2*k]))
  else:
    ss.append(sum(sp[i:i+2*k+1]))
print(max(ss))
Problem p03076 (python)

Fixed submission:
a = [int(input()) for _ in range(5)]
b = [i%10 for i in a if i%10 !=0]
if len(b)==0:
  b=0
else:
  b= 10 - min(b)
print(sum([((i + 9)//10 *10) for  i in a]) - b)

Buggy submission (verdict: Runtime Error):
a = [int(input()) for _ in range(5)]
b = min([i%10 for i in a if i%10 != 0],0)
print(sum([((i + 9)//10 *10) for  i in a]) - (10-b) )

Buggy submission (verdict: Runtime Error):
a = [int(input()) for _ in range(5)]
b = min([i%10 for i in a if i%10 != 0])
print(sum([((i + 9)//10 *10) for  i in a]) - (10-b) )
Problem p03138 (python)

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

b = 1
c = 0
while b <= k:
  b *= 2
  c += 1

B = [0]*(c)
for a in A:
  for i in range(c):
    if a>>i & 1 :      
      B[i] += 1
      
x = 0
for b in range(c,-1,-1):
  if x + (1<<b) > k:
    continue
  if B[b] < (n+1)//2:
    x += 1<<b
    
ans = 0
for a in A:
  ans += x^a
print(ans)

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

b = 1
c = 0
while b <= k:
  b *= 2
  c += 1

B = [0]*(c+1)
for a in A:
  for i in range(c):
    if a>>i & 1 :      
      B[i] += 1
    
x = 0
for i in range(c):
  if B[i] <= n/2:
    x += 1<<i
    
flag = 0    
for i in range(c):
  if k>>(4-i) == 0 and x>>(4-i)==1:
    x -= 1<<(4-i)
    break

ans = 0
for a in A:
  ans += x^a
  
print(ans)

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

b = 1
c = 0
while b <= k:
  b *= 2
  c += 1

B = [0]*c
for a in A:
  for i in range(c):
    if a>>i & 1 :      
      B[i] += 1
    
x = 0
for i in range(c):
  if B[i] <= n/2:
    x += 1<<i
    
flag = 0    
for i in range(c):
  if k>>(4-i) == 0 and x>>(4-i)==1:
    x -= 1<<(4-i)
    break

ans = 0
for a in A:
  ans += x^a
  
print(ans)
Problem p03145 (python)

Fixed submission:
a = list(map(int,input().split()))
a = sorted(a)
print(int(a[0]*a[1]/2))

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split())
a = sorted(a)
print(a[0]*a[1]/2)