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

N = int(input())
A = [int(a) for a in input().split(" ")]
if N==2:
    print(gcd(*A))
else:
    left = reduce(lambda acc, x: acc+[gcd(x, acc[-1])], A, A[:1])
    right = reduce(lambda acc, x: acc+[gcd(x, acc[-1])], A[::-1], A[-1:])[::-1]

    ans = max([gcd(left[i-1], right[i+1]) for i in range(1,N-1)])
    ans = max([right[1], ans, left[-2]])
    print(ans)


Fixed submission:
from functools import reduce
from fractions import gcd

N = int(input())
A = [int(a) for a in input().split(" ")]
if N==2:
    print(max(A))
else:
    left, right = [-1]*(N-1), [-1]*(N-1)
    lacc, racc = (A[0], A[-1])
    for i in range(N-1):
        lacc, racc = gcd(lacc, A[i]), gcd(racc, A[N-1-i])
        left[i], right[i] = lacc, racc
    ans = max(right[-1], left[-1])
    for l, r in zip(left[:-1], reversed(right[:-1])):
        ans = max(ans, gcd(l,r))
    print(ans)

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

N = int(input())
A = [int(a) for a in input().split(" ")]
if N==2:
    print(gcd(*A))
    exit()

left = reduce(lambda acc, x: acc+[gcd(x, acc[-1])], A, A[:1])
right = reduce(lambda acc, x: acc+[gcd(x, acc[-1])], A[::-1], A[-1:])[::-1]

ans = max([gcd(left[i-1], right[i+1]) for i in range(1,N-1)])
ans = max([right[1], ans, left[-2]])
print(ans)


Fixed submission:
from functools import reduce
from fractions import gcd

N = int(input())
A = [int(a) for a in input().split(" ")]
if N==2:
    print(max(A))
else:
    left, right = [-1]*(N-1), [-1]*(N-1)
    lacc, racc = (A[0], A[-1])
    for i in range(N-1):
        lacc, racc = gcd(lacc, A[i]), gcd(racc, A[N-1-i])
        left[i], right[i] = lacc, racc
    ans = max(right[-1], left[-1])
    for l, r in zip(left[:-1], reversed(right[:-1])):
        ans = max(ans, gcd(l,r))
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# a>b
dic = {}

def gcd(a, b):
    key = (a, b)
    if key in dic:
        return dic[key]
    ans = 0
    if b == 0:
        ans = a
    else:
        ans = gcd(b, a%b)
    dic[key] = ans
    return ans

def gcd_arr(arr):
    if len(arr)==1:
        return arr[0]
    i = len(arr)//2
    l, r = (gcd_arr(arr[:i]), gcd_arr(arr[i:]))
    return gcd(l, r) if l>r else gcd(r, l)

N = int(input())
As = [int(s) for s in input().split()]
ans = 1

for i in range(N):
    curr = None
    arr = [As[j] for j in range(N) if i!=j]
    ans = max(ans, gcd_arr(arr))

print(ans)

Fixed submission:
from functools import reduce
from fractions import gcd

N = int(input())
A = [int(a) for a in input().split(" ")]
if N==2:
    print(max(A))
else:
    left, right = [-1]*(N-1), [-1]*(N-1)
    lacc, racc = (A[0], A[-1])
    for i in range(N-1):
        lacc, racc = gcd(lacc, A[i]), gcd(racc, A[N-1-i])
        left[i], right[i] = lacc, racc
    ans = max(right[-1], left[-1])
    for l, r in zip(left[:-1], reversed(right[:-1])):
        ans = max(ans, gcd(l,r))
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# a>b
dic = {}

def gcd(a, b):
    key = (a, b)
    if key in dic:
        return dic[key]
    ans = 0
    if b == 0:
        ans = a
    else:
        ans = gcd(b, a%b)
    dic[key] = ans
    return ans

N = int(input())
As = [int(s) for s in input().split()]
ans = 0

for i in range(N):
    curr = None
    for j in range(N):
        if i==j:
            continue
        curr = As[j] if curr is None else gcd(max(curr, As[j]), min(curr, As[j]))
    ans = max(curr, ans)
    
print(ans)

Fixed submission:
from functools import reduce
from fractions import gcd

N = int(input())
A = [int(a) for a in input().split(" ")]
if N==2:
    print(max(A))
else:
    left, right = [-1]*(N-1), [-1]*(N-1)
    lacc, racc = (A[0], A[-1])
    for i in range(N-1):
        lacc, racc = gcd(lacc, A[i]), gcd(racc, A[N-1-i])
        left[i], right[i] = lacc, racc
    ans = max(right[-1], left[-1])
    for l, r in zip(left[:-1], reversed(right[:-1])):
        ans = max(ans, gcd(l,r))
    print(ans)