Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

x, y, z, k = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

ab = [ai + bi for ai in a for bi in b]
ab.sort(reverse=True)
ab = ab[:k]

abc = [abi + ci for abi in ab for ci in c]
abc.sort(reverse = True)

for i in range(len(abc)):
  if i < k:
    print(abc[i])
  else:
    break

Fixed submission:
# coding: utf-8

x, y, z, k = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

ab = [ai + bi for ai in a for bi in b]
ab.sort(reverse=True)
ab = ab[:k]

abc = [abi + ci for abi in ab for ci in c]
abc.sort(reverse = True)

for i in range(len(abc)):
  if i < k:
    print(abc[i])
  else:
    break

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import math 

N = int(input())
abcde = [int(input()) for _ in range(5)]

time = 0
n = N
last = 0 # 最後の1回で移動する人数
for i in range(5):
  time +=  math.ceil(n / abcde[i])
  last = n % abcde[i]
  if last == 0:
    last = abcde[i]
  if i < 4: 
    n = last + max((N-last) - (time-1) * abcde[i+1], 0)


print(time)

Fixed submission:
# coding: utf-8

x, y, z, k = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

ab = [ai + bi for ai in a for bi in b]
ab.sort(reverse=True)
ab = ab[:k]

abc = [abi + ci for abi in ab for ci in c]
abc.sort(reverse = True)

for i in range(len(abc)):
  if i < k:
    print(abc[i])
  else:
    break
Buggy python submission (verdict: Runtime Error):
# coding: utf-8

A, B, C = map(int, input().split())

if A == B && B == C:
  print('Yes')
else:
  print('No')

Fixed submission:
# coding: utf-8

A, B, C = map(int, input().split())

if A == B and B == C:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
import numpy as np
input = sys.stdin.readline

N, Q = [int(i) for i in input().split()]
S = input()
is_AC = [S[i:i+2] == "AC" for i in range(N)]
AC_csum = np.cumsum(is_AC)

for i in range(Q):
  l, r = [int(i) for i in input().split()]
  ans = AC_csum[r-1] - AC_csum[l-1] - is_AC[r-1] + is_AC[l-1]
  print(ans)


Fixed submission:
# coding: utf-8
import sys
import numpy as np
input = sys.stdin.readline

N, Q = [int(i) for i in input().split()]
S = input()
is_AC = [False] * N
AC_csum = [0] * N
for i in range(N):
  is_AC[i] = S[i:i+2] == "AC"
  AC_csum[i] = AC_csum[i-1] + is_AC[i]

for i in range(Q):
  l, r = [int(i) for i in input().split()]
  ans = AC_csum[r-1] - AC_csum[l-1] - is_AC[r-1] + is_AC[l-1]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
input = sys.stdin.readline

N, Q = [int(i) for i in input().split()]
S = input()
is_AC = [S[i:i+2] == "AC" for i in range(N)]

for i in range(Q):
  l, r = [int(i) for i in input().split()]
  print(sum(is_AC[(l-1):r]) - is_AC[r-1])


Fixed submission:
# coding: utf-8
import sys
import numpy as np
input = sys.stdin.readline

N, Q = [int(i) for i in input().split()]
S = input()
is_AC = [False] * N
AC_csum = [0] * N
for i in range(N):
  is_AC[i] = S[i:i+2] == "AC"
  AC_csum[i] = AC_csum[i-1] + is_AC[i]

for i in range(Q):
  l, r = [int(i) for i in input().split()]
  ans = AC_csum[r-1] - AC_csum[l-1] - is_AC[r-1] + is_AC[l-1]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

N, Q = [int(i) for i in input().split()]
S = input()
is_AC = [S[i:i+2] == "AC" for i in range(N)]

for i in range(Q):
  l, r = [int(i) for i in input().split()]
  print(sum(is_AC[(l-1):r]) - is_AC[r-1])


Fixed submission:
# coding: utf-8
import sys
import numpy as np
input = sys.stdin.readline

N, Q = [int(i) for i in input().split()]
S = input()
is_AC = [False] * N
AC_csum = [0] * N
for i in range(N):
  is_AC[i] = S[i:i+2] == "AC"
  AC_csum[i] = AC_csum[i-1] + is_AC[i]

for i in range(Q):
  l, r = [int(i) for i in input().split()]
  ans = AC_csum[r-1] - AC_csum[l-1] - is_AC[r-1] + is_AC[l-1]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

N, Q = [int(i) for i in input().split()]
S = input()
is_AC = [False] * N

for i in range(N):
  if S[i:i+2] == "AC":
    is_AC[i] = True

for i in range(Q):
  l, r = [int(i) for i in input().split()]
  print(sum(is_AC[(l-1):r]) - is_AC[r-1])


Fixed submission:
# coding: utf-8
import sys
import numpy as np
input = sys.stdin.readline

N, Q = [int(i) for i in input().split()]
S = input()
is_AC = [False] * N
AC_csum = [0] * N
for i in range(N):
  is_AC[i] = S[i:i+2] == "AC"
  AC_csum[i] = AC_csum[i-1] + is_AC[i]

for i in range(Q):
  l, r = [int(i) for i in input().split()]
  ans = AC_csum[r-1] - AC_csum[l-1] - is_AC[r-1] + is_AC[l-1]
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

input()

B_ = [int(i) for i in input().split()]

def f (B, ans):
  if len(B) == 0:
    return ans
  for i in range(len(B)):
    if B[i] <= len(B) and B[i] == i+1 :
      B2 = B[:]
      ans2 = ans[:]
      ans2.append(B2.pop(B[i]-1))
      result = f(B2, ans2)
      if result is not None: 
        return result

result = f(B_, [])
if result is None:
  result = [-1]
for s in result[::-1]:
  print(s)

Fixed submission:
# coding: utf-8

N = int(input())

B = [int(i) for i in input().split()]

ans = []

while (len(B) > 0):
  for _ in range(len(B)):
    for i in list(range(len(B)))[::-1]:
      if B[i] == i+1:
        ans.append(i+1)
        B.pop(i)
        break
  break

if len(ans) != N:
  print(-1)
else:
  for i in ans[::-1]:
    print(i)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
from sys import stdin.readline as input
 
N, M = [int(i) for i in input().split()]
 
plices = [[int(i) for i in input().split()] for _ in range(N)]
 
plices.sort(key = lambda x:x[0])
 
m = 0
cost = 0
 
for i in range(N):
    if m >= M:
        break
    buy = min(M - m, plices[i][1])
    cost += plices[i][0] * buy
    m += buy
 
print(cost)

Fixed submission:
# coding: utf-8
import sys
input = sys.stdin.readline

N, M = [int(i) for i in input().split()]

plices = [[int(i) for i in input().split()] for _ in range(N)]

plices.sort(key = lambda x:x[0])

m = 0
cost = 0

for i in range(N):
    if m >= M:
        break
    buy = min(M - m, plices[i][1])
    cost += plices[i][0] * buy
    m += buy

print(cost)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8

A, B = [int(i) for i in input().split()]

def count_1(bi, idx):
    bi = bi[::-1]
    cnt = 0
    if idx > 0:
        for i in range(0, idx):
            cnt += int(bi[idx]) * int(bi[i]) * int(2**i)
    if idx < (len(bi) - 1):
        for i in range(idx + 1, len(bi)):
            cnt += int(bi[i]) * int(2**i) / 2
    cnt += int(bi[idx])        
    return(int(cnt))

a = str(bin(A-1))[2:]
b = str(bin(B))[2:]
a = (len(b) - len(a)) * "0" + a # 長さ調整

def count_1s(bi):
    return([count_1(bi, i) for i in range(len(bi))[::-1]])

a_cnt = count_1s(a)
b_cnt = count_1s(b)

print(int("".join([str((i - j) % 2) for i, j in zip(b_cnt, a_cnt)]), 2))


Fixed submission:
# coding: utf-8

A, B = [int(i) for i in input().split()]

def count_1(bi, idx):
    bi = bi[::-1]
    cnt = 0
    if idx > 0:
        for i in range(0, idx):
            cnt += int(bi[idx]) * int(bi[i]) * int(2**i)
    if idx < (len(bi) - 1):
        for i in range(idx + 1, len(bi)):
            cnt += int(bi[i]) * int(2**i) / 2
    cnt += int(bi[idx])        
    return(int(cnt))

a = str(bin(max(A-1, 0)))[2:]
b = str(bin(B))[2:]
a = (len(b) - len(a)) * "0" + a # 長さ調整

def count_1s(bi):
    return([count_1(bi, i) for i in range(len(bi))[::-1]])

a_cnt = count_1s(a)
b_cnt = count_1s(b)


print(int("".join([str((i - j) % 2) for i, j in zip(b_cnt, a_cnt)]), 2))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8

I, O, T, J, L, S, Z = [int(i) for i in input().split()]

K = (I//2)*2 + O + (J//2)*2 + (L//2)*2
if I % 2 == 1 and J % 2 == 1 and L % 2 ==1:
    K += 3
elif (I % 2 + J % 2 + L % 2 == 2) and (I * J * L > 0):
    K += 1
print(K)

Fixed submission:
# coding: utf-8
# Here your code !

x, y = [int(i) for i in input().split()]

alist = []

if (y > x) and (y - x) >= 0:
    alist.append(y - x)

if y < x:
    alist.append(abs(abs(x)-abs(y))+2)
    
if (abs(x) < abs(y) and x >= 0 and y <= 0):
    alist.append(abs(y)-abs(x)+1)

if (abs(x) > abs(y) and x <= 0 and y >= 0):
    alist.append(abs(x)-abs(y)+1)

if (abs(x) < abs(y) and x <= 0 and y >= 0):
    alist.append(abs(y) - abs(x) + 1)

if (abs(x) > abs(y) and x >= 0 and y <= 0):
    alist.append(abs(x) - abs(y) + 1)

if (abs(x) == abs(y)):
    alist.append(1)
    
print(min(alist))
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())
for i in range(k):
    if a > 0:
        a -= 1
        continue
    if b > 0:
        b -= 1
        continue
print('%d %d'%(a, b))

Fixed submission:
a, b, k = map(int, input().split())
num = min(a, k)
a -= num
b = max(0, b - (k - num))
print(a, b)
Buggy python submission (verdict: Runtime Error):
a, b = map(int,input())
print(6-a-b)

Fixed submission:
number1 = int(input())
number2 = int(input())
choices = [1,2,3]
choices.remove(number1)
choices.remove(number2)
print(*choices)

Buggy python submission (verdict: Runtime Error):
a, b = input(), input()
print(6-a-b)

Fixed submission:
number1 = int(input())
number2 = int(input())
choices = [1,2,3]
choices.remove(number1)
choices.remove(number2)
print(*choices)

Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
print(6-a-b)

Fixed submission:
number1 = int(input())
number2 = int(input())
choices = [1,2,3]
choices.remove(number1)
choices.remove(number2)
print(*choices)
Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int,stdin.readline().split())
gcd = math.gcd(a,b)
print((a*b)//math.gcd(a,b))

Fixed submission:
a, b = map(int,input().split())
for i in range(1,b+1):
  if (a*i) % b == 0:
    print(a*i)
    break

Buggy python submission (verdict: Runtime Error):
from sys import stdin
import math
a, b = map(int,stdin.readline().split())
gcd = math.gcd(a,b)
print((a*b)//math.gcd(a,b))

Fixed submission:
a, b = map(int,input().split())
for i in range(1,b+1):
  if (a*i) % b == 0:
    print(a*i)
    break

Buggy python submission (verdict: Runtime Error):
from sys import stdin
import math
a, b = map(int,stdin.readline().split())
gcd = math.gcd(a,b)
lcm = (a*b)/gcd
print(lcm)

Fixed submission:
a, b = map(int,input().split())
for i in range(1,b+1):
  if (a*i) % b == 0:
    print(a*i)
    break

Buggy python submission (verdict: Runtime Error):
from sys import stdin
import math
a, b = map(int,stdin.readline().split())
gcd = math.gcd(a,b)
lcm = (a*b)//gcd
print(lcm)

Fixed submission:
a, b = map(int,input().split())
for i in range(1,b+1):
  if (a*i) % b == 0:
    print(a*i)
    break

Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int,input().split())
gcd = math.gcd(a,b)
lcm = (a*b)//gcd
print(lcm)

Fixed submission:
a, b = map(int,input().split())
for i in range(1,b+1):
  if (a*i) % b == 0:
    print(a*i)
    break

Buggy python submission (verdict: Runtime Error):
from sys import stdin
import math
a, b = map(int,stdin.readline().split())
gcd = math.gcd(a,b)
lcm = (a*b)//gcd
print(lcm)

Fixed submission:
a, b = map(int,input().split())
for i in range(1,b+1):
  if (a*i) % b == 0:
    print(a*i)
    break

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
a, b = map(int,stdin.readline().split())
greater = max(a,b)
while(True):
    if (greater % a == 0) and (greater % b == 0):
        lcm = greater
        break
    greater += 1
print(lcm)

Fixed submission:
a, b = map(int,input().split())
for i in range(1,b+1):
  if (a*i) % b == 0:
    print(a*i)
    break
Buggy python submission (verdict: Runtime Error):
nums = [input() for i in range(6)]

if nums[4] - nums[0] > nums[5]:
  print(':(')
print('Yay!')


Fixed submission:
nums = [int(input()) for i in range(6)]

if nums[4] - nums[0] > nums[5]:
  print(':(')
else:
  print('Yay!')

Buggy python submission (verdict: Runtime Error):
nums = [input() for i in range(6)]

if nums[4] - nums[0] > nums[5]:
  print ':('
print 'Yay!'

Fixed submission:
nums = [int(input()) for i in range(6)]

if nums[4] - nums[0] > nums[5]:
  print(':(')
else:
  print('Yay!')

Buggy python submission (verdict: Runtime Error):
nums = [input() for i in range(6)]

if nums[4] - nums[0] > nums[5]:
  return ':('
return 'Yay!'

Fixed submission:
nums = [int(input()) for i in range(6)]

if nums[4] - nums[0] > nums[5]:
  print(':(')
else:
  print('Yay!')
Buggy python submission (verdict: Runtime Error):
x,y = map(int,input().split())	
c=input()
c.split()
print(y)
count=0
for i in c:
    if(float(y) <= float(i)):
        count+=1
print(count)

Fixed submission:
x,y = map(float,input().split())	
li = list(map(float,input().split()))	
count=0
for i in li:
    if(y <= i):
        count+=1
print(count)
Buggy python submission (verdict: Runtime Error):
a=int(input())

b=list(map(int, input().split()))
b.sort(reverse=True)
alice=0
bob=0
c=iter(b)
for i in c:
    alice+=i
    bob+=next(c)
print(alice-bob)

Fixed submission:
a=int(input())

b=list(map(int, input().split()))
b.sort(reverse=True)
alice=0
bob=0
c=iter(b)
for i in c:
    alice+=i
    try:
    	bob+=next(c)
    except:
      break
print(alice-bob)

Buggy python submission (verdict: Runtime Error):
a=int(input())

b=list(map(int, input().split()))
b.sort()
alice=0
bob=0

c=iter(b)
for i in c:
    alice=i
    bob=next(c)
print(alice-bob if alice>bob else bob-alice)

Fixed submission:
a=int(input())

b=list(map(int, input().split()))
b.sort(reverse=True)
alice=0
bob=0
c=iter(b)
for i in c:
    alice+=i
    try:
    	bob+=next(c)
    except:
      break
print(alice-bob)

Buggy python submission (verdict: Runtime Error):
a=int(input())

b=list(map(int, input().split()))
b.sort()
alice=0
bob=0

c=iter(b)
for i in c:
    alice=i
    bob=next(c)
print(alice-bob if alice>bob else bob-alice)

Fixed submission:
a=int(input())

b=list(map(int, input().split()))
b.sort(reverse=True)
alice=0
bob=0
c=iter(b)
for i in c:
    alice+=i
    try:
    	bob+=next(c)
    except:
      break
print(alice-bob)
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())

predict_price1 = math.floor((N)  / 1.08)  # 整数で計算,切り捨て処理
predict_price2 = math.ceil(N+1)  / 1.08)  # 整数で計算,切り上げ処理

if predict_price1 == predict_price2:
    print(predict_price1)
else:
    print(":(")   

Fixed submission:
import math

N = int(input())

if math.floor(math.floor((N) / 1.08) * 1.08) == N:
    print(math.floor((N) / 1.08))
elif math.floor(math.floor((N+1) / 1.08) * 1.08) == N:
    print(math.floor((N+1) / 1.08))
else:
    print(":(")
Buggy python submission (verdict: Runtime Error):
A, B, X = map(int,input().split())

min_num = 0
max_num = 10 ** 9
#２分探索
# まず、最大値の10**9が購入できるか判定
if A * max_num + B * 9 <= X:
    print(max_num)
    exit()

while(1):
    ave_num = (min_num + max_num)//2 # get a center number
    price = A * ave_num + B * len(str(ave_num)) # price = f(ave_num)
    #print(ave_num,"_",min_num, "_", max_num)
    if min_num + 1 == max_num:
        print(min_num)
        break
    elif min_num == max_num:
        print(min_num)
        break

    elif X >= price:         # bottom down 
        min_num = ave_num
    else:                   # top up
        max_num = ave_num



Fixed submission:
S = input()

if S == "SUN":
    print("7")
elif S == "MON":
    print("6")
elif S == "TUE":
    print("5")
elif S == "WED":
    print("4")
elif S == "THU":
    print("3")
elif S == "FRI":
    print("2")
elif S == "SAT":
    print("1")
Buggy python submission (verdict: Runtime Error):

N = int(input())
S = list(input())

# ordで文字からunicode数字を返す
# chrでunicode数字から文字を返す

def chr_change(chr, N):
    """ print("chr is", chr)
    print("N is", N)
    print("ord(chr) is ", ord(chr))
     """
    Num_AtoZ = ord("Z") - ord("A")
    if ord(chr) + N > ord("Z"):
        chg_chr = ord(chr) + N - Num_AtoZ -1
    else:
        chg_chr = ord(chr) + N
    #print("chg_chr is", chg_chr)
    return chg_chr


for i in range(N):
    tmp_chr = S[i]
    print(chr(chr_change(tmp_chr, N)), end = "")
print("\n")


Fixed submission:

N = int(input())
S = list(input())

# ordで文字からunicode数字を返す
# chrでunicode数字から文字を返す

def chr_change(chr, N):
    """ print("chr is", chr)
    print("N is", N)
    print("ord(chr) is ", ord(chr))
     """
    Num_AtoZ = ord("Z") - ord("A")
    if ord(chr) + N > ord("Z"):
        chg_chr = ord(chr) + N - Num_AtoZ -1
    else:
        chg_chr = ord(chr) + N
    #print("chg_chr is", chg_chr)
    return chg_chr


for i in range(len(S)):
    tmp_chr = S[i]
    print(chr(chr_change(tmp_chr, N)), end = "")
print("\n")
Buggy python submission (verdict: Time Limit Exceeded):
import math

X, Y = map(int, input().split())

#initial: (X,Y) = (0,0)

num = 10**9 + 7
sum = 0
#print(num)
for i in range(X+1):# i は1step回数。２stepを行う回数は(X-i)//2(余りあったらbreak)
    if (X-i)% 2 == 0:
        j = (X-i)//2
        #print("i and j is ", i, j)
        if i * 2 + j  == Y:
            #conbination_num1 = (math.factorial(i + j) / math.factorial(i)) % num
            sum += math.factorial(i + j) / (math.factorial(i) * math.factorial(j)) % num  

print(int(sum))




Fixed submission:
import math

def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    nf = rf = 1
    for i in range(r):
        nf = nf * (n-i) % mod
        rf = rf * (i+1) % mod
    return nf * pow(rf, mod-2, mod) % mod

if __name__ == "__main__":
    X, Y = map(int, input().split())

    #initial: (X,Y) = (0,0)

    num = 10**9 + 7
    sum = 0
    #print(num)
    for i in range(X+1):# i は1step回数。２stepを行う回数は(X-i)//2(余りあったらbreak)
        if (X-i)% 2 == 0:
            j = (X-i)//2
            #print("i and j is ", i, j)
            if i * 2 + j  == Y:
                #conbination_num1 = (math.factorial(i + j) / math.factorial(i)) % num
                sum += combination(i+j, i, num)  

    print(int(sum))
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = list(map(int, input().split()))
score_list = [k] * n
a = list(map(int, [input() for i in range(q)]))

for i in range(q):
  score_list = list(map(lambda x: x-1, score_list))
  score_list[a[i]-1] += 1
#  print(score_list)

 # print(a[i])

#for i in range(n):
#  print(score_list[i])

    
for i in range(n):
  if score_list[i] > 0:
    print("Yes")
  else:
    print("No")

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

#print(a)

score = [k - q ] * n
#print(score)
for i in range(q):
  score[ a[i]-1 ] += 1
  #print(score)
  
for i in range(n):
  print("Yes" if score[i] > 0 else "No")

Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = list(map(int, input().split()))
score_list = [0] * n
a = list(map(int, [input() for i in range(q)]))
 
 
for answer_num in range(q):
  for person_num in range(n):
    if a[answer_num] is not (person_num + 1):
      score_list[person_num] += 1
    
for i in range(n):
  if score_list[i] >= k:
    print("No")
  else:
    print("Yes")
    
      

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

#print(a)

score = [k - q ] * n
#print(score)
for i in range(q):
  score[ a[i]-1 ] += 1
  #print(score)
  
for i in range(n):
  print("Yes" if score[i] > 0 else "No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = list(map(int,input().split()))

count = [0]*n

for i in range(n):
#  print("i is", i,"=======")
  for j in range(i, n-1):
 #   print("h[j] is", h[j])
 #   print("h[j+1] is", h[j+1])
    if h[j] >= h[j + 1]:
      count[i] += 1
  #    print("count is",count)
    else:
      break

max_cnt = sorted(count, reverse = True)
print(max_cnt[0])

  

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
t = 0
result = 0
for i in range(n - 1):
  if h[i + 1] <= h[i]:
    t += 1
  else:
    result = max(t, result)
    t = 0
result = max(t, result)
print(result)
Buggy python submission (verdict: Runtime Error):
x, a = int(input().split())

print(10 if x < a else 0)

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

print(0 if x < a else 10)
Buggy python submission (verdict: Runtime Error):
from math import gcd

N = int(input())
A = list(map(int, input().split()))

L = [0]
R = [0]

for i in range(N):
    L.append(gcd(L[i], A[i]))  # 0, gcd(0,A[0]), gcd(0,A[0],A[1]) , ...
    R.append(gcd(R[i], A[N - i -1])) # 0 , gcd(0, A[N-1]), gcd(0, A[N-1], A[N-2]))..

R.reverse() # R is gcd(0,...A[0]), gcd(0,...A[1]),....
# pairs are 
#  L     :R
#  0    : (0,A[N-1],A[n-2], ... A[1])
#  A[0] : (0,A[N-1],A[n-2], ... A[2])
#  ...
#  A[0,1,..N-3] :(0,A[N-1]
#  A[0,1,..N-2] :(0)
print(max( (gcd(L[i], R[i+1]) for i in range(N))))



Fixed submission:
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))

L = [0]
R = [0]

for i in range(N):
    L.append(gcd(L[i], A[i]))  # 0, gcd(0,A[0]), gcd(0,A[0],A[1]) , ...
    R.append(gcd(R[i], A[N - i -1])) # 0 , gcd(0, A[N-1]), gcd(0, A[N-1], A[N-2]))..

R.reverse() # R is gcd(0,A[N-1]...A[0]), gcd(0,A[N-1]...A[1]),....
# pairs are 
#  L     :R
#  0    : (0,A[N-1],A[n-2], ... A[1])
#  A[0] : (0,A[N-1],A[n-2], ... A[2])
#  ...
#  A[0,1,..N-3] :(0,A[N-1]
#  A[0,1,..N-2] :(0)
print(max( (gcd(L[i], R[i+1]) for i in range(N))))

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
from functools import reduce
N = int(input())
a = list(map(int, input().split()))

list_ans = []

for i in range(N):
    remove_a = a.pop(0)
    #print("a is",a)
    ans = reduce(gcd, a)
    list_ans.append(ans)
    a.append(remove_a)
    #print("fix a is",a)

print(max(list_ans))

Fixed submission:
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))

L = [0]
R = [0]

for i in range(N):
    L.append(gcd(L[i], A[i]))  # 0, gcd(0,A[0]), gcd(0,A[0],A[1]) , ...
    R.append(gcd(R[i], A[N - i -1])) # 0 , gcd(0, A[N-1]), gcd(0, A[N-1], A[N-2]))..

R.reverse() # R is gcd(0,A[N-1]...A[0]), gcd(0,A[N-1]...A[1]),....
# pairs are 
#  L     :R
#  0    : (0,A[N-1],A[n-2], ... A[1])
#  A[0] : (0,A[N-1],A[n-2], ... A[2])
#  ...
#  A[0,1,..N-3] :(0,A[N-1]
#  A[0,1,..N-2] :(0)
print(max( (gcd(L[i], R[i+1]) for i in range(N))))

Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce
N = int(input())
a = list(map(int, input().split()))

list_ans = []

for i in range(N):
    remove_a = a.pop(0)
    #print("a is",a)
    ans = reduce(gcd, a)
    list_ans.append(ans)
    a.append(remove_a)
    #print("fix a is",a)

print(max(list_ans))

Fixed submission:
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))

L = [0]
R = [0]

for i in range(N):
    L.append(gcd(L[i], A[i]))  # 0, gcd(0,A[0]), gcd(0,A[0],A[1]) , ...
    R.append(gcd(R[i], A[N - i -1])) # 0 , gcd(0, A[N-1]), gcd(0, A[N-1], A[N-2]))..

R.reverse() # R is gcd(0,A[N-1]...A[0]), gcd(0,A[N-1]...A[1]),....
# pairs are 
#  L     :R
#  0    : (0,A[N-1],A[n-2], ... A[1])
#  A[0] : (0,A[N-1],A[n-2], ... A[2])
#  ...
#  A[0,1,..N-3] :(0,A[N-1]
#  A[0,1,..N-2] :(0)
print(max( (gcd(L[i], R[i+1]) for i in range(N))))
Buggy python submission (verdict: Runtime Error):
a,b,k = map(int, input().split())

min_val  = min(a,b)
list = []
for i in range(min_val,0,-1):
  if a%(i+1) == 0 and b%(i+1) == 0:
    list.append(i+1)
    
print(list[k-1])

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

min_val  = min(a,b)
t = 0
for i in range(min_val,0,-1):
  if a%(i) == 0 and b%(i) == 0:
    t += 1
  if t == k:
    print(i)
    break