Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

d = {}
m = []

if len(A) == 2:
    print(max(A))
    exit()

for i in range(N):
    _A = []
    _A.extend(A[0:i])
    _A.extend(A[i+1:N])

    for j in range(1, len(_A)):
        if j == 1:
            tmp = gcd(_A[j], _A[j-1])
        else:
            tmp = gcd(_A[j], tmp)
    m.append(tmp)
print(max(m))


Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

L = [0] * N
R = [0] * N

L[0] = A[0]
R[N-1] = A[-1]

for n in range(1, N):
    L[n] = gcd(L[n - 1], A[n])
for n in reversed(range(N-1)):
    R[n] = gcd(R[n + 1], A[n])

ans = 0
for n in range(N):
    if n == 0:
        ans = max(ans, R[n+1])
    elif n == N - 1:
        ans = max(ans, L[n-1])
    else:
        ans = max(ans, gcd(L[n-1], R[n+1]))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

d = {}
m = []

if len(A) == 2:
    print(max(A))
    exit()

for i in range(N):
    _A = []
    _A.extend(A[0:i])
    _A.extend(A[i+1:N])

    for j in range(1, len(_A)):
        if j == 1:
            tmp = gcd(_A[j], _A[j-1])
        else:
            tmp = gcd(_A[j], tmp)
    m.append(tmp)
print(max(m))


Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

L = [0] * N
R = [0] * N

L[0] = A[0]
R[N-1] = A[-1]

for n in range(1, N):
    L[n] = gcd(L[n - 1], A[n])
for n in reversed(range(N-1)):
    R[n] = gcd(R[n + 1], A[n])

ans = 0
for n in range(N):
    if n == 0:
        ans = max(ans, R[n+1])
    elif n == N - 1:
        ans = max(ans, L[n-1])
    else:
        ans = max(ans, gcd(L[n-1], R[n+1]))

print(ans)

Buggy python submission (verdict: Runtime Error):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors


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

d = {}
for a in A:
    for x in make_divisors(a):
        d[x] = d.get(x, 0) + 1

print(sorted([(k,v) for k,v in d.items() if v >= N-1], key=lambda x: -x[0])[0][0])


Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

L = [0] * N
R = [0] * N

L[0] = A[0]
R[N-1] = A[-1]

for n in range(1, N):
    L[n] = gcd(L[n - 1], A[n])
for n in reversed(range(N-1)):
    R[n] = gcd(R[n + 1], A[n])

ans = 0
for n in range(N):
    if n == 0:
        ans = max(ans, R[n+1])
    elif n == N - 1:
        ans = max(ans, L[n-1])
    else:
        ans = max(ans, gcd(L[n-1], R[n+1]))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors


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

d = {}
for a in A:
    for x in make_divisors(a):
        d[x] = d.get(x, 0) + 1

print(sorted([(k,v) for k,v in d.items() if v >= N-1], key=lambda x: -x[0])[0][0])


Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

L = [0] * N
R = [0] * N

L[0] = A[0]
R[N-1] = A[-1]

for n in range(1, N):
    L[n] = gcd(L[n - 1], A[n])
for n in reversed(range(N-1)):
    R[n] = gcd(R[n + 1], A[n])

ans = 0
for n in range(N):
    if n == 0:
        ans = max(ans, R[n+1])
    elif n == N - 1:
        ans = max(ans, L[n-1])
    else:
        ans = max(ans, gcd(L[n-1], R[n+1]))

print(ans)