Problem:


Score : 300 points

Problem Statement

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.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Output

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Sample Input 1

3
7 6 8

Sample Output 1

2

If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.

Sample Input 2

3
12 15 18

Sample Output 2

6

Sample Input 3

2
1000000000 1000000000

Sample Output 3

1000000000

We can replace an integer with itself.



Sample input:
3
7 6 8


Sample output:
2

Submission status: Runtime Error

Solution code:
from fractions import gcd
N = int(input())
array = list(map(int,input().split()))
gcd_arr = [array[0]]

for i in range(N-1):
  gcd_arr.append(gcd(gcd_arr[-1],array[i+1]))

gcd_arr.reverse()

for i in range(N):
  if gcd_arr[i+1] > gcd_arr[i]:
    break
    
array.pop(N-i-1)

new_gcd = array[0]
for i in range(N-2):
  new_gcd = gcd(new_gcd,array[i+1])

print(new_gcd)

Submission status: Runtime Error

Solution code:
#プログラムの例:
n=int(input())
listsT=list(map(int,input().split()))
from math import gcd
lists_left=[]
lists_right=[]
number1=0
number2=0
for i in range(n):
    if i==0:
        lists_left.append(0)
    if i==1:
        lists_left.append(listsT[0])
        number1=listsT[0]
    if i>=2:
        number1=gcd(number1,listsT[i-1])
        lists_left.append(number1)

number2=listsT[-1]
for j in range(n,0,-1):
    if j==n:
        lists_right.append(0)
    if j==n-1:
        lists_right.append(listsT[-1])
    if j<n-1:      
        number2=gcd(number2,listsT[j])  
        lists_right.append(number2)
ans=0
for x in range(n):
    if ans<= gcd(lists_right[x],lists_left[n-1-x]):
        ans=gcd(lists_right[x],lists_left[n-1-x])   
print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int, input().split()))

ans = 1
# 1つ使わない中で最大公約数が最大のものを求める
for i in range(0, n):
    if i == 0:
        gcd_num = a[1]
    else:
        gcd_num = a[0]
    for j in range(1, n):
        if i == j:
            continue
        gcd_num = math.gcd(gcd_num, a[j])
    ans = max(ans, gcd_num)
print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int, input().split()))

ans = 1
gcd_num = a[0]
# 1つ使わない中で最大公約数が最大のものを求める
for i in range(0, n):
    if i == 0:
        gcd_num = a[1]
    else:
        gcd_num = a[0]
    for j in range(0, n):
        if i == j:
            continue
        gcd_num = math.gcd(gcd_num, a[j])
    ans = max(ans, gcd_num)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split(' ')))

def myGCD(a,b):
    while b!=0:
        a,b = b,a%b
    return a

def list_gcd(numbers):
    tmp=numbers[0]
    for i in range(len(numbers)-1):
        tmp=min(tmp,myGCD(numbers[i],numbers[i+1]))
    return(tmp)

#print(list_gcd(A))

candidate=[0,0]
t1 = A[0]
candidate[0]=max(A[0],A[1])
candidate[1]=myGCD(A[0],A[1])
candidate[2]=myGCD(A[0],A[1])

for i in range(2,N):
    candidate[0]=myGCD(candidate[0],A[i])
    candidate[1]=candidate[1]
    candidate[2]=myGCD(candidate[2],A[i])
    candidate[0]=min(candidate[0],candidate[1])

#print(min(candidate))

print(max(candidate))

Submission status: Runtime Error

Solution code:
import math

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

def list_gcd(numbers):
    tmp=numbers[0]
    for i in range(len(numbers)-1):
        tmp=min(tmp,math.gcd(numbers[i],numbers[i+1]))
    return(tmp)

maxgcd = 0
for i in range(N):
    Atmp=A[0:i]
    if i < N-1:
        Atmp.extend(A[i+1:N])
    #print(Atmp)
    tmpgcd=list_gcd(Atmp)
    #print(tmpgcd)
    if tmpgcd > maxgcd:
        maxgcd = tmpgcd

print(maxgcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

def list_gcd(numbers):
    return(reduce(math.gcd,numbers))

maxgcd = 0
for i in range(N):
    Atmp=A[0:i]
    if i < N-1:
        Atmp.extend(A[i+1:N])
    #print(Atmp)
    tmpgcd=list_gcd(Atmp)
    #print(tmpgcd)
    if tmpgcd > maxgcd:
        maxgcd = tmpgcd

print(maxgcd)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0

import math
from functools import reduce

def gcd_list(numbers):
    return int(reduce(math.gcd, numbers))

for i in range(N):
    ans = max(gcd_list(A[:i]+A[i+1:]), ans)

print(ans)

Submission status: Runtime Error

Solution code:
import fraction

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

left = [0] * N
right = [0] * N

left[0] = A[0]
for i in range(1,N):
    left[i] = fraction.gcd(left[i-1],A[i])

right[N-1] = A[N-1]
for j in range(N-2,0,-1):
    right[j] = fraction.gcd(A[j],right[j+1])

can = [0] * N
can[0] = right[1]
for k in range(1,N-1):
    can[k] = fraction.gcd(left[k-1],right[k+1])
can[N-1] = left[N-2]

print(max(can))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = int(input())
A_list = list(map(int,input().split()))
f_list = []

for i in range(N):
    aaa =A_list.pop(i)
    f=gcd_list(A_list)
    f_list.append(f)
    A_list.insert(i,aaa)

print(max(f_list))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = int(input())
A_list = list(map(int,input().split()))
f_list = []

for i in range(N):
    aaa =A_list.pop(i)
    f=gcd_list(A_list)
    f_list.append(f)
    A_list.insert(i,aaa)

print(max(f_list))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import math
import sys
from functools import reduce
sys.setrecursionlimit(10 ** 7)


def solve(N: int, A: "List[int]"):
    ans = 0
    for i in range(N):
        ans = max(ans, reduce(math.gcd, A[0:i] + A[i + 1:]))
    print(ans)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools
# (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

import fractions
N = int(input())
A = list(map(int, input().split()))
L = [0]
R = [0]
for i in range(N-1):
    L.append(gcd(L[i], A[i]))
    R.append(gcd(R[i], A[-i-1]))
MAX = 0
for i in range(N):
    MAX = max(MAX, gcd(L[i], R[-i-1]))
print(MAX)

Submission status: Runtime Error

Solution code:

import fractions
L = [0]
R = [0]
for i in range(N-1):
    L.append(gcd(L[i], A[i]))
    R.append(gcd(R[i], A[-i-1]))
MAX = 0
for i in range(N):
    MAX = max(MAX, gcd(L[i], R[-i-1]))
print(MAX)

Submission status: Runtime Error

Solution code:
import functools
import math
N = int(input())
A = list(map(int, input().split()))
gcd_max = 1
for i in range(N):
    gcd = functools.reduce(math.gcd, A[i+1:] + A[:i])
    if gcd > gcd_max:
        gcd_max = gcd

print(gcd_max)

Submission status: Runtime Error

Solution code:
import functools
import math
N = int(input())
A = list(map(int, input().split()))
gcd_max = 1
for i in range(N):
    gcd = functools.reduce(math.gcd, A[i+1:] + A[:i])
    if gcd > gcd_max:
        gcd_max = gcd
        i_max = i

print(gcd_max)

Submission status: Runtime Error

Solution code:
import math as m

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

gstackl = [0]
gstackr = [0]

ans = 0

for i in range(0, n):
	gstackl.append(m.gcd(gstackl[i], al[i]))

for i in reversed(range(1, n)):
	gstackr = [m.gcd(gstackr[0], al[i])] + gstackr

gstackr.append(0)

#print(gstackl)
#print(gstackr)

for i in range(n):
	l = gstackl[i]
	r = gstackr[i]
	#print("{} {}".format(l, r))
	a = m.gcd(l, r)
	#print(a)
	if a > ans:
		ans = a

print(ans)

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce
def resolve():
    n=int(input())
    A=set(map(int,input().split()))
    ans=0
    if n==2:
        print(max(A))
        return
    for a in A:
        ans=max(ans,reduce(gcd,A^{a}))
    print(ans)
resolve()

Submission status: Runtime Error

Solution code:
from fractions import gcd
def resolve():
    n=int(input())
    A=set(map(int,input().split()))
    ans=0
    if n==2:
        print(max(A))
        return
    for a in A:
        ans=max(ans,gcd(*(A^{a})))
    print(ans)
resolve()

Submission status: Runtime Error

Solution code:
def resolve():
    from math import gcd
    #%%
    n=int(input())
    A=set(map(int,input().split()))
    ans=0
    if n==2:
        print(max(A))
        return
    for a in A:
        ans=max(ans,gcd(*(A^{a})))
    print(ans)
resolve()

Submission status: Runtime Error

Solution code:
import fractions
import copy

N = int(input())
l = list(map(int, input().split()))
m = b = copy.deepcopy(l)
n = []

for i in range(N - 1):
    l.pop(i)
    ans = l[0]
    for j in range(1,N-2):
        ans = fractions.gcd(ans, l[j])
        n.append(ans)
    l = m
    
print(max(n))

Submission status: Runtime Error

Solution code:
INFTY = 10**10
def gcd(x,y):
    if y>x:
        x,y = y,x
    while y>0:
        x,y = y,x%y
    return x
N = int(input())
A = list(map(int,input().split()))
cmin = INFTY
MIN = []
for i in range(N-1):
    c = gcd(A[i],A[i+1])
#     print("cmin,c,A[i],A[i+1]={},{},{},{}".format(cmin,c,A[i],A[i+1]))
    if c<cmin:
        cmin = c
        MIN = [(A[i],A[i+1])]
    elif c==cmin:
        MIN.append((A[i],A[i+1]))
c = gcd(A[N-1],A[0])
if c<cmin:
    MIN = [(A[N-1],A[0])]
elif c==cmin:
    MIN.append((A[N-1],A[0]))
if len(MIN)==2:
    x,y,z,w = MIN[0][0],MIN[0][1],MIN[1][0],MIN[1][1]
    if x==y and y==z and z==w:
        emin = x
    else:
        B = [x,y,z,w]
        for a in B:
            if B.count(a)==2:
                b = a
                break
        C = A[:]
        C.remove(b)
        emin = INFTY
        for i in range(N-2):
            emin = min(emin,gcd(C[i],C[i+1]))
elif len(MIN)==1:
    x,y = MIN[0][0],MIN[0][1]
    B = A[:]
    B.remove(x)
    bmin = INFTY
    for i in range(N-2):
        bmin = min(bmin,gcd(B[i],B[i+1]))
    C = A[:]
    C.remove(y)
    cmin = INFTY
    for i in range(N-2):
        cmin = min(cmin,gcd(C[i],C[i+1]))
    emin = max(bmin,cmin)
print(emin)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
    if min(a, b) == 0:
        return max(a, b)
    while b:
        a, b = b, a % b
    return a

def gcd_l(l):
    if len(l) == 1:
        return l[0]
    else:
        return gcd(l[0], gcd_l(l[1:]))

ans = 0
from copy import deepcopy
for i in range(n):
    li = deepcopy(a)
    li.remove(a[i])
    ans = max(ans, gcd_l(li))

print(ans)

Submission status: Runtime Error

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))
a.sort()
 
if len(a) == 2:
  print(max(a))
else:
  gcd_1 = fractions.gcd(a[0], a[1])
  gcd_2 = fractions.gcd(a[0], a[2])
  gcd_3 = fractions.gcd(a[1], a[2])
  if gcd_1 == gcd_2 and gcd_2 == gcd_3:
    print(gcd_1)
  elif gcd_1 == gcd_2:
    if gcd_1 < gcd_3:
      print(fractions.gcd(gcd_3, a[3]))
    else:
      print(fractions.gcd(gcd_1, a[3]))
  elif gcd_2 == gcd_3:
    if gcd_2 < gcd_1:
      print(fractions.gcd(gcd_1, a[3]))
    else:
      print(fractions.gcd(gcd_2, a[3]))
  elif gcd_1 == gcd_3:
    if gcd_1 < gcd_2:
      print(fractions.gcd(gcd_2, a[3]))
    else:
      print(fractions.gcd(gcd_1, a[3]))
  else:
    temp=[gcd_1, gcd_2, gcd_3]
    print(fractions.gcd(max(temp), a[4]))

Submission status: Runtime Error

Solution code:
def gcd(x,y):
    if y == 0:
        return x
    return gcd(x%y, y)

n = int(input())
a = list(map(int, input().split()))
L = [0]
R = [0]
now1 = 0
now2 = 0
ans = 0

for i in range(n-1):
    now1 = gcd(now1,a[i])
    L.append(now1)

    now2 = gcd(now2,a[-i-1])
    R.append(now2)

for i in range(n):
    ans = max(ans, gcd(L[i], R[n-i-1]))

print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque
import fractions
N=int(input())
s=deque(list(map(int,input().split())))
ans=1
for i in range(N):
  a=s.popleft()
  b=fractions.gcd(s[0],s[1])
  for j in range(2,N-2):
    b=fractions.gcd(b,s[j])
  ans=max(ans,b)
  s.append(a)
print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int,input().split(" ")))
b = a[0]
for i in range(n-1):
    b = math.gcd(b,a[i+1])
for i in range(n-1):
    if math.gcd(a[i],a[i+1]) == b:
        a[i] = min(a[i],a[i+1])
        a[i+1] = min(a[i],a[i+1])
        break;
b = a[0]
for i in range(n-1):
    b = math.gcd(b,a[i+1])
print(b)

Submission status: Runtime Error

Solution code:
from itertools import combinations
import math
n = int(input())
l = [int(i) for i in input().split()]

num = 0
for i in list(combinations(l,2)):
    gcd = math.gcd(i[0],i[1])
    num = max(num,gcd)
    
print(num)

Submission status: Runtime Error

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

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)

    # divisors.sort()
    return divisors

A = sorted(A)

dicts = {}

if len(A) <=2:
    for i in A:
        for num in make_divisors(i):
            if num in dicts:
                dicts[num]+=1
            else:
                dicts[num]=1
    max_value=0
    for k,v in dicts.items():
        if v>=N-1 and max_value<k:
            max_value=k

    print(max_value)
else:
    for i in range(3):
        for num in make_divisors(A[i]):
            if num in dicts:
                dicts[num]+=1
            else:
                dicts[num]=1
    
    #
    new_list=[]
    for k,v in dicts.items():
        if v>=2:
            new_list.append(k)
    new_set=set(new_list)
    for i in range(3,len(A)):
        for num in new_set:
            if A[i]%num!=0:
                new_set-=set([num])
    print(max(new_set))

Submission status: Runtime Error

Solution code:
import math

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

if n == 2:
    print(max(nums))
else:
    l_gcds = [nums[0]]
    r_gcds = [nums[-1]]
    for i in range(1, n - 1):
        l = math.gcd(l_gcds[-1], nums[i])
        r = math.gcd(r_gcds[-1], nums[n - i - 1])
        l_gcds.append(l)
        r_gcds.append(r)
        if i == 1:
          break

Submission status: Runtime Error

Solution code:
import math

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

if n == 2:
    print(max(nums))
else:
    l_gcds = [nums[0]]
    r_gcds = [nums[-1]]
    for i in range(1, n - 1):
        l = math.gcd(l_gcds[-1], nums[i])
        r = math.gcd(r_gcds[-1], nums[n - i - 1])
        l_gcds.append(l)
        r_gcds.append(r)

Submission status: Runtime Error

Solution code:
import math

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

if n == 2:
    print(max(nums))
else:
    l_gcds = [nums[0]]
    r_gcds = [nums[-1]]
    for i in range(1, n - 1):
        l = math.gcd(l_gcds[-1], nums[i])
        r = math.gcd(r_gcds[-1], nums[n - i - 1])
        l_gcds.append(l)
        r_gcds.append(r)
    r_gcds = r_gcds[::-1]
    gcds = [l_gcds[-1], r_gcds[0]]
    for i in range(1, n - 1):
        gcds.append(math.gcd(l_gcds[i - 1], r_gcds[i]))
    print(max(gcds))

Submission status: Runtime Error

Solution code:
import math

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

if n == 2:
    print(max(nums))
else:
    l_gcds = [nums[0]]
    r_gcds = [nums[-1]]
    for i in range(1, n):
        l = math.gcd(l_gcds[-1], nums[i])
        r = math.gcd(r_gcds[-1], nums[n - i - 1])
        l_gcds.append(l)
        r_gcds.append(r)
    r_gcds = r_gcds[::-1]
    gcds = [l_gcds[-2], r_gcds[1]]
    for i in range(1, n - 1):
        gcds.append(math.gcd(l_gcds[i - 1], r_gcds[i + 1]))
    print(max(gcds))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
    if min(a, b) == 0:
        return max(a, b)
    while b:
        a, b = b, a % b
    return a

def l(i):
    if i == 0:
        return 0
    else:
        return gcd(l(i-1), a[i-1])

def r(i):
    if i == n:
        return 0
    else:
        return gcd(r(i+1), a[i])

gcd_max = 1
for i in range(n):
    i_gcd = gcd(l(i), r(i+1))
    if i_gcd > gcd_max:
        gcd_max = i_gcd

print(gcd_max)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
    if min(a, b) == 0:
        return max(a, b)
    while b:
        a, b = b, a%b
    return a

def l(i):
    if i == 0:
        return 0
    else:
        return gcd(l(i-1), a[i-1])

def r(i):
    if i == n:
        return 0
    else:
        return gcd(r(i+1), a[i])

gcd_max = 1
for i in range(n):
    i_gcd = gcd(l(i), r(i+1))
    if i_gcd > gcd_max:
        gcd_max = i_gcd

print(gcd_max)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))

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

def gcd_l(l):
    if len(l) <= 1:
        return l[0]
    elif len(l) == 2:
        return gcd(l[0], l[1])
    else:
        return gcd(gcd_l(l[:-1]), l[-1])

gcd_max = 1
for i in range(n):
    if i == 0:
        i_gcd = gcd_l(a[i+1:])
    elif i == n-1:
        i_gcd = gcd_l(a[:i])
    else:
        i_gcd = gcd(gcd_l(a[:i]), gcd_l(a[i+1:]))
    if i_gcd > gcd_max:
        gcd_max = i_gcd

print(gcd_max)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))

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

def gcd_l(l):
    if len(l) == 1:
        return l[0]
    elif len(l) == 2:
        return gcd(l[0], l[1])
    else:
        return gcd(gcd_l(l[:-1]), l[-1])

gcd_max = 1
for i in range(n):
    i_gcd = gcd_l(a[:i]+a[i+1:])
    if i_gcd > gcd_max:
        gcd_max = i_gcd

print(gcd_max)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans = 0
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
    A_new = A[:i] + A[i+1:]
    ans = max(ans, gcd(*A_new))
print(ans)

Submission status: Runtime Error

Solution code:
#また、50ぷんはかかった、しかもTLE
import copy
import fractions
#from functools import reduce

n=int(input())
a1=[int(i) for i in input().split()]
#高階関数reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

#def gcd_list(numbers):
#    nul = numbers[0]
#    for i in range(1, len(numbers)):
#        nul = fractions.gcd(nul, numbers[i])
#    return nul

c=1

for i in range(n):
    a2=copy.deepcopy(a1)
    a2.pop(i)
    c=max([c,gcd_list(a2)])
print(c)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
  if a>b:
    a,b = b,a
  if a==1:
    return a
  else:
    return gcd(b%a,a)

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

ans = A[1]
g = A[0]

for i in range(N):
  g = gcd(g,A[i])
  ans = max(ans,g)
print(ans)

Submission status: Runtime Error

Solution code:
def gcd(x,y):
  if y == 0:
    return x
  else:
    return gcd(y,x%y)
gcd_A_all = []
for i in range(n):
    A_pop = [a for a in A[0:i] + A[i+1:n]]
    gcd_A = A_pop[0]
    for j in range(n-1):
        gcd_A = gcd(gcd_A, A_pop[j])
    gcd_A_all.append(gcd_A)
print(max(gcd_A_all))

Submission status: Runtime Error

Solution code:
from fractions import gcd

#####segfunc######                                                              
def segfunc(x,y):
    return gcd(x,y)

def init(init_val):
    #set_val                                                                    
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built                                                                      
    for i in range(num-2,-1,-1):
	seg[i]=segfunc(seg[2*i+1],seg[2*i+2])

def update(k,x):
    k+=num-1
    seg[k]=x
    while k+1:
	k=(k-1)//2
	seg[k]=segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
	return ide_ele
    p+=num-1
    q+=num-2
    res=ide_ele
    while q-p>1:
	if p&1==0:
            res=segfunc(res,seg[p])
	if q&1==1:
            res=segfunc(res,seg[q])
            q-=1
	p=p//2
	q=(q-1)//2
    if p==q:
	res=segfunc(res,seg[p])
    else:
        res=segfunc(segfunc(res,seg[p]),seg[q])
    return res

ide_ele=0
n=int(input())
num=2**(n-1).bit_length()
seg=[ide_ele]*2*num
a=list(map(int,input().split()))

ans=0
for i in range(n):
    ans=min(gcd(query(0,i),query(i+1,n)),ans)
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
import heapq
import copy
N = int(input())
a = list(map(int, input().split()))
heap = []
for b in a:
    c = copy.deepcopy(a)
    c.remove(b)
    ans == c[0]
    for i in range(1, N-1):
        ans = fractions.gcd(ans, c[i])
        if ans = 1:
            break
    heapq.heappush(heap, -ans)
print(-heapq.heappop(heap))

Submission status: Runtime Error

Solution code:
import fractions
import heapq
import copy
N = int(input())
a = list(map(int, input().split()))
heap = []
for b in a:
    c = copy.deepcopy(a)
    c.remove(b)
    ans = c[0]
    for i in range(1, N-1):
        ans = fractions.gcd(ans, c[i])
        if ans = 1:
            break
    heapq.heappush(heap, -ans)
print(-heapq.heappop(heap))

Submission status: Runtime Error

Solution code:
def MAP(): return map(int,input().split())
import math

n = int(input())
*a, = MAP()

mx = max(a)
a = sorted(a,key=lambda x:math.gcd(mx,x))
print(math.gcd(a[1],mx))

Submission status: Runtime Error

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))
b = [0] * 3
c = [0] * 3
for i in range(len(a)):
    if i == 0:
        b[i] = a[i]
        c[-i-1] = a[-i-1]
    else:
        b[i] = fractions.gcd(a[i], b[i-1])
        c[-i-1] = fractions.gcd(a[-i-1], c[-i])
b.insert(0, 0)
c.append(0)
m_gcd = 0
print(b, c)
for i in range(len(b)-2):
    m_gcd = max(fractions.gcd(c[i+1], b[i]), m_gcd)
print(m_gcd)

Submission status: Runtime Error

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))
b = [0] * 3
c = [0] * 3
for i in range(len(a)):
    if i == 0:
        b[i] = a[i]
        c[-i-1] = a[-i-1]
    else:
        b[i] = fractions.gcd(a[i], b[i-1])
        c[-i-1] = fractions.gcd(a[-i-1], c[-i])
b.insert(0, 0)
c.append(0)
m_gcd = 0
for i in range(len(b)-1):
    m_gcd = max(fractions.gcd(c[i+1], b[i]), m_gcd)
print(m_gcd)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
import math

sys.setrecursionlimit(1000000)

def main(): 

    N = int(input())
    A = list(map(int,input().split()))
    A_gcd_for=[]
    A_gcd_for.append(A[0])
    A_gcd_af=[]
    A_gcd_af.append(A[-1])
    for i in range(1,N):
        A_gcd_for.append(math.gcd(A_gcd_for[-1], A[i]))
        A_gcd_af.append(math.gcd(A_gcd_af[-1], A[N-i-1]))
    ans=0
    for i in range(N):
        if i==0: a = A_gcd_af[N-i-2]
        elif i==N-1: a = A_gcd_for[i-1]
        else: a = math.gcd(A_gcd_for[i-1], A_gcd_af[N-i-2])
        if a > ans:
            ans=a
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import fractions

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

for j in range(len(A)):
    B = A[:]
    B.pop(j)
    tmp = max(B)
    for i in B:
        tmp = fractions.gcd(tmp, i)
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Runtime Error

Solution code:
a

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
import math
gcd=a[0]
l=[]
r=[]
for i in range(n):
	gcd=math.gcd(gcd,a[i])
	l.append(gcd)
gcd=a[-1]
for i in range(n):
	gcd=math.gcd(gcd,a[-i-1])
	r.append(gcd)
x=list()
x.append((r[n-2]))
for i in range(n-2):
	x.append(math.gcd(l[i],r[n-i-3]))
x.append((l[n-2]))
print(max(x))

Submission status: Runtime Error

Solution code:
from functools import reduce
from fractions import *

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

def gcd_list(numbers):
    return reduce(gcd, numbers)

ans = 1
for i in range(len(A)):
    l = A.copy()
    l.pop(i)
    ans = max(ans,gcd_list(l))

print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
from fraction import *

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

def gcd_list(numbers):
    return reduce(gcd, numbers)

ans = 1
for i in range(len(A)):
    l = A.copy()
    l.pop(i)
    ans = max(ans,gcd_list(*l))

print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
from fractions import gcd

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

def gcd_list(numbers):
    return reduce(gcd, numbers)

ans = 1
for i in range(len(A)):
    l = A.copy()
    l.pop(i)
    ans = max(ans,gcd(*l))

print(ans)

Submission status: Runtime Error

Solution code:
#from math import gcd

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

    L = [[] for i in range(N+1)]
    R = [[] for i in range(N+1)]
    L[0] = 0
    R[N] = 0

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

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

    return max(M)

if __name__ == '__main__':
    print(main())

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
from math import gcd

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

    L = [[] for i in range(N+1)]
    R = [[] for i in range(N+1)]
    L[0] = 0
    R[N] = 0

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

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

    return max(M)

if __name__ == '__main__':
    print(main())

Submission status: Runtime Error

Solution code:
import fractions
n=int(input())
v=list(map(int,input().split()))
def g(a,b):
  if a==0:return b
  if b==0:return a
  return fractions.gcd(a,b)
l=[0]*(n+1)
r=[0]*(n+1)
for i in range(1,n+1):
  l[i]=g(l[i-1],v[i-1])
for i in range(n)[::-1]:
  r[i]=g(r[i+1],v[i])
x=0
for i in range(n):
  c=g(l[i],r[i+1])
  x=max(c,x)
print(ans)

Submission status: Runtime Error

Solution code:
import math
ans=0
c=0
N = int(input())
A = [int(i) for i in input().split()] 
L=[1]*N
R=[1]*N
L[0]=1
L[1]=A[0]
R[N-1]=1
R[N-2]=A[N-1]
for i in range(2,N):
    L[i]=math.gcd(L[i-1],A[i-1])
    R[N-i-1]=math.gcd(R[N-i],A[N-i])
for i in range(N):
    if i==0 or i==N-1:
        c=max(L[i],R[i])
        if c>=ans:
            ans=c
    else:
        c=math.gcd(L[i],R[i])
        if c>=ans:
            ans=c
print(ans)

Submission status: Runtime Error

Solution code:
import math
ans=0
c=0
N = int(input())
A = [int(i) for i in input().split()] 
L=[1]*N
R=[1]*N
L[0]=1
L[1]=A[0]
R[N-1]=1
R[N-2]=A[N-1]
for i in range(2,N):
    L[i]=math.gcd(L[i-1],A[i-1])
    R[N-i-1]=math.gcd(R[N-i],A[N-i])
for i in range(N):
    if i==0 or i==N-1:
        c=max(L[i],R[i])
        if c>=ans:
            ans=c
    else:
        c=math.gcd(L[i],R[i])
        if c>=ans:
            ans=c
print(ans)

Submission status: Runtime Error

Solution code:
import math
ans=0
c=0
N = int(input())
A = [int(i) for i in input().split()] 
L=[1]*N
R=[1]*N
L[0]=1
L[1]=A[0]
R[N-1]=1
R[N-2]=A[N-1]
for i in range(2,N):
    L[i]=math.gcd(L[i-1],A[i-1])
    R[N-i-1]=math.gcd(R[N-i],A[N-i])
print(L,R)
for i in range(N):
    if i==0 or i==N-1:
        c=max(L[i],R[i])
        if c>=ans:
            ans=c
    else:
        c=math.gcd(L[i],R[i])
        if c>=ans:
            ans=c
print(ans)

Submission status: Runtime Error

Solution code:
import math
ans=0
N = int(input())
A = [int(i) for i in input().split()] 
B=A
L=[1]*N
R=[1]*N
L[0]=1
L[1]=A[0]
R[N-1]=1
R[N-2]=A[N-1]
for i in range(2,N):
    L[i]=math.gcd(L[i-1],A[i-1])
    R[N-i-1]=math.gcd(R[N-i],A[N-i])
for i in range(N):
    c=math.gcd(L[i],R[i])
    if c>ans:
        ans=c
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))
def gcd(pos, l, cur_gcd):
  if pos == len(l):
    return cur_gcd
  else:
    return gcd(pos+1, l, fractions.gcd(cur_gcd, l[pos]))
l1 = []
l2 = a[:]
ans = gcd(1, l2, l2[0])
for i in range(n):
  num = l2.pop(0)
  if len(l1) > 0:
    l1_gcd = gcd(1, l1, l1[0])
  if len(l2) > 0:
    l2_gcd = gcd(1, l2, l2[0])
  
  if len(l1) < 1:
    ans = max(ans, l2_gcd)
  elif len(l2) < 1:
    ans = max(ans, l1_gcd)
  else:
    ans = max(ans, fractions.gcd(l1_gcd, l2_gcd))
  l1.append(num)
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))
def gcd(pos, l, cur_gcd):
  if pos == len(l):
    return cur_gcd
  else:
    return gcd(pos+1, l, fractions.gcd(cur_gcd, l[pos]))
l1 = a[:n//2]
l2 = a[n//2:]
l1_gcd = gcd(1, l1, l1[0])
l2_gcd = gcd(1, l2, l2[0])
ans = fractions.gcd(l1_gcd, l2_gcd)

for i in range(n):
  if i < len(l1):
    if len(l1) < 2:
      ans = max(ans, l2_gcd)
      continue
    temp = [l1[j]  for j  in range(len(l1)) if i != j]
    temp_gcd = gcd(1, temp, temp[0])
    ans = max(ans, fractions.gcd(temp_gcd, l2_gcd))
  else:
    if len(l2) < 2:
      ans = max(ans, l1_gcd)
      break
    temp = [l2[j]  for j  in range(len(l2)) if i!= j+len(l1)]
    temp_gcd = gcd(1, temp, temp[0])
    ans = max(ans, fractions.gcd(temp_gcd, l1_gcd))
print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int, input().split()))
def gcd(pos, l, cur_gcd):
  if pos == len(l):
    return cur_gcd
  else:
    return gcd(pos+1, l, math.gcd(cur_gcd, l[pos]))
l1 = a[:n//2]
l2 = a[n//2:]
l1_gcd = gcd(1, l1, l1[0])
l2_gcd = gcd(1, l2, l2[0])
ans = math.gcd(l1_gcd, l2_gcd)

for i in range(n):
  if i < len(l1):
    if len(l1) < 2:
      ans = max(ans, l2_gcd)
      continue
    temp = [l1[j]  for j  in range(len(l1)) if i != j]
    temp_gcd = gcd(1, temp, temp[0])
    ans = max(ans, math.gcd(temp_gcd, l2_gcd))
  else:
    if len(l2) < 2:
      ans = max(ans, l1_gcd)
      break
    temp = [l2[j]  for j  in range(len(l2)) if i!= j+len(l1)]
    temp_gcd = gcd(1, temp, temp[0])
    ans = max(ans, math.gcd(temp_gcd, l1_gcd))
print(ans)

Submission status: Runtime Error

Solution code:
from fractions import gcd 
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
    ans=max(ans,gcd(a[:i]+a[i+1:]))
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd 
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
    ans=max(ans,reduce(gcd,a[:i]+a[i+1:]))
print(ans)

Submission status: Runtime Error

Solution code:
import math


def solve():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    m = []
    for i in range(n):
        gcd = 0
        b = [a[x] for x in range(n) if x != i]
        for j in range(n - 2):
            gcd = math.gcd(b[j], b[j + 1])
        m.append(gcd)
    return max(m)


if __name__ == "__main__":
    print(solve())