Problem: There are N integers, A_1, A_2, ..., A_N, written on the blackboard.  You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.  Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Submission attempts (in order):
import fractions
import functools
N=int(input())
A=[int(i) for i in input().split()] 
max_gcd=functools.reduce(fractions.gcd, A)
for i in range(N):
	tmp=A.copy()
	tmp.pop(i)
	gcd=functools.reduce(fractions.gcd, tmp)
	if max_gcd<gcd:
		max_gcd=gcd
print(max_gcd)


import fractions
import functools

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

max_gcd = functools.reduce(fractions.gcd, A)

for i in range(N):
	tmp = A.copy()
	tmp.pop(i)
	gcd = functools.reduce(fractions.gcd, tmp)
	if max_gcd < gcd:
		max_gcd = gcd

print(max_gcd)


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

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

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

L[0] = A[0]
r[-1] = A[-1]

for i in range(1, N):
	L[i] = gcd(L[i], A[i])
	idx = N-1-i
	R[i] = gcd(R[idx], A[idx])


mx = 0
for i in range(N):
	if i==N-1:	
		v = L[N-2]
	elif i==0:	
		v = R[1]
	else:		
		v = gcd(L[i+1], R[i-1])
	mx = max(v, mx)
print(mx)


import fractions
import functools
N = int(input())
A = [int(i) for i in input().split()] 
num = 0
for i in range(N):
	
	sosu = True
	if A[i] % 2 == 0:
		sosu = False
		break
	for n in range(3, i, 2):
		if i % n == 0:
			sosu = False
			break
			
			
	if sosu:
		num += 1

if num >= 3:
	max_gcd = 1


else:
	max_gcd = functools.reduce(fractions.gcd, A)
	for i in range(N):
		tmp = A.copy()
		tmp.pop(i)
		gcd = functools.reduce(fractions.gcd, tmp)
		if max_gcd < gcd:
			max_gcd = gcd
print(max_gcd)


import fractions
import functools
N=int(input())
A=[int(i) for i in input().split()] 
#max_gcd=functools.reduce(fractions.gcd, A)
max_gcd = 1
for i in range(N):
	tmp=A.copy()
	tmp.pop(i)
	gcd=functools.reduce(fractions.gcd, tmp)
	if max_gcd<gcd:
		max_gcd=gcd
print(max_gcd)


import fractions
import functools

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

max_gcd = functools.reduce(fractions.gcd, A)

for i in range(N):
	if A[i] % 2 == 1:
		tmp = A.copy()
		tmp.pop(i)
		gcd = functools.reduce(fractions.gcd, tmp)
		if max_gcd < gcd:
			max_gcd = gcd

print(max_gcd)


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)








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

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

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

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


mx = 0
for i in range(N):
	if i == N-1:	
		v = L[N-2]
	elif i == 0:	
		v = R[1]
	else:		
		v = gcd(R[i+1], L[i-1])
	mx = max(v, mx)
print(mx)



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

L[0] = A[0]
R[-1] = A[-1]
for i in range(1, N):
    L[i] = gcd(L[i-1], A[i])
    idx = N-1-i
    R[idx] = gcd(R[idx+1], A[idx])

mx = 0
for i in range(N):
    if i == N-1:
        v = L[N-2]
    elif i == 0:
        v = R[1]
    else:
        v = gcd(R[i+1], L[i-1])
    mx = max(v, mx)
print(mx)


import fractions
import functools
N=int(input())
A=[int(i) for i in input().split()] 
#max_gcd=functools.reduce(fractions.gcd, A)
for i in range(N):
	tmp=A.copy()
	tmp.pop(i)
	gcd=functools.reduce(fractions.gcd, tmp)
	if max_gcd<gcd:
		max_gcd=gcd
print(max_gcd)


import fractions

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

l = [0]*N
r = [0]*N

l[0] = A[0]
r[-1] = A[-1]

for i in range(N):
	l[i] = fractions.gcd(l[i], A[i])
	idx = N-1-i
	r[i] = fractions.gcd(r[idx], A[idx])
mx = 0
for i in range(N):
	if i==N-1:#
		val = l[N-2]
	elif i==0:#
		val = r[1]
	else:#
		val = fractions.gcd(r[i+1], l[i-1])
	mx = max(val, mx)
print(mx)


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

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

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

L[0] = A[0]
r[-1] = A[-1]

for i in range(1, N):
	L[i] = gcd(L[i], A[i])
	idx = N-1-i
	R[i] = gcd(R[idx], A[idx])


mx = 0
for i in range(N):
	if i==N-1:	
		v = L[N-2]
	elif i==0:	
		v = R[1]
	else:		
		v = gcd(R[i+1], L[i-1])
	mx = max(v, mx)
print(mx)


import fractions
import functools
N = int(input())
A = [int(i) for i in input().split()] 
max_gcd = functools.reduce(fractions.gcd, A)
for i in range(1, N):
	tmp = A.copy()
	tmp.pop(i)
	gcd = functools.reduce(fractions.gcd, tmp)
	if max_gcd < gcd:
		max_gcd = gcd
print(max_gcd)


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

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

l = [0]*N
r = [0]*N

l[0] = A[0]
r[-1] = A[-1]

for i in range(N):
	l[i] = gcd(l[i], A[i])
	idx = N-1-i
	r[i] = gcd(r[idx], A[idx])


mx = 0
for i in range(N):
	if i==N-1:	
		val = l[N-2]
	elif i==0:	
		val = r[1]
	else:		
		val = gcd(r[i+1], l[i-1])
	mx = max(val, mx)
print(mx)


import fractions
import functools
N = int(input())
A = [int(i) for i in input().split()] 
max_gcd = functools.reduce(fractions.gcd, A)
for i in range(N):
	tmp = A.copy()
	if A[i]%2==1:
		tmp.pop(i)
		gcd = functools.reduce(fractions.gcd, tmp)
	else:
		gcd = functools.reduce(fractions.gcd, tmp)
	if max_gcd < gcd:
		max_gcd = gcd
print(max_gcd)


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

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

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

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

for i in range(1, N):
	L[i] = gcd(L[i-1], A[i])
	idx = N-1-i
	R[i] = gcd(R[idx], A[idx])


mx = 0
for i in range(N):
	if i==N-1:	
		v = L[N-2]
	elif i==0:	
		v = R[1]
	else:		
		v = gcd(R[i+1], L[i-1])
	mx = max(v, mx)
print(mx)


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

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

l = [0]*N
r = [0]*N

l[0] = A[0]
r[-1] = A[-1]

for i in range(1, N):
	l[i] = gcd(l[i], A[i])
	idx = N-1-i
	r[i] = gcd(r[idx], A[idx])


mx = 0
for i in range(N):
	if i==N-1:	
		val = l[N-2]
	elif i==0:	
		val = r[1]
	else:		
		val = gcd(r[i+1], l[i-1])
	mx = max(val, mx)
print(mx)


# -*- coding: utf-8 -*-

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

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








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

L[0] = A[0]
R[-1] = A[-1]
for i in range(1, N):
    L[i] = gcd(L[i-1], A[i])
    idx = N-1-i
    R[idx] = gcd(R[idx+1], A[idx])



mx = 0
for i in range(N):
	if i == N-1:	
		v = L[N-2]
	elif i == 0:	
		v = R[1]
	else:		
		v = gcd(R[i+1], L[i-1])
	mx = max(v, mx)
print(mx)



Verdicts: Time Limit Exceeded

Time Limit Exceeded

Runtime Error

Wrong Answer

Time Limit Exceeded

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted