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:
import functools
import math

n = int(input())

a_li = list(map(int, input().split()))
ans = 0
for i in range(n):
    temp = a_li.copy()
    temp.pop(i)
    gcd = functools.reduce(math.gcd, temp)
    if ans < gcd:
        ans = gcd
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

def get_cum_gcd(N, As):
    cum_gcd = [0] * N
    for i, n in enumerate(As):
        if i == 0:
            cum_gcd[i] = n
        else:
            cum_gcd[i] = np.gcd(cum_gcd[i-1], n)
    return cum_gcd

def get_cav_gcds(N, cum_l, cum_r):
    cav_gcds = [0] * N
    for i in range(N):
        if i == 0:
            cav_gcds[i] = cum_r[i+1]
        elif i == N-1:
            cav_gcds[i] = cum_l[i-1]
        else:
            cav_gcds[i] = np.gcd(cum_l[i-1], cum_r[i+1])
    return cav_gcds

def main():
    input = sys.stdin.readline
    N = int(input())
    As = list(map(int, input().split()))
    cum_l = get_cum_gcd(N, As)
    cum_r = list(reversed(get_cum_gcd(N, reversed(As))))
    cav_gcds = get_cav_gcds(N, cum_l, cum_r)
    print(max(cav_gcds))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
ans = reduce(math.gcd, a)

for i in range(n):
    b = a[:i]+a[i+1:]
    ans = max(reduce(math.gcd, b), ans)

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
n=0
i=0
while(n<N):
    i+=1
    n=2**i
INF=0
dat=[INF]*(2*n-1)
def update(i,x):
    i+=n-1
    dat[i]=x
    while(i>0):
        i=(i-1)//2
        dat[i]=gcd(dat[i*2+1],dat[i*2+2])
def find(a,b,k,l,r):
    if r<=a or b<=l:
        return INF
    if a<=l and r<=b:
        return dat[k]
    else:
        vl=find(a,b,k*2+1,l,(l+r)//2)
        vr=find(a,b,k*2+2,(l+r)//2,r)
        return gcd(vl,vr)
for i in range(N):
    update(i,A[i])
ans=0
for i in range(N):
    f=find(0,i,0,0,n)
    g=find(i+1,N,0,0,n)
    ans=max(gcd(f,g),ans)
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
import math
N = int(input())
a = list(map(int, input().split()))

gcd = []
for i in range(N):
    list_not_i = a.copy()
    list_not_i.remove(a[i])
    gcd.append(reduce(math.gcd, list_not_i))

print(max(gcd))

Submission status: Runtime Error

Solution code:
import fraction  # python3.5以降ではmath


def seekGcd(A, n):
    ans = A[0]
    for i in range(1, n):
        ans = fraction.gcd(ans, A[i])  # python3.5以降ではmath.gcd
    ans_list.append(ans)


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

for i in range(n):
    p = A.pop(0)
    seekGcd(A, n-1)
    A.append(p)

print(max(ans_list))

Submission status: Runtime Error

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

gcd = []
for i in range(N):
    list_not_i = a.copy()
    list_not_i.remove(a[i])
    gcd.append(functools.reduce(math.gcd, list_not_i))

print(max(gcd))

Submission status: Runtime Error

Solution code:
import math


def seekGcd(A, n):
    ans = A[0]
    for i in range(1, n):
        ans = math.gcd(ans, A[i])
    ans_list.append(ans)


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

seekGcd(A, n)

for i in range(n):
    p = A.pop(0)
    seekGcd(A, n-1)
    A.append(p)

print(max(ans_list))

Submission status: Runtime Error

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

import functools
import math

gcd = []
for i in range(N):
    list_not_i = a.copy()
    list_not_i.remove(a[i])
    gcd.append(functools.reduce(math.gcd, list_not_i))

print(str(max(gcd)))

Submission status: Runtime Error

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

gcd = []
for i in range(N) :
    list_not_i = a.copy()
    list_not_i.remove(a[i])
    gcd.append(functools.reduce(math.gcd, list_not_i))

print(str(max(gcd)))

Submission status: Runtime Error

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

gcd = []
for i in range(N) :
    list_not_i = a.copy()
    list_not_i.remove(a[i])
    gcd.append(functools.reduce(math.gcd, list_not_i))

print(str(max(gcd)))

Submission status: Runtime Error

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

gcd = []
for i in range(N) :
    list_not_i = a.copy()
    list_not_i.remove(a[i])
    gcd.append(functools.reduce(math.gcd, list_not_i))

print(int(max(gcd)))

Submission status: Runtime Error

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

gcd = []
for i in range(N) :
    list_not_i = a.copy()
    list_not_i.remove(a[i])
    gcd.append(functools.reduce(math.gcd, list_not_i))

print(max(gcd))

Submission status: Runtime Error

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

gcd = []
for i in range(N) :
    list_not_i = []
    for j in range(N) :
        if i != j :
            list_not_i.append(int(a[j]))
    gcd.append(functools.reduce(math.gcd, list_not_i))

print(max(gcd))

Submission status: Runtime Error

Solution code:
import math

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

for i in range(n):
    p = A.pop(0)
    ans = A[0]
    for j in range(1, n-1):
        ans = math.gcd(ans, A[j])
    ans_list.append(ans)
    A.append(p)

print(max(ans_list))

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(1000000)

import fractions
from functools import reduce

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

def mygcd(a,b):
    if a==0:
        return b
    elif b==0:
        return a
    else:
        return fractions.gcd(a,b)

L=[0]*N
for i in range(1,N):
    L[i]=mygcd(L[i-1],A[i-1])

R=[0]*N
for i in range(N-2,-1,-1):
    R[i]=mygcd(R[i+1],A[i+1])

ans=1
for i in range(N):
    c=mygcd(L(i),R(i))
    ans=max(ans,c)

print(ans)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

def mygcd(a,b):
    if a==0:
        return b
    elif b==0:
        return a
    else:
        return fractions.gcd(a,b)


def L(n):
    if n==-1:
        return 0
    else:
        return mygcd(L(n-1),A[n])

def R(n):
    if n==N:
        return 0
    else:
        return mygcd(R(n+1),A[n])

ans=1
for i in range(N):
    c=mygcd(L(i-1),R(i+1))
    ans=max(ans,c)

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
d = {}
for i in range(n):
  for ri in ret_dividable(a[i]):
    if ri in d.keys():
      d[ri]+=1
    else:
      d[ri]=1 

# 出現数が1番目に多い値を取得(二段階で並べ替え)
tmp = sorted(d.items(),key = lambda x:(x[1],x[0]) ,reverse=True)


# 全ての ai が同じ場合、答えは ai
issame = (sum([1 for ai in a if ai==a[0]]) == n)
if issame:
  print(a[0])
else:  
  # 出現数が2番目に多いものだけ抜き取る
  freq_2 = [t for t in tmp if t[1]==n-1]
  if len(freq_2)>0:
    print(freq_2[0][0])
  else:
    print(1)

Submission status: Runtime Error

Solution code:
#解説の方針にしたがった
import fractions

N = int(input())
X = list(map(int, input().split()))
   
M = 1  
L = [0 for i in range(10)] #L(0)=0
R = [0 for i in range(10)]  #R(N+1) = 0

for i in range(N):
  L[i] = (fractions.gcd(L[i-1],X[i]))

for i in reversed(range(N)):
  #print(i)
  R[i] = (fractions.gcd(R[i+1],X[i]))
    
ans = 1

#print(L)
#print(R)
for i in range(N):
  ans = max(ans, fractions.gcd(L[i-1],R[i+1]))

print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import math
from functools import reduce

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

n = int(input())
ls = list(map(int, input().split()))
ls_com = itertools.combinations(ls, n-1)
ans = 0

for i in ls_com:
    ans = max(gcd_list(i),ans)
print(ans)

Submission status: Runtime Error

Solution code:
import math
import functools
N = int(input())
a = list(map(int, input().split()))
a_max = max(a)
ans = 0

for i in range(len(a)):
    save = a[i]
    a[i] = a_max
    gcd = functools.reduce(math.gcd, a)
    if gcd > ans:
        ans = gcd
    a[i] = save
print(ans)

Submission status: Runtime Error

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

import math
from functools import reduce

def gcd(numbers):
    return reduce(math.gcd, numbers)
ans = 0
for idx, num in enumerate(A):
  result = gcd(A[:idx:]+A[idx+1::])
  if result > ans:
    ans = result
print(ans)

Submission status: Runtime Error

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

import math
from functools import reduce

def gcd(numbers):
    return reduce(math.gcd, numbers)
ans = 0
for idx, num in enumerate(A):
  result = gcd(A[:idx:]+A[idx+1::])
  if result > ans:
    ans = result
print(ans)

Submission status: Runtime Error

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

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans = 0
for idx, num in enumerate(A):
  result = gcd(A[:idx:]+A[idx+1::])
  if ans > result:
    ans = result
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import fractions

N = int(input())
arr = list(map(int, input().split()))
L = [0]
R = [0]
B = []

for i in range(N):
    L.append(fractions.gcd(arr[i], L[i]))
    R.append(fractions.gcd(arr[N - i - 1], R[i]))
for i in range(N):
    B.append(math.gcd(L[i],R[N - i - 1]))
print(max(B))

Submission status: Runtime Error

Solution code:
#ユークリッド互除法！
def gcd(a,b):
  if(a<b):
    a,b=b,a
  if(b==0):
    return a
  c= a%b
  return gcd(b,c)

n=int(input())
hoge=list(map(int,input().split()))
L=[]
L.append(hoge[0])
R=[]
R.append(hoge[-1])
for i in range(n-1):
  L.append(gcd(L[0],hoge[i+1]))
  R.append(gcd(R[0],hoge[-(i+2)]))

ans=[]
ans.append(R[-2])
ans.append(L[-2])
for i in range(n-2):
  ans.append(gcd(L[i],R[n-3-i]))
  
print(max(ans)

Submission status: Runtime Error

Solution code:
from math import gcd


def main():
    N = int(input())
    A = [0] + list(map(int, input().split()))

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


main()

Submission status: Runtime Error

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

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

def l(m): #左m個
    if m == 0:
        return 0
    else:
        return gcd(l(m-1),a[m-1])
def r(m):  #右m個
    if m == 0:
        return 0
    else:
        return gcd(r(m-1),a[n-m])
print(max([gcd(l(i),r(n-i-1)) for i in range(n)]))

Submission status: Runtime Error

Solution code:
import math

def main():
  n = int(input())
  a = list(map(int, input().split()))

  right = []
  left  = []

  right.append(a[0])
  left.append(a[-1])

  for i in range(1, len(a)-1):
    right.append(math.gcd(right[i-1], a[i]))
    left.append(math.gcd(left[i-1], a[len(a)-i-1]))
  
  ans = max(right[-1], left[-1])
  
  for i in range(len(right)-1):
    ans = max(ans, math.gcd(right[0], left[len(left)-2-i]))
    
  print(ans)
  
main()

Submission status: Runtime Error

Solution code:
import math

def main():
  n = int(input())
  a = list(map(int, input().split()))

  right = []
  left  = []

  right.append(a[0])
  left.append(a[-1])

  for i in range(1, len(a)-1):
    right.append(math.gcd(right[i-1], a[i]))
    left.append(math.gcd(left[i-1], a[-i-1]))
  
  ans = max(right[-1], left[-1])
  
  for i in range(len(right)-1):
    ans = max(ans, math.gcd(right[0], left[-2-i]))
    
  print(ans)
  
main()

Submission status: Runtime Error

Solution code:
import math

def main():
  n = int(input())
  a = list(map(int, input().split()))

  right = []
  left  = []

  right.append(a[0])
  left.append(a[-1])

  for i in range(1, len(a)-1):
    right.append(math.gcd(right[i-1], a[i]))
    left.append(math.gcd(left[i-1], a[len(a)-i-1]))
  
  ans = max(right[-1], left[-1])
  
  for i in range(len(right)-1):
    ans = max(ans, math.gcd(right[0], left[-2-i]))
    
  print(ans)
  
main()

Submission status: Runtime Error

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

N = int(input())
A = list(map(int, input().split()))
A.sort()
B = []
C = []
for i in range(1,N):
  B.append(gcd(A[0],A[i]))
  C.append(gcd(A[1],A[i]))
B.sort()
C.sort()
print(B[1],C[1])

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
import copy
N = int(input())
A=[int(i) for i in input().split()]
B=[]
def list_gcd(a):
    return reduce(fractions.gcd , a)
b = []
for i in range(N):
    a = A[:i-1]+A[i+1:]
    b.append(list_gcd(a))
print(max(b))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import math
from functools import reduce

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

#最小のものを除く
S[S.index(min(S))] = max(S)
print(reduce(math.gcd, S))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import math
from functools import reduce

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

#最小のものを除く


print(reduce(math.gcd, S.remove(min(S))))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from fractions import gcd

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

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

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

ans = 0

for i in range(N):
    a = A.pop(0)
    p = gcd_list(A)
    if p > ans:
        ans = p
    A.append(a)
print(ans)

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

ans = 0

for i in range(N):
    a = A.pop(0)
    p = gcd_list(A)
    if p > ans:
        ans = p
    A.append(a)
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 27 20:55:53 2019

@author: makigon
"""
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(map(int,input().split()))

ans = 0

for i in range(N):
    a = A.pop(0)
    p = gcd_list(A)
    if p > ans:
        ans = p
    A.append(a)
print(ans)

Submission status: Runtime Error

Solution code:
try :
    from math import gcd
except ImportError :
    from fractions import gcd


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

X = [A[0]]
Y = [A[-1]]

for i in range(1,N) :
    X.append(gcd(X[i-1], A[i]))

for i in range(N-2,-1,-1) :
    Y.append(gcd(Y[i-1], A[i]))

Y = Y[::-1]

ans = 0

for i in range(N) :
    if i == 0 :
        ans = max(ans, Y[1])
    elif i == N-1 :
        ans = max(ans, X[N-2])
    else :
        ans = max(ans, gcd(X[i-1], Y[i+1]))

print(ans)

Submission status: Runtime Error

Solution code:
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])

Submission status: Runtime Error

Solution code:
import fractions

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

gcd_l = [0]
gcd_r = [0]

for i in range(n):
  gcd_l.append(fractions.gcd(gcd_l[i], l[i]))
  gcd_r.append(fractions.gcd(gcd_r[i], l[-(i+1)]))
gcd_r = gcd_r[::-1]
# print(gcd_l)
# print(gcd_r)

ans = [0]*n
for i in range(n):
  ans[i] = fractions.gcd(gcd_l[i], gcd_r[i+1])
print(maxx(ans))

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce
from collections import deque

N = int(input())

line = [int(a) for a in input().split()]
line = deque(line)

def check(inf):
  return reduce(gcd, inf)
m=0
for i in range(N):
  x = line.pop()
  g = check(line)
  if g>m:
    m = g
  line.appendleft(x)

print(m)

Submission status: Runtime Error

Solution code:
import fractions

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

def l(m):
    if m == 0:
        return 0
    else:
        return fractions.gcd(l(m-1),a[m-1])
def r(m):
    if m == 0:
        return 0
    else:
        return fractions.gcd(r(m-1),a[n-m])
print(max([fractions.gcd(l(i),r(n-i-1)) for i in range(n)]))

Submission status: Runtime Error

Solution code:
import fractions

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

def l(m): #左m個
    if m == 0:
        return 0
    else:
        return fractions.gcd(l(m-1),a[m-1])
def r(m):  #右m個
    if m == 0:
        return 0
    else:
        return fractions.gcd(r(m-1),a[n-m])
max([fractions.gcd(l(i),r(n-i-1)) for i in range(n)])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
m = 0
for i in range(n):
    b = a.copy()
    b[i:i+1] = []
    g = b[0]
    for j in range(n-1):
        g = math.gcd(g,b[j])
    m = max(m,g)
print(m)

Submission status: Runtime Error

Solution code:
import math

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

#print(A)

lgcd=[A[0]]*N
for i in range(1,N):
    lgcd[i]=math.gcd(lgcd[i-1],A[i])

rgcd=[A[-1]]*N
for i in reversed(range(0,N-1)):
    rgcd[i]=math.gcd(rgcd[i+1],A[i])

#print(lgcd)
#print(rgcd)


ans=[0]*N
ans[0]=rgcd[1]
ans[N-1]=lgcd[N-2]
for i in range(1,N-1):
    ans[i]=math.gcd(lgcd[i-1],rgcd[i+1])
print(max(ans))

Submission status: Runtime Error

Solution code:
import math

n=int(input())
a=list(map(int,input().split()))
ans=[];work=a[:]

def gcd(l):
    if len(l)>=2:
        for i in range(1,len(l)):
            l[i]=math.gcd(l[i-1],l[i])
    return l[-1]

for i in range(n):
    work[i]=work[i-1]
    ans.append(gcd(work))
    work=a[:]
print(max(ans))

Submission status: Runtime Error

Solution code:
#ABC125C
import fractions
import copy
N = int(input())
A = list(map(int, input().split()))
ans = -1
A_n = copy.copy(A)
for i in range(N):
    element = fractions.gcd(A_n[0],A_n[1])    
    for j in range(2,N-1):
        element = fractions.gcd(element, A_n[j])
    A_n = copy.copy(A)
    A_n.pop(i)
    ans = max(element,ans)
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

ans = []
if len(a) != 1:
    ans.append(gcd(a[1:]))
    ans.append(gcd(a[:n]))

    for i in range(1, n-1):
        aaaa = []
        aaaa.append(gcd(a[:i]))
        aaaa.append(gcd(a[i+1:]))
        ans.append(gcd(aaaa))
else:
    ans.append(a[0])
    
print(max(ans))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

ans = []
ans.append(gcd(a[1:]))
ans.append(gcd(a[:n]))

for i in range(1, n-1):
    aaaa = []
    aaaa.append(gcd(a[:i]))
    aaaa.append(gcd(a[i+1:]))
    ans.append(gcd(aaaa))

print(max(ans))

Submission status: Runtime Error

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
As = nl()

from math import gcd      #3.5
gcds_left = [0] * N
gcds_right = [0] * N
gcds_left[0] = As[0]
gcds_right[N-1] = As[N-1]

for i in range(1, N):
    gcds_left[i] = gcd(As[i], gcds_left[i-1])
    gcds_right[N-1-i] = gcd(As[N-1-i], gcds_right[N-i])

max_gcd = -1
for i in range(1, N-1):
    g = gcd(gcds_left[i-1], gcds_right[i+1])
    if g > max_gcd:
        max_gcd = g
print(max(max_gcd, gcds_left[1], gcds_right[N-2]))

Submission status: Runtime Error

Solution code:
from fractions import gcd
from math import gcd

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

total=0
left=[0]*(N+1)
right=[0]*(N+1)

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

for i in range(N):
    total=max(total,gcd(left[i],right[i+1]))

print(total)

Submission status: Runtime Error

Solution code:
import fractions

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

total=0
left=[0]*(N+1)
right=[0]*(N+1)

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

for i in range[N]:
    total=max(total,fractions.gcd(left[i]),right[N+1])
    
print(total)

Submission status: Runtime Error

Solution code:
import copy
import math

n=int(input())
a=list(map(int,input().split()))
ans=0
r=[]
if n==2:
    print(max(a[0],a[1]))
else:
    for i in range(n):
      l=a.copy()
      del l[i]
      r.clear()
      for j in range(n-2):
        r.append(math.gcd(l[j],l[j+1]))
      g=r[-1]
      if ans<g:
        ans=g
    print(ans)

Submission status: Runtime Error

Solution code:
import copy
import math

n=int(input())
a=list(map(int,input().split()))
ans=0
r=[]
if n==2:
    print(max(a[0],a[1]))
else:
    
    for i in range(n):
      l=copy.copy(a)
      del l[i]
      r.clear()
      for j in range(n-2):
        r.append(math.gcd(l[j],l[j+1]))
      g=r[-1]
      if ans<g:
        ans=g
    print(ans)

Submission status: Runtime Error

Solution code:
import copy

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  l=copy.copy(a)
  del l[i]
  r=[]
  for j in range(n-2):
    r.append(gcd(l[j],l[j+1]))
  g=max(r)
  if ans<g:
    ans=g
print(ans)

Submission status: Runtime Error

Solution code:
import functools
import math
import copy

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  l=copy.copy(a)
  del l[i]
  g=functools.reduce(math.gcd, l)
  if ans<g:
    ans=g
print(ans)

Submission status: Runtime Error

Solution code:
import functools
import math
import copy

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
    l=copy.copy(a)
    del l[i]
    gcd=functools.reduce(math.gcd, l)
    if ans<gcd:
        ans=gcd
print(ans)

Submission status: Runtime Error

Solution code:
import functools
import math
import copy

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
    l=copy.copy(a)
    del l[i]
    gcd=functools.reduce(math.gcd, l)
    if ans<gcd:
        ans=gcd
print(ans)

Submission status: Runtime Error

Solution code:
import functools
import math

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  l=a
  del l[i]
  ans=max(ans,functools.reduce(math.gcd, l))
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  l=a
  del l[i]
  ans=max(ans,gcd(l))
print(ans)

Submission status: Runtime Error

Solution code:
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
    c = a % b
    return gcd(b, c)

X = [0]*N
Y = [0]*N

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

Z = [0]*n
for i in range(N):
    Z[i]=gcd(X[i],Y[i])
print(max(Z))

Submission status: Runtime Error

Solution code:
import math

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

A.sort()
A[1]=A[0]
ans=A[0]
for i in range(N):
    ans=math.gcd(ans,A[i])
print(ans)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
lst = list(map(int,input().split()))
lst_gcd =[]
for i in range(n):
    lst_new = lst[:i]+lst[i+1:]
    gcd = lst_new[0]
    for j in range(n-1):
        gcd=math.gcd(gcd,lst_new[j])
    lst_gcd.append(gcd)
print(max(lst_gcd))

Submission status: Runtime Error

Solution code:
import sys
import math
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MAT(h): return [list(map(int, input().split())) for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = INT()
    A = LIST()
    L = [0] * N
    R = [0] * N
    M = [0] * N
    for i in range(N - 1):
        L[i + 1] = math.gcd(L[i], A[i])
        R[N - i - 2] = math.gcd(R[N - i - 1], A[N - i - 1])
    maxv = 0
    for i in range(N):
        M[i] = math.gcd(L[i], R[i])
        if maxv < M[i]:
            maxv = M[i]
    print(maxv)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import math

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MAT(h): return [list(map(int, input().split())) for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = INT()
    A = LIST()
    L = [0] * N
    R = [0] * N
    M = [0] * N
    for i in range(N - 1):
        L[i + 1] = math.gcd(L[i], A[i])
        R[N - i - 2] = math.gcd(R[N - i - 1], A[N - i - 1])
    maxv = 0
    for i in range(N):
        M[i] = math.gcd(L[i], R[i])
        if maxv < M[i]:
            maxv = M[i]
    print(maxv)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import fractions
import copy
from functools import reduce

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

def r(i):
    if i==N:
        return 0
    else:
        return fractions.gcd(r(i+1),A[i])

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

ans=[]
if N==2:
    ans.append(max(A))
else:
    for i in range(N):
        ans.append(fractions.gcd(l(i),r(i+1)))

print(max(ans))

Submission status: Runtime Error

Solution code:
import fractions
import copy

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

ans=1
if N==1:
    ans=10**9
elif N==2:
    ans=max(A)
else:
    for a in A:
        A2=copy.deepcopy(A)
        A2.remove(a)
        ans=max(ans,fractions.gcd(*A2))

print(ans)

Submission status: Runtime Error

Solution code:
import fractions

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

ans=1
if len(A)==1:
    ans=10**9
elif len(A)==2:
    ans=max(A)
else:  
    for a in A:
        A2=A-{a}
        ans=max(ans,fractions.gcd(*A2))

print(ans)

Submission status: Runtime Error

Solution code:
import fractions

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

ans=1
if len(A)==1:
    ans=10**9
elif len(A)==2:
    ans=max(A)
else:  
    for a in A:
        A2=A-{a}
        print(A)
        ans=max(ans,fractions.gcd(*A2))

print(ans)

Submission status: Runtime Error

Solution code:
import fractions

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

ans=1
if len(A)==1:
    print(10**9)
elif len(A)==2:
    ans=max(A)
else:  
    for a in A:
        A2=A-{a}
        print(A)
        ans=max(ans,fractions.gcd(*A2))

print(ans)

Submission status: Runtime Error

Solution code:
import fractions

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

ans=1
if len(A)<=2:
    ans=max(A)
else:  
    for a in A:
        A2=A-{a}
        ans=max(ans,fractions.gcd(*A2))

print(ans)

Submission status: Runtime Error

Solution code:
import fractions

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

ans=1
for a in A:
    A2=A-{a}
    ans=max(ans,fractions.gcd(*A2))

print(ans)

Submission status: Runtime Error

Solution code:
def yakusu(n):
    a = []
    while(n > 1):
        i = 2
        while(True):
            if n %  i == 0:
                n /= i
                a.append(i)
                break
            i += 1
            if i > 3:
                i += 1
    return a
    
def yakusu1(n, a1):
    a2 = []
    nex = 0
    for index, i in enumerate(a1[:]):
        if n % i == 0:
            a2.append(i)
            del a1[index-nex]
            nex += 1
        else n /= i
    return a1, a2
    
def yakusu2(n, a1_miss, a):
    enter = []
    b = a1_miss[:]
    nex = 0
    n1 = n
    for index, i in enumerate(a[:]):
        if n % i != 0:
            del a[index-nex]
            nex += 1
            enter.append(i)
        else:
            n /= i
    nex = 0
    for index, i in enumerate(b):
        if n1 % i != 0:
            del a1_miss[index-nex]
            nex += 1
        else:
            n1 /= i
    for i in enter:
        a1_miss.append(i)
    return a1_miss, a
            
    
    

N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
for index, x in enumerate(A):
    if index  == 0:
        a = yakusu(A[0])
    elif index == 1:
        a1_miss, a = yakusu1(A[1], a)
    else:
        a1_miss, a = yakusu2(A[index], a1_miss, a)
value = 1
for i in a:
    value *= i
if len(a1_miss) != 0:
    print(value*max(a1_miss))
else:
    print(value)

Submission status: Runtime Error

Solution code:
n=int(input())
a=input().split()
for i in range(0,len(a)):
  a[i]=int(a[i])
answer=0
for i in range(0,len(a)):
  b=a
  del b[i]
  if answer<=gcd_list(b):
    answer=gcd_list(b)
print(answer)

Submission status: Runtime Error

Solution code:
from math import gcd
#input
N = int(input())
A = [int(i) for i in input().split()]
#cluc left and right gcd 
left = [0]*N
right = [0]*N
count = 0
left[0] = A[0]
right[-1] = A[-1]
Ans = []

for i in A[1:]:
    left[count+1] = gcd(left[count],i)
    count += 1

for i in reversed(A[:-1]):
    right[count-1] = gcd(right[count],i)
    count -= 1
# make ans
Ans.append(right[1])
Ans.append(left[-2])
for i in range(N-2):
    Ans.append(gcd(left[i],right[i+2]))
print(max(Ans))

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 = tuple(map(int, input().split()))
ans = 1

for i in range(N):
    AL = list(A)
    AL.pop(i)
    ans = max(ans, gcd_list(AL))

print(ans)