Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
import sys
from fractions import gcd
from functools import lru_cache
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()

@lru_cache(None)
def solve(index, n, g):
    '''既に１つ数を選んだらnは１'''
    if index == N:
        return g
    if n == 1:
        return solve(index+1, 1, gcd(g, A[index]))
    else:
        ret = max(solve(index+1, 1, g), solve(index+1, 0, gcd(g, A[index])))
        return ret

result1 = solve(0, 0,  A[0])
result2 = solve(0, 0, A[-1])
answer = max(result1, result2)
print(answer)


Fixed submission:
from fractions import gcd
import math
N = int(input())
A = list(map(int, input().split()))

gl = [0] * (N-1)
gr = [0] * (N-1)

gl[0] = A[0]
gr[0] = A[-1]
for i in range(1,N-1):
    gl[i] = gcd(gl[i-1],A[i])
    gr[i] = gcd(gr[i-1],A[-i-1])
#print(gl[i])
ans = max(gr[-1],gl[N-2])
for i in range(1,N-1):
    g = gcd(gl[i-1],gr[-i-1])
    ans = max(ans,g)
#print(gl,gr)
print(ans)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys
from fractions import gcd
from functools import lru_cache

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()

@lru_cache(None)
def solve(index, n, g):
    '''既に１つ数を選んだらnは１'''
    if index == N:
        return g
    if n == 1:
        return solve(index+1, 1, gcd(g, A[index]))
    else:
        ret = max(solve(index+1, 1, g), solve(index+1, 0, gcd(g, A[index])))
        return ret

result1 = solve(0, 0,  A[0])
result2 = solve(0, 0, A[-1])
answer = max(result1, result2)
print(answer)


Fixed submission:
from fractions import gcd
import math
N = int(input())
A = list(map(int, input().split()))

gl = [0] * (N-1)
gr = [0] * (N-1)

gl[0] = A[0]
gr[0] = A[-1]
for i in range(1,N-1):
    gl[i] = gcd(gl[i-1],A[i])
    gr[i] = gcd(gr[i-1],A[-i-1])
#print(gl[i])
ans = max(gr[-1],gl[N-2])
for i in range(1,N-1):
    g = gcd(gl[i-1],gr[-i-1])
    ans = max(ans,g)
#print(gl,gr)
print(ans)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import sys
from math import gcd
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def prime_factorize(n): # Nの素因数分解
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

# 約数が１つしかないものを探す
N = ir()
A = lr()
g = A[0]
dic = defaultdict(int)
for a in A:
    g = gcd(g, a)
    primes = prime_factorize(a)
    for p in primes:
        dic[p] += 1

cand = [1]
for k, v in dic.items():
    if v == 1:
        cand.append(k)

x = max(cand)
g = A[0] if A[0] % x != 0 else A[-1]
for a in A:
    if a%x == 0:
        continue
    g = gcd(g, a)

answer = g
print(answer)


Fixed submission:
from fractions import gcd
import math
N = int(input())
A = list(map(int, input().split()))

gl = [0] * (N-1)
gr = [0] * (N-1)

gl[0] = A[0]
gr[0] = A[-1]
for i in range(1,N-1):
    gl[i] = gcd(gl[i-1],A[i])
    gr[i] = gcd(gr[i-1],A[-i-1])
#print(gl[i])
ans = max(gr[-1],gl[N-2])
for i in range(1,N-1):
    g = gcd(gl[i-1],gr[-i-1])
    ans = max(ans,g)
#print(gl,gr)
print(ans)

Buggy python submission (verdict: Runtime Error):
from functools import reduce
from fractions import *

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

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

ans = 1
for i in range(len(A)):
    l = A.copy()
    l.pop(i)
    ans = max(ans,gcd_list(l))

print(ans)


Fixed submission:
from fractions import gcd
import math
N = int(input())
A = list(map(int, input().split()))

gl = [0] * (N-1)
gr = [0] * (N-1)

gl[0] = A[0]
gr[0] = A[-1]
for i in range(1,N-1):
    gl[i] = gcd(gl[i-1],A[i])
    gr[i] = gcd(gr[i-1],A[-i-1])
#print(gl[i])
ans = max(gr[-1],gl[N-2])
for i in range(1,N-1):
    g = gcd(gl[i-1],gr[-i-1])
    ans = max(ans,g)
#print(gl,gr)
print(ans)

Buggy python submission (verdict: Runtime Error):
from functools import reduce
from fractions import *

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

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

ans = 1
for i in range(len(A)):
    l = A.copy()
    l.pop(i)
    ans = max(ans,gcd_list(l))

print(ans)


Fixed submission:
from fractions import gcd
import math
N = int(input())
A = list(map(int, input().split()))

gl = [0] * (N-1)
gr = [0] * (N-1)

gl[0] = A[0]
gr[0] = A[-1]
for i in range(1,N-1):
    gl[i] = gcd(gl[i-1],A[i])
    gr[i] = gcd(gr[i-1],A[-i-1])
#print(gl[i])
ans = max(gr[-1],gl[N-2])
for i in range(1,N-1):
    g = gcd(gl[i-1],gr[-i-1])
    ans = max(ans,g)
#print(gl,gr)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from fractions import *

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

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

ans = 1
for i in range(len(A)):
    l = A.copy()
    l.pop(i)
    ans = max(ans,gcd_list(l))

print(ans)

Fixed submission:
from fractions import gcd
import math
N = int(input())
A = list(map(int, input().split()))

gl = [0] * (N-1)
gr = [0] * (N-1)

gl[0] = A[0]
gr[0] = A[-1]
for i in range(1,N-1):
    gl[i] = gcd(gl[i-1],A[i])
    gr[i] = gcd(gr[i-1],A[-i-1])
#print(gl[i])
ans = max(gr[-1],gl[N-2])
for i in range(1,N-1):
    g = gcd(gl[i-1],gr[-i-1])
    ans = max(ans,g)
#print(gl,gr)
print(ans)

Buggy python submission (verdict: Runtime Error):
from functools import reduce
from fraction import *

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

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

ans = 1
for i in range(len(A)):
    l = A.copy()
    l.pop(i)
    ans = max(ans,gcd_list(*l))

print(ans)



Fixed submission:
from fractions import gcd
import math
N = int(input())
A = list(map(int, input().split()))

gl = [0] * (N-1)
gr = [0] * (N-1)

gl[0] = A[0]
gr[0] = A[-1]
for i in range(1,N-1):
    gl[i] = gcd(gl[i-1],A[i])
    gr[i] = gcd(gr[i-1],A[-i-1])
#print(gl[i])
ans = max(gr[-1],gl[N-2])
for i in range(1,N-1):
    g = gcd(gl[i-1],gr[-i-1])
    ans = max(ans,g)
#print(gl,gr)
print(ans)

Buggy python submission (verdict: Runtime Error):
from functools import reduce
from fractions import gcd

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

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

ans = 1
for i in range(len(A)):
    l = A.copy()
    l.pop(i)
    ans = max(ans,gcd(*l))

print(ans)



Fixed submission:
from fractions import gcd
import math
N = int(input())
A = list(map(int, input().split()))

gl = [0] * (N-1)
gr = [0] * (N-1)

gl[0] = A[0]
gr[0] = A[-1]
for i in range(1,N-1):
    gl[i] = gcd(gl[i-1],A[i])
    gr[i] = gcd(gr[i-1],A[-i-1])
#print(gl[i])
ans = max(gr[-1],gl[N-2])
for i in range(1,N-1):
    g = gcd(gl[i-1],gr[-i-1])
    ans = max(ans,g)
#print(gl,gr)
print(ans)