Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
def gcm(a, b):
  if a < b:
    a = a+b
    b=a-b
    a = a-b
  if b == 0:
    return a
  else:
    r = a%b
    return b if r == 0 else gcm(b, r)
ans = 0
for i in range(N):
  g = 0
  for j in range(i):
    g = gcm(g, A[j])
  for j in range(i+1,N):
    g = gcm(g, A[j])
  ans = max(g, ans)
print(ans)



Fixed submission:
from collections import deque
def gcm(a, b):
  if a < b:
    a = a+b
    b=a-b
    a = a-b
  if b == 0:
    return a
  else:
    r = a%b
    return b if r == 0 else gcm(b, r)
N = int(input())
A = list(map(int, input().split()))
L = deque([0])
for i in range(1, N):
  L.append(gcm(L[-1],A[i-1]))
R = deque([0])
for i in reversed(range(N-1)):
  R.appendleft(gcm(R[0],A[i+1]))
ans = 0
for i in range(N):
  ans = max(ans, gcm(L[i],R[i]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2000)

memo_gcm = {}
def uclid_gcm(a, b):
  if a < b:
    a += b
    b = a-b
    a=a-b
  if b == 0:
    return a
  elif (a, b) in memo_gcm.keys():
    return memo_gcm[(a, b)]
  else:
    r = a%b
    memo_gcm[(a, b)] = b if r == 0 else uclid_gcm(b, r)
    return memo_gcm[(a, b)]

def gcm_all(array):
  l = len(array)
  if l == 1:
    return array[0]
  else:
    tmp = []
    for i in range(l//2):
      tmp.append(uclid_gcm(array[i*2], array[i*2+1]))
    if l %2 == 1:
      tmp.append(uclid_gcm(array[-2],array[-1]))
    return gcm_all(tmp)

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

ans = 0
for i in range(N):
  t  = A[i]
  A[i] = 0
  ans = max(ans, gcm_all(A))
  A[i] = t
print(ans)



Fixed submission:
from collections import deque
def gcm(a, b):
  if a < b:
    a = a+b
    b=a-b
    a = a-b
  if b == 0:
    return a
  else:
    r = a%b
    return b if r == 0 else gcm(b, r)
N = int(input())
A = list(map(int, input().split()))
L = deque([0])
for i in range(1, N):
  L.append(gcm(L[-1],A[i-1]))
R = deque([0])
for i in reversed(range(N-1)):
  R.appendleft(gcm(R[0],A[i+1]))
ans = 0
for i in range(N):
  ans = max(ans, gcm(L[i],R[i]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2000)

def uclid_gcm(a, b):
  if a < b:
    a += b
    b = a-b
    a=a-b
  if b == 0:
    return a
  r = a%b
  return b if r == 0 else uclid_gcm(b, r)

def gcm_all(array):
  l = len(array)
  if l == 1:
    return array[0]
  else:
    tmp = []
    for i in range(l//2):
      tmp.append(uclid_gcm(array[i*2], array[i*2+1]))
    if l %2 == 1:
      tmp.append(uclid_gcm(array[-2],array[-1]))
    return gcm_all(tmp)

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

ans = 0
for i in range(N):
  t  = A[i]
  A[i] = 0
  ans = max(ans, gcm_all(A))
  A[i] = t
print(ans)



Fixed submission:
from collections import deque
def gcm(a, b):
  if a < b:
    a = a+b
    b=a-b
    a = a-b
  if b == 0:
    return a
  else:
    r = a%b
    return b if r == 0 else gcm(b, r)
N = int(input())
A = list(map(int, input().split()))
L = deque([0])
for i in range(1, N):
  L.append(gcm(L[-1],A[i-1]))
R = deque([0])
for i in reversed(range(N-1)):
  R.appendleft(gcm(R[0],A[i+1]))
ans = 0
for i in range(N):
  ans = max(ans, gcm(L[i],R[i]))
print(ans)