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):
n = int(input())
A = map(int, input().split())

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

X = [0] * (n + 1)
Y = [0] * (n + 1)

for i in range(n):
  X[i+1] = gcd(X[i], A[i])
  Y[n-1-i] = gcd(Y[n-i], A[n-1-i])

gcds = []

for i in range(n+1):
  gcds.append(gcd(X[i], Y[i+1]))

print(max(gcds))

from functools import reduce
import fractions

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

def gcd(data):
    if len(data) == 1:
        return data[0]
    return reduce(lambda x, y: fractions.gcd(x, y), data)

gcds = []

for i in range(1, n-2):
    gcds.append(gcd(A[0:i] + A[i+1:n]))

print(max(gcds))


# coding: utf-8

from functools import reduce
import copy
import fractions

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

default_gcd = reduce(fractions.gcd, integers)
change_to = filter(lambda x: x >= default_gcd, integers)

gcds = []

for i in range(N):
    tmp_integers = copy.copy(integers)
    for x in change_to:
        tmp_integers[i] = x
        gcds.append(reduce(fractions.gcd, tmp_integers))
print(max(gcds))


# coding: utf-8

from functools import reduce
import copy
import fractions

N = int(input())
integers = list(map(int, input().split()))
integer_set = set(integers)


gcds = []

for i in range(N):
    tmp_integers = copy.copy(integers)
    for x in integer_set:
        tmp_integers[i] = x
        gcds.append(reduce(fractions.gcd, tmp_integers))
print(max(gcds))


from functools import reduce
from itertools import combinations
import fractions

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


def gcd(data):
    if len(data) < 2:
        return data[0]
    return reduce(lambda x, y: fractions.gcd(x, y), data)

result = max(gcd(x) for x in combinations(A, n-1))

print(result)


# coding: utf-8

from functools import reduce
import copy
import fractions

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

default_gcd = reduce(fractions.gcd, integers)
change_to = filter(lambda x: x >= default_gcd, integers)

gcds = []

for i in range(N):
    orig = integers[i]
    for x in change_to:
        integers[i] = x
        gcds.append(reduce(fractions.gcd, integers))
    integers[i] = orig
print(max(gcds))


from functools import reduce
import fractions

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

def gcd(data):
    if len(data) == 1:
        return data[0]
    return reduce(lambda x, y: fractions.gcd(x, y), data)

gcds = []

for i in range(1, n-1):
    gcds.append(gcd(A[0:i] + A[i+1:n]))

print(max(gcds))


# coding: utf-8

from functools import reduce
import copy
import fractions

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


gcds = []

for i in range(N):
    for x in set(integers):
        tmp_integers = copy.copy(integers)
        tmp_integers[i] = x
        print(tmp_integers)
        gcds.append(reduce(fractions.gcd, tmp_integers))
print(max(gcds))


# coding: utf-8

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

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

L = [0]
R = [0]

for i in range(n):
    L.append(gcd(L[i], A[i]))
    R.append(gcd(R[i], A[n-1-i]))
R.reverse()

print(max(gcd(l, r) for l, r in zip(L, R)))




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

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

X = [0] * (n + 1)
Y = [0] * (n + 1)

for i in range(n):
  X[i+1] = gcd(X[i], A[i])
  Y[n-1-i] = gcd(Y[n-i], A[n-1-i])

gcds = []

for i in range(n+1):
  gcds.append(gcd(X[i], Y[i+1]))

print(max(gcds))


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

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

X = [0] * (n + 1)
Y = [0] * (n + 1)

for i in range(n):
  X[i+1] = gcd(X[i], A[i])
  Y[n-1-i] = gcd(Y[n-i], A[n-1-i])

gcds = []

for i in range(n):
  gcds.append(gcd(X[i], Y[i+1]))

print(max(gcds))


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Time Limit Exceeded

Time Limit Exceeded

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Accepted