Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 文字列の入力
S = str(input())

ans=0

if len(S)==1:
  ans=0
elif len(S)==2:
  if S[0]==S[1]:
    ans=1
  else:
    ans=0
else: #3枚以上はちゃんと読み込む
  strint=[]
  original_string=[]
  
  for i in range(len(S)):
    string.append(S[i])
    original_string.append(S[i])
    
  for i in range(len(S)-2):
    gramed = str(string[i])+str(string[i+1])+str(string[i+2])
    
    if gramed=="000":
      string[i+1]="1"
    if gramed=="001":
      string[i]="1"
    if gramed=="011":
      string[i+2]="0"
    if gramed=="110":
      string[i]="0"
    if gramed=="100":
      string[i+2]="1"
    if gramed=="111":
      string[i+1]="1"
  
  #print(string)
  #print(original_string)
  
  for i in range(len(S)):
    if original_string[i]!=string[i]:
      ans=ans+1
  
print(ans)

Fixed submission:
#124c
S = str(input())
#################01234567
ans_b_start = 0 #01010101…
ans_w_start = 0 #10101010…

for i in range(len(S)):
    if i%2==0:
        if S[i]=="0":
            ans_w_start+=1
        if S[i]=="1":
            ans_b_start+=1
    if i%2==1:
        if S[i]=="0":
            ans_b_start+=1
        if S[i]=="1":
            ans_w_start+=1
        
if ans_w_start > ans_b_start:
    print(ans_b_start)
else:
    print(ans_w_start)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 文字列の入力
S = str(input())

ans=0

if len(S)==1:
  ans=0
elif len(S)==2:
  if S[0]==S[1]:
    ans=1
  else:
    ans=0
else: #3枚以上はちゃんと読み込む
  strint=[]
  original_string=[]
  
  for i in range(len(S)):
    string.append(S[i])
    original_string.append(S[i])
    
  for i in range(len(S)-2):
    gramed = str(string[i])+str(string[i+1])+str(string[i+2])
    
    if gramed=="000":
      string[i+1]="1"
    if gramed=="001":
      string[i]="1"
    if gramed=="011":
      string[i+2]="0"
    if gramed=="110":
      string[i]="0"
    if gramed=="100":
      string[i+2]="1"
    if gramed=="111":
      string[i+1]="1"
  
  print(string)
  print(original_string)
  
  for i in range(len(S)):
    if original_string[i]!=string[i]:
      ans=ans+1
  
print(ans)

Fixed submission:
#124c
S = str(input())
#################01234567
ans_b_start = 0 #01010101…
ans_w_start = 0 #10101010…

for i in range(len(S)):
    if i%2==0:
        if S[i]=="0":
            ans_w_start+=1
        if S[i]=="1":
            ans_b_start+=1
    if i%2==1:
        if S[i]=="0":
            ans_b_start+=1
        if S[i]=="1":
            ans_w_start+=1
        
if ans_w_start > ans_b_start:
    print(ans_b_start)
else:
    print(ans_w_start)
Buggy python submission (verdict: Runtime Error):
#122c
N,Q = map(int, input().split())
S = str(input())

for _ in range(Q):
    l,r = map(int, input().split())
    print(S[l-1:r].count('AC'))

Fixed submission:
S = list(input())
ACGT = set(["A","C","G","T"])
ans = 0
acgt_length = 0

for i in range(len(S)):
  if S[i] in ACGT:
    acgt_length += 1
  else:
    ans = max(ans,acgt_length)
    acgt_length = 0
    
ans = max(ans,acgt_length)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#122c
N,Q = map(int, input().split())
S = str(input())

for _ in range(Q):
    l,r = map(int, input().split())
    print(S[l-1:r].count('AC'))

Fixed submission:
#122c
#累積和
N,Q = map(int, input().split())
S = list(input())

AC_cumsum = list()
AC_cumsum.append(0)

for i in range(1,N):
    #print(S[i])
    if S[i-1]=="A" and S[i]=="C":
        AC_cumsum.append(AC_cumsum[-1] + 1)
    else:
        AC_cumsum.append(AC_cumsum[-1])
        
#print(AC_cumsum)
    
for i in range(Q):
    l,r = map(int, input().split())
    print(AC_cumsum[r-1] - AC_cumsum[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy

# スペース区切りの整数の入力
A,B = map(int, input().split())

ans = A

for i in range(A+1,B+1,1):
  ans=ans^i
  
print(ans)

Fixed submission:
# -*- coding: utf-8 -*-
import numpy

# スペース区切りの整数の入力
A,B = map(int, input().split())

num = B-A+1

if A%2==0:
  if num%4==0:
    print("0")
  elif num%4==1:
    print(B)
  elif num%4==2:
    print("1")
  else: #num%4==3:
    print(B^1)
else:
  if num%4==0:
    print(A^B^1)
  elif num%4==1:
    print(A)
  elif num%4==2:
    print(A^B)
  else: #num%4==3:
    print(A^1)
Buggy python submission (verdict: Runtime Error):
# スペース区切りの整数の入力
A,B,K = map(int, input().split())

import math

divisor = math.gcd(A,B)
counter = 1

if K==1:
  print(divisor)
  
else:
  divisor-=1
  while(divisor>=0):
    #print(divisor)
    
    if A%divisor==0 and B%divisor==0:
      counter+=1
      #print("count",counter)
      
      if counter==K:
        break
        
    divisor-=1
    
  print(divisor)

Fixed submission:
import fractions

# スペース区切りの整数の入力
A,B,K = map(int, input().split())

divisor = fractions.gcd(A,B)
counter = 1

if K==1:
  print(divisor)
  
else:
  divisor-=1
  while(divisor>=0):
    #print(divisor)
    
    if A%divisor==0 and B%divisor==0:
      counter+=1
      #print("count",counter)
      
      if counter==K:
        break
        
    divisor-=1
    
  print(divisor)

Buggy python submission (verdict: Runtime Error):
# スペース区切りの整数の入力
A,B,K = map(int, input().split())

import math

divisor = math.gcd(A,B)
counter = 1

if K==1:
  print(divisor)
  
else:
  divisor-=1
  while(divisor>=0):
    #print(divisor)
    
    if A%divisor==0 and B%divisor==0:
      counter+=1
      #print("count",counter)
      
      if counter==K:
        break
        
    divisor-=1
    
  print(divisor)
  
  

Fixed submission:
import fractions

# スペース区切りの整数の入力
A,B,K = map(int, input().split())

divisor = fractions.gcd(A,B)
counter = 1

if K==1:
  print(divisor)
  
else:
  divisor-=1
  while(divisor>=0):
    #print(divisor)
    
    if A%divisor==0 and B%divisor==0:
      counter+=1
      #print("count",counter)
      
      if counter==K:
        break
        
    divisor-=1
    
  print(divisor)
Buggy python submission (verdict: Runtime Error):
# スペース区切りの整数の入力
N,M = map(int, input().split())
A_list=[]
food_list=[]

for i in range(N):
  A_list.append([int(e) for e in input().split()])

for i in range(M):
  food_list.append(0)
  
for i in range(N):
  K=A_list[i][0]
  for j in range(1,K+1):
    #print(A_list[i][j],end="")
    food_list[A_list[i][j]-1]+=1

ans=0
    
for i in range(M):
  if food_list[i]==N:
    ans+=1
    
print(ans)

Fixed submission:
# スペース区切りの整数の入力
A,B = map(int, input().split())

if B%A==0:
  print(A+B)
else:
  print(B-A)
Buggy python submission (verdict: Runtime Error):
#118c
N = int(input())
A_list = list(input())

import fractions #math
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

print(gcd_list(A_list))

Fixed submission:
#118c
#最小公倍数
N = int(input())
A_list = [int(e) for e in input().split()]

#######################################
#https://note.nkmk.me/python-gcd-lcm/
#import math
import fractions
from functools import reduce

def gcd(*numbers):
    #return reduce(math.gcd, numbers)
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    #return reduce(math.gcd, numbers)
    return reduce(fractions.gcd, numbers)
#######################################

print(gcd(*A_list))
Buggy python submission (verdict: Runtime Error):
N = int(input())
T, A = map(int, input().split())
H_list = [int(e) for e in input().split()]

diff=1000000
ans = 0

for i in H_list:
	 
    if abs(A-(T−i*0.006)) < diff
    	diff = abs(A-(T−i*0.006))
        ans=i
        
print(ans)

Fixed submission:
N = int(input())
T, A = map(int, input().split())
H_list = [int(e) for e in input().split()]
     
diff=1000000
ans = 0
     
for i in range(len(H_list)):
  if abs(T-H_list[i]*0.006-A)<diff:
    diff = abs(T-H_list[i]*0.006-A)
    ans = i
    
print(ans+1)
Buggy python submission (verdict: Runtime Error):
N,T = map(int, input().split())

min_t = T + 1
ans = "TLE"

for i in range(N):
  c,t = map(int, input().split())
  if t<min_t:
    min_t = t
    ans = c
  elif t==min_t:
    if ans>c:
      ans=c
print(ans)

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

ans = 10000

for i in range(N):
  c,t = map(int, input().split())
  
  if t<=T and c<ans:
    ans=c

if ans!=10000:
  print(ans)
else:
  print("TLE")
Buggy python submission (verdict: Runtime Error):
N = int(input())

xyh_list = list()

for i in range(N):
    x,y,h = map(int, input().split())
    xyh_list.append((x,y,h))
    
for i in range(N):
    h = xyh_list[i][2]
    if h != 0:
        no_zero_h = i
        break
else:


break_flag = 0

for i in range(0,101):
    for j in range(0,101):
        
        x = xyh_list[no_zero_h][0]
        y = xyh_list[no_zero_h][1]
        h = xyh_list[no_zero_h][2]
        H = h + abs(x-i) + abs(y-j)
        
        if 1 <= H:
            for k in range(0,N):
                x = xyh_list[k][0]
                y = xyh_list[k][1]
                h = xyh_list[k][2]
                
                if h + abs(x-i) + abs(y-j) != H:
                    break
            else:
                print(i,j,H)
                break_flag = 1
                
        if break_flag == 1:
            break
            
    if break_flag == 1:
        break

Fixed submission:
N = int(input())

xyh_list = list()

for i in range(N):
    x,y,h = map(int, input().split())
    xyh_list.append((x,y,h))
    
for i in range(N):
    h = xyh_list[i][2]
    if h != 0:
        no_zero_h = i
        break


break_flag = 0

for i in range(0,101):
    for j in range(0,101):
        
        x = xyh_list[no_zero_h][0]
        y = xyh_list[no_zero_h][1]
        h = xyh_list[no_zero_h][2]
        H = h + abs(x-i) + abs(y-j)
        
        if 1 <= H:
            for k in range(0,N):
                x = xyh_list[k][0]
                y = xyh_list[k][1]
                h = xyh_list[k][2]
                
                if (h != 0 and h + abs(x-i) + abs(y-j) != H) or (h == 0 and H - abs(x-i) - abs(y-j) > 0):
                    break
            else:
                print(i,j,H)
                break_flag = 1
                
        if break_flag == 1:
            break
            
    if break_flag == 1:
        break
Buggy python submission (verdict: Runtime Error):
    A, B = map(int, input().split())
     
    if A*B%2==0:
      print("No")
    else:
      print("Yes")

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

if A*B%2==0:
  print("No")
else:
  print("Yes")

Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

if A*B%2=0:
  print("No")
else:
  print("Yes")

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

if A*B%2==0:
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
#108b
import math

x1,y1,x2,y2 = map(int, input().split())

#正方形なのでベクトル(x2,y2)→(x3,y3)とベクトル(x2,y2)→(x1,y1)は同じ長さで直交している。
#(x3-x2)=xA
#(y3-y2)=yA
#(x1-x2)=xB
#(y1-y2)=yB
#とする。

#・大きさ同じ
# (x3-x2)**2+(y3-y2)**2 = (x1-x2)**2+(y1-y2)**2
# xA**2 + yA**2 = xB**2 + yB**2
#・直交→内積は0
# (x3-x2)*(x1-x2) + (y3-y2)*(y1-y2) = 0
# xA * xB = yA * yB

#整理すると
#yA = xA * xB / yB
#xA**2 + yA**2 = xB**2 + yB**2
#xA**2 + (xA * xB / yB)**2 = xB**2 + yB**2
#xA**2 * {1 + (xB / yB)**2)} = xB**2 + yB**2
#xA**2 = {xB**2 + yB**2} / {1 + (xB / yB)**2}

#xA = ±sqrt({xB**2 + yB**2} / {1 + (xB / yB)**2})
#yA = xA * xB / yB

xB = x1 - x2
yB = y1 - y2

xA = math.sqrt((xB**2 + yB**2) / (1 + (xB / yB)**2))
yA = xA * xB / yB
y3 = yA + y2

xA = -1 * math.sqrt((xB**2 + yB**2) / (1 + (xB / yB)**2))
yA = xA * xB / yB
x3 = xA + x2

###############################################################
#上と同様に考える
#xA = x4-x1
#yA = y4-y1
xB = x2 - x1
yB = y2 - y1

xA = math.sqrt((xB**2 + yB**2) / (1 + (xB / yB)**2))
yA = xA * xB / yB
y4 = yA + y1

xA = -1 * math.sqrt((xB**2 + yB**2) / (1 + (xB / yB)**2))
yA = xA * xB / yB
x4 = xA + x1

print(int(x3),int(y3),int(x4),int(y4))

Fixed submission:
def get_ans(x1,y1,x2,y2):
    def_x = abs(x2-x1)
    def_y = abs(y2-y1)

    if x2 < x1 and y2 <= y1:
        x3 = x2+def_y
        y3 = y2-def_x
        x4 = x1+def_y
        y4 = y1-def_x 
    elif y2 < y1 and x1 <= x2:
        x3 = x2+def_y
        y3 = y2+def_x
        x4 = x1+def_y
        y4 = y1+def_x     
    elif x2 > x1 and y1 <= y2:
        x3 = x2-def_y
        y3 = y2+def_x
        x4 = x1-def_y
        y4 = y1+def_x 
    elif y2 > y1 and x1 >= x2:
        x3 = x2-def_y
        y3 = y2-def_x
        x4 = x1-def_y
        y4 = y1-def_x

    print(x3,y3,x4,y4)
    #return x3,y3,x4,y4

x1,y1,x2,y2 = map(int, input().split())
get_ans(x1,y1,x2,y2)
Buggy python submission (verdict: Runtime Error):
import copy
import itertools

N = int(input())
six_nines = set()

#6,9の乗数を列挙する
for i in range(1,6):
  a = 6**i
  if a <= N and a not in six_nines:
    six_nines.add(a)
    for j in range(1,N//a):
      six_nines.add(a*j)
  a = 9**i
  if a <= N and a not in six_nines:
    six_nines.add(a)
    for j in range(1,N//a):
      six_nines.add(a*j)

comb_six_nines = copy.copy(six_nines)

#6,9の乗数の和を列挙する
for comb in itertools.combinations(six_nines,2):
  if comb[0]+comb[1] <= N and comb[0]+comb[1] not in comb_six_nines:
    comb_six_nines.add(comb[0]+comb[1])

#comb_six_nines = list(comb_six_nines)
#comb_six_nines.sort(reverse=True)
#comb_six_nines.append(1)
six_nines = list(six_nines)
six_nines.sort(reverse=True)
six_nines.append(1)

#print(comb_six_nines)
print(six_nines)

#Nを列挙した中の大きい方から引いていく
ans = 0
while N != 0:
  for comb in six_nines:
    if N >= comb:
      print(N,comb)
      if N 
      N -= comb
      ans += 1

print(ans)

Fixed submission:
#99c
import math

N = int(input()) #<=100000

#引き算を足し算で下から求める

#直で引き出せる一覧のsetを作る。
single_withdraw_set = set()
single_withdraw_set.add(1)
single_withdraw_set |= {6**i for i in range(1,2 + int(math.log(N,6)))}
single_withdraw_set |= {9**i for i in range(1,2 + int(math.log(N,9)))}
#print(single_withdraw_set)

#何回で引き出せるかのdict。この後の計算でマイナス値を参照するので、あらかじめ作っておく。
withdraw_dict = {int(-i):10**9+7 for i in range(1,1 + max(single_withdraw_set)) }
withdraw_dict[0] = 0

#最低の引き出し回数を1円から計算していく
for i in range(1,N+1):
    if i in single_withdraw_set:
        #1回で引き出せるsetにあるなら当然1回
        withdraw_dict[i] = 1
    else:
        #なければ (現状の値 - 1回で引き出し可能な値)の中で1番少ない値 + 1 
        withdraw_dict[i] = 1 + min([withdraw_dict[i-j] for j in single_withdraw_set])
    
    #print(i,":",withdraw_dict[i])
    
#print(withdraw_dict)
print(withdraw_dict[N])
Buggy python submission (verdict: Runtime Error):
#094c
N = int(input()) #N<200000=2 * 10**5
X_list = [int(e) for e in input().split()]

#l が奇数のとき，l 個の数 a1,a2,...,al の中央値とは，a1,a2,...,al の中で (l+1)/2番目に大きい値のことを言います．
#N個の数 X1,X2,...,XN が与えられます．ここで，N は偶数です． 
#i=1,2,...,N に対して，X1,X2,...,XN から Xi のみを除いたもの，すなわち X1,X2,...,Xi−1,Xi+1,...,XN の中央値を Biとします．
#i=1,2,...,Nに対して，Bi を求めてください．

X_list.sort(reverse=False)
print(X_list)
Bi_smaller = X_list[int(len(X_list)/2)]
Bi_bigger = X_list[int(len(X_list)/2 +1)]

for i in range(int(N/2)):
    print(Bi_bigger)
    
for i in range(int(N/2),N):
    print(Bi_smaller)

Fixed submission:
#094c
import copy
N = int(input()) #N<200000=2 * 10**5
X_list = [int(e) for e in input().split()]

sort_X_list = copy.copy(X_list)
sort_X_list.sort(reverse=False)
Bi_smaller = sort_X_list[int(len(X_list)/2-1)]
Bi_bigger = sort_X_list[int(len(X_list)/2)]

for i in range(N):
    if X_list[i]>=Bi_bigger:
        print(Bi_smaller)
    else:
        print(Bi_bigger)

Buggy python submission (verdict: Time Limit Exceeded):
#094c
import copy
N = int(input()) #N<200000=2 * 10**5
X_list = [int(e) for e in input().split()]
#print(X_list)

for i in range(N):
    copy_X_list = copy.copy(X_list)
    copy_X_list.pop(i)
    copy_X_list.sort(reverse=False)
    #print(copy_X_list)
    print(copy_X_list[int(len(X_list)/2) -1])

Fixed submission:
#094c
import copy
N = int(input()) #N<200000=2 * 10**5
X_list = [int(e) for e in input().split()]

sort_X_list = copy.copy(X_list)
sort_X_list.sort(reverse=False)
Bi_smaller = sort_X_list[int(len(X_list)/2-1)]
Bi_bigger = sort_X_list[int(len(X_list)/2)]

for i in range(N):
    if X_list[i]>=Bi_bigger:
        print(Bi_smaller)
    else:
        print(Bi_bigger)
Buggy python submission (verdict: Runtime Error):
#094d
from scipy.special import comb
from bisect import bisect_left, bisect_right

n = int(input())
a_list = [int(e) for e in input().split()]

#n 個のものから順番を無視して r 個を選ぶ場合の数を comb(n,r) と書くことにします。 
#n 個の非負の整数 a1,a2,...,an から 2 つの数 ai > aj を comb(ai,aj) が最大になるように選んで下さい。 
#最大になる組が複数ある場合、どれを選んでも構いません。

#全組み合わせはn*(n-1)≒10**10 地球爆発

#comb = n*(n-1)*…*(n-r) / r
#from scipy.special import combすれば = comb(n, r, exact=True) で計算可能
#nに最大の値、rにその半分の値(nが奇数なら±0.5)を使った時に大きい値をとることを下記で確認した。
#from scipy.special import comb

#for i in range(101):
#    max_comb = 0
#    max_comb_j = 1 
#    for j in range(1,i):
#        ij_comb = comb(i, j, exact=True) 
#        if ij_comb > max_comb:
#            max_comb = ij_comb
#            max_comb_j = j
#            
#    print(i,max_comb_j,max_comb)


#が、丁度良く半分の値があるとは限らない。
#∴n側は全探索して、rはbisectで半分の値を探る

a_list.sort(reverse=False)

#仮値を入れる
max_comb = comb(a_list[1], a_list[0], exact=True) 
max_comb_ai = a_list[1]
max_comb_aj = a_list[0]

#n側を全探索
for ai in a_list: #10**5
    aj_left = bisect_left(a_list, ai/2) #O(log N)…17回で探れる　∴17*10**5なので間に合いそう
    
    #半分に近い値を算出
    if a_list[aj_left] == ai/2:
        aj_list = [a_list[aj_left]]
    elif a_list[aj_left] < ai/2:
        if aj_left != n-1:
            aj_list = [a_list[aj_left],a_list[aj_left + 1]]
        else:
            aj_list = [a_list[aj_left]]
    elif a_list[aj_left] > ai/2:
        if aj_left != 0:
            aj_list = [a_list[aj_left],a_list[aj_left - 1]]
        else:
            aj_list = [a_list[aj_left]]
    
    #combを計算
    for aj in aj_list:
        temp_comb = comb(ai, aj, exact=True)
        if temp_comb > max_comb:
            max_comb = temp_comb
            max_comb_ai = ai
            max_comb_aj = aj
        
print(max_comb_ai,max_comb_aj)

Fixed submission:
#094d
import math

N = int(input()) #N<10**5
a_list = list(int(e) for e in input().split())
a_tuple = tuple(a_list)

comb_n = max(a_tuple)

a_list.remove(comb_n)
diff = min([abs(comb_n/2 - a) for a in a_list])
a_tuple = tuple(a_list)
if int(comb_n/2 + diff) in a_tuple:
    comb_r = comb_n/2 + diff
elif int(comb_n/2 - diff) in a_tuple:
    comb_r = comb_n/2 - diff  
    
print(int(comb_n),int(comb_r))
Buggy python submission (verdict: Runtime Error):
#75b
H,W = map(int, input().split())

S_list = [[0 for i in range(W+2)] for j in range(H+2)]

for i in range(1,H+1):
    S = list(input())
    S_list[i][1:W+1] = S
    
ans = [["#" for i in range(W+2)] for j in range(H+2)]
    
for i in range(1,H+1):
    for j in range(1,W+1):
        if S_list[i][j] != "#":            
            ans[i][j] = S_list[i-1][j-1:j+2].count("#") + S_list[i][j-1:j+2].count("#") + S_list[i+1][j-1:j+2].count("#")
            
for i in range(1,H+1):
    print(''.join(map(str, ans[i][1:-1])))

Fixed submission:
#75a
A,B,C = map(int, input().split())

if A==B:
    print(C)
elif A==C:
    print(B)
elif B==C:
    print(A)
Buggy python submission (verdict: Runtime Error):
#70c
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())

T_set = set()

for _ in range(N):
    t = int(input())
    T_set.add(t)
    
T_list = list(T_set)
print(lcm_list(T_list))


Fixed submission:
#70c
from functools import reduce
import math
import fractions

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())

T_set = set()

for _ in range(N):
    t = int(input())
    T_set.add(t)
    
T_list = list(T_set)
print(lcm_list(T_list))
Buggy python submission (verdict: Runtime Error):
#065b
N = int(input())
a_list=[0]

for i in range(N):
    ai = int(input())
    a_list.append(ai)

def push_button(pushed_button,pushed_button_set):
	if pushed_button == 2:
		print(len(pushed_button_set))
	else:
		if pushed_button in pushed_button_set:
			print(-1)
			return -1
		else:
			pushed_button_set.add(pushed_button)
			push_button(a_list[pushed_button],pushed_button_set)
			
push_button(1,set())

Fixed submission:
N = int(input())

button_dict = dict()

for i in range(1,N+1):
    button_dict[i] = int(input())

pushed_button_set = set()
i = 1
while 1:
    if i in pushed_button_set:
        print(-1)
        break
    elif i == 2:
        print(len(pushed_button_set))
        break
    else:
        pushed_button_set.add(i)
        i = button_dict[i]

Buggy python submission (verdict: Runtime Error):
#065b
N = int(input())
a_list=[0]

for i in range(N):
    ai = int(input())
    a_list.append(ai)
    
def push_button(pushed_button,ans):
    ans += 1
    #print(ans,":",pushed_button,a_list[pushed_button])
    
    if a_list[pushed_button] == 2:
        return ans
    elif a_list[pushed_button] == pushed_button or pushed_button == a_list[a_list[pushed_button]]:
        return -1
    else:
        ans = push_button(a_list[pushed_button],ans)
        return ans
        
#print(a_list)
print(push_button(1,0))

Fixed submission:
N = int(input())

button_dict = dict()

for i in range(1,N+1):
    button_dict[i] = int(input())

pushed_button_set = set()
i = 1
while 1:
    if i in pushed_button_set:
        print(-1)
        break
    elif i == 2:
        print(len(pushed_button_set))
        break
    else:
        pushed_button_set.add(i)
        i = button_dict[i]
Buggy python submission (verdict: Runtime Error):

N,M = map(int, input().split())

town_road_dict = {}

for i in range(M):
    a,b = map(int, input().split())
    
    if a not in town_road_dict:
        town_road_dict[a] = [b]
    else:
        town_road_dict[a].append(b)
    if b not in town_road_dict:
        town_road_dict[b] = [a]
    else:
        town_road_dict[b].append(a)
        
for i in range(N):
    print(len(town_road_dict[i+1]))

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

town_road = [0 for _ in range(N+2)]

for i in range(M):
    a,b = map(int, input().split())
           
    town_road[a] += 1
    town_road[b] += 1
        
for i in range(1,N+1):
    print(town_road[i])
Buggy python submission (verdict: Time Limit Exceeded):
#61c
N,K = map(int, input().split())

array = []

for i in range(N):
    a,b = map(int, input().split())
    array += [a for i in range(b)]
    
array.sort(reverse=False) #O( n・log(n) )
print(array[K-1])

Fixed submission:
#61c
#import random #テスト用

N,K = map(int, input().split())#N,K<=10**5　#Nのループで考えないとTLEしそう
#N = 100000 #test

a_b_dict = dict()

#b_sum = 0 #test

for i in range(N):
    a,b = map(int, input().split())
    #a = random.randint(1, 100000) #test
    #b = random.randint(1, 100000) #test
    
    if a not in a_b_dict:
        a_b_dict[a] = 0
    
    a_b_dict[a] += b
    
    #b_sum += b #test
    
a_b_dict_sorted = sorted(a_b_dict.items(), key=lambda x:x[0])

#K = random.randint(1, b_sum)

position = 0
for ab in a_b_dict_sorted:
    b = ab[1]
    position += b
    
    if position >= K:
        print(ab[0])
        break

Buggy python submission (verdict: Time Limit Exceeded):
#61c
N,K = map(int, input().split())

array = []

for i in range(N):
    a,b = map(int, input().split())
    array += [a for i in range(b)]
    
array.sort(reverse=False) #O( n・log(n) )
print(array[K-1])

Fixed submission:
#61c
#import random #テスト用

N,K = map(int, input().split())#N,K<=10**5　#Nのループで考えないとTLEしそう
#N = 100000 #test

a_b_dict = dict()

#b_sum = 0 #test

for i in range(N):
    a,b = map(int, input().split())
    #a = random.randint(1, 100000) #test
    #b = random.randint(1, 100000) #test
    
    if a not in a_b_dict:
        a_b_dict[a] = 0
    
    a_b_dict[a] += b
    
    #b_sum += b #test
    
a_b_dict_sorted = sorted(a_b_dict.items(), key=lambda x:x[0])

#K = random.randint(1, b_sum)

position = 0
for ab in a_b_dict_sorted:
    b = ab[1]
    position += b
    
    if position >= K:
        print(ab[0])
        break