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:
t=list(map(int,input().split()))
s=list(map(int,input().split()))
def gcd(x,y):
  if y==0:
    return(x)
  else:
    return gcd(y,x%y)
  
a=gcd(s[0],s[1])
b=gcd(s[0],s[2])
c=gcd(s[1],s[2])
if a<b:
  if b<c:
    print(c)
  else:
    print(b)
else:
  if a<c:
    print(c)
  else:
    print(a)

Submission status: Runtime Error

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

import sys
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd

def input(): return sys.stdin.readline().strip()
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
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 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

class SegTree:
    """
    以下のクエリを処理する
    1.update:  i番目の値をxに更新する
    2.get_val: 区間[l, r)の値を得る
    """
 
    def __init__(self, n, func, init):
        """
        :param n: 要素数
        :param func: 値の操作に使う関数(min, max, addなど)
        :param init: 要素の初期値
        """
        n += 1
        self.n = n
        self.func = func
        self.init = init
        # nより大きい2の冪数
        n2 = 1
        while n2 < n:
            n2 <<= 1
        self.n2 = n2
        self.tree = [self.init] * (n2 << 1)
 
    def update(self, i, x):
        """
        i番目の値をxに更新
        :param i: index(0-indexed)
        :param x: update value
        """
        i += self.n2
        self.tree[i] = x
        while i > 1:
            self.tree[i >> 1] = x = self.func(x, self.tree[i ^ 1])
            i >>= 1
 
    def get_val(self, a, b):
        """
        [a, b)の値を得る
        :param a: index(0-indexed)
        :param b: index(0-indexed)
        """
        return self._get_val(a, b, 1, 0, self.n2)
 
    def _get_val(self, a, b, k, l, r):
        """
        [a, b)の値を得る内部関数
        :param k: 現在調べている区間のtree内index
        :param l, r: kが表す区間の左右端index [l, r)
        :return: kが表す区間と[a, b)の共通区間内での最小値。共通区間を持たない場合は初期値
        """
        # 範囲外なら初期値
        if r <= a or b <= l:
            return self.init
        # [a,b)が完全に[l,r)を包含するならtree[k]の値を採用
        if a <= l and r <= b:
            return self.tree[k]
        # 一部だけ範囲内なら2つに分けて再帰的に調査
        m = (l + r) // 2
        return self.func(
            self._get_val(a, b, k << 1, l, m),
            self._get_val(a, b, (k << 1) + 1, m, r)
        )

N=INT()
A=LIST()

st=SegTree(N+2, gcd, 0)
for i in range(1, N+1):
    st.update(i, A[i])

ans=0
for i in range(1, N+1):
    ans=max(ans, gcd(st.get_val(0, i), st.get_val(i+1, N+2)))
print(ans)

Submission status: Runtime Error

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

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

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

		
for i in range(1, N):
	L.append(gcd(L[-1], A[i]))
	R.insert(0, gcd(R[0], N - i))
	
# print(L, R)
high = 1

for i in range(N):
	if i == 0:
		ans = R[1]
	elif i == N - 1:
		ans = L[-]
	else:
		ans = gcd(L[i - 1], R[i + 1])
	if ans > high:
		high = ans
		
print(high)

Submission status: Runtime Error

Solution code:
import math

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

def gcd_list(num_list):
    for i, num in enumerate(num_list):
        if i == 0:
            g = num
        else:
            g = math.gcd(num, g)
    return g

GCD = 0
for i in range(N):
    others = A[:]
    others.pop(i)
    gcd = gcd_list(others)
    if gcd > GCD:
        GCD = gcd
print(GCD)

Submission status: Runtime Error

Solution code:
import math

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

def gcd_list(num_list):
    for i, num in enumerate(num_list):
        if i == 0:
            g = num
        else:
            g = math.gcd(num, g)
    return g

GCD = 0
for i in range(N):
    others = A[:i] + A[i+1:]
    gcd = gcd_list(others)
    if gcd > GCD:
        GCD = gcd
print(GCD)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

GCD = 0
for i in range(N):
    others = A[:i] + A[i+1:]
    gcd = gcd_list(others)
    if gcd > GCD:
        GCD = gcd
print(GCD)

Submission status: Runtime Error

Solution code:
from fractions import gcd
import functools
import math

n = int(input())
a = list(map(int,input().split()))
l = []
m = []
l.append(0)
m.append(0)
for i in range(n):
    l.append(math.gcd(l[i],a[i]))
    m.append(math.gcd(m[i],a[-(i+1)]))
b = [math.gcd(l[i],m[-(i+2)]) for i in range(n)]
print(max(b))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

l = []
for i in range(n):
    a_except_for_i = a[:i] + a[i + 1:]
    l.append(reduce(math.gcd, a_except_for_i))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

l = []
for i in range(n):
    a_except_for_i = a[:i] + a[i + 1:]
    l.append(reduce(math.gcd, a_except_for_i))
print(max(l))

Submission status: Runtime Error

Solution code:
from fractions import gcd

n = int(input())
a = [int(i) for i in input().split()]
l,r = [0],[0]
for i in range(n//2+1):
    l.append(gcd(l[i],a[i]))
    r.append(gcd(a[n-i-1],r[i]))

#print(l,r)
ans = 0
for i in range(min(len(l),len(r))):
    ans = max(ans,gcd(l[i],r[n-i-1]))
print(ans)

Submission status: Runtime Error

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

if n==2:
    b=max(a)
else:
    s1=gcd(a[0],a[1])
    s2=gcd(a[0],a[2])
    s3=gcd(a[2],a[1])
    c=gcd(s1,s2)
    b=max(s1,s2,s3)
    if b==s1:
        t=a[2]
    elif b==s2:
        t=a[1]
    else:
        t=a[0]
    if len(a)>=4:
        for i in a[3:]:
            d=gcd(b,i)
            if d>c:
                b=d
                c=gcd(c,i)
            else:
                t=i
                b=c
                c=d
print(b)

Submission status: Runtime Error

Solution code:
from functools import reduce
from itertools import combinations
from fractions import gcd

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

def get_gcd(number_list):
    return reduce(gcd, number_list)

def L_gcd(i):
    if i == -1:
        return 0
    else:
        return gcd(A[i - 1], L_gcd(i - 1))
        
def R_gcd(i):
    if i == N:
        return 0
    else:
        return gcd(A[i], R_gcd(i + 1))


gcd_list = []
for i in range(N):
    Left = L_gcd(i)
    Right = R_gcd(i)
    gcd_list.append(gcd(Left, Right))


print(int(max(gcd_list)))

Submission status: Runtime Error

Solution code:
from functools import reduce
from itertools import combinations
from fractions import gcd

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

def get_gcd(number_list):
    return reduce(gcd, number_list)

def L_gcd(i):
    if i == -1:
        return 0
    else:
        return gcd(A[i - 1], L_gcd(i - 1))
        
def R_gcd(i):
    if i == N:
        return 0
    else:
        return gcd(A[i], R_gcd(i + 1))


gcd_list = []
for i in range(N):
    Left = L_gcd(i)
    Right = R_gcd(i + 1)
    gcd_list.append(gcd(Left, Right))

#print(gcd_list)

print(int(max(gcd_list)))

Submission status: Runtime Error

Solution code:
from functools import reduce
from itertools import combinations
from fractions import gcd

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

def get_gcd(number_list):
    return reduce(gcd, number_list)

def L_gcd(i):
    if i == 0:
        return 0
    else:
        return gcd(A[i - 1], L_gcd(i - 1))
        
def R_gcd(i):
    if i == N:
        return 0
    else:
        return gcd(A[i], R_gcd(i + 1))


gcd_list = []
for i in range(N):
    Left = L_gcd(i)
    Right = R_gcd(i + 1)
    gcd_list.append(gcd(Left, Right))

#print(gcd_list)

print(int(max(gcd_list)))

Submission status: Runtime Error

Solution code:
import numpy

n = int(input())
a_list = [int(a) for a in input().split()]

left = [0]
right = [0]
for a in a_list:
    left.append(numpy.gcd(left[-1], a))
    
a_list.reverse()
for a in a_list:
    right.append(numpy.gcd(right[-1], a))

right.reverse()

m = []
for i in range(len(a_list)):
    m.append(numpy.gcd(left[i], right[i + 1]))
    
print(max(m))

Submission status: Runtime Error

Solution code:

from functools import reduce
from itertools import combinations
from math import gcd

def get_gcd(number_list):
    return reduce(gcd, number_list)

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

skipped = list(combinations(Numbers, N - 1))

gcd_list = [get_gcd(item) for item in skipped]
    
print(int(max(gcd_list)))

Submission status: Runtime Error

Solution code:

from functools import reduce
from itertools import combinations
from fractions import gcd

def get_gcd(number_list):
    return reduce(gcd, number_list)

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

skipped = list(map(combinations(Numbers, N - 1)))

gcd_list = [get_gcd(item) for item in skipped]
    
print(int(max(gcd_list)))

Submission status: Runtime Error

Solution code:
#ずっとre
from functools import reduce
from itertools import combinations
from fractions import gcd

def get_gcd(number_list):
    return reduce(gcd, number_list)

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

skipped = list(map(list, combinations(Numbers, N - 1)))

gcd_list = [get_gcd(skipped) for i in range(N)]
    
print(int(max(gcd_list)))

Submission status: Runtime Error

Solution code:
#ずっとre
from functools import reduce
from itertools import combinations
from fractions import gcd

def get_gcd(number_list):
    return reduce(gcd, number_list)

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

skipped = list(map(list, combinations(Numbers, 5)))

gcd_list = [get_gcd(skipped) for i in range(N)]
    
print(int(max(gcd_list)))

Submission status: Runtime Error

Solution code:
#ずっとre
from math import gcd
from functools import reduce

def get_gcd(number_list):
    return reduce(gcd, number_list)

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

gcd_list = [0] * N
for i in range(N):
    tmp_list = Numbers[:i] + Numbers[i + 1:]
    gcd_list[i] = get_gcd(tmp_list)
    
print(int(max(gcd_list)))

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce

def get_gcd(number_list):
    return reduce(gcd, number_list)

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

gcd_list = []
for i in range(N):
    tmp_list = Numbers[:i] + Numbers[i + 1:]
    gcd_list.append(get_gcd(tmp_list))
print(int(max(gcd_list)))

Submission status: Runtime Error

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

from math import gcd
from functools import reduce
import sys

def get_gcd(number_list):
    return reduce(gcd, number_list)

gcd_list = []
for i in range(N):
    tmp_list = Numbers[:i] + Numbers[i + 1:]
    gcd_list.append(get_gcd(tmp_list))
print(int(max(gcd_list)))

Submission status: Runtime Error

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

def get_gcd(number_list):
    return reduce(gcd, number_list)

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

gcd_list = []
for i in range(N):
    tmp_list = Numbers[:i] + Numbers[i + 1:]
    gcd_list.append(get_gcd(tmp_list))
print(int(max(gcd_list)))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import sys

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

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

print(Numbers)

if len(Numbers) == 2:
    print(int(max(Numbers)))
    sys.exit()
else:
    gcd_list = []
    for i in range(N):
        tmp_list = Numbers[:i] + Numbers[i + 1:]
        gcd_list.append(gcd(tmp_list))
    print(int(max(gcd_list)))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import sys

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

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

if N == 2:
    print(int(max(Numbers)))
    sys.exit()
else:
    gcd_list = []
    for i in range(N):
        tmp_list = Numbers[:i] + Numbers[i + 1:]
        gcd_list.append(gcd(tmp_list))
    print(int(max(gcd_list)))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import sys

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

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


gcd_list = []
for i in range(N):
    tmp_list = Numbers[:i] + Numbers[i + 1:]
    gcd_list.append(gcd(tmp_list))
print(int(max(gcd_list)))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import sys

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

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

if N == 2:
    print(int(max(Numbers)))
    sys.exit()

gcd_list = []
for i in range(N):
    tmp_list = Numbers[:i] + Numbers[i + 1:]
    gcd_list.append(gcd(tmp_list))
print(int(max(gcd_list)))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import sys

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

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

if N == 2:
    print(max(Numbers))
    sys.exit()

gcd_list = []
for i in range(N):
    tmp_list = Numbers[:i] + Numbers[i + 1:]
    gcd_list.append(gcd(tmp_list))
print(max(gcd_list))

Submission status: Runtime Error

Solution code:
from fraction import gcd
# from functools import reduce
# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)

n=int(input())

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

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-i],a[n-i-1])

# print(left)
# print(right)
last=[0]*n

for i in range(n):
    last[i]=(gcd(left[i],right[i+1]))


print(max(last))

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

left=[0]*(n+1)
right=[0]*(n+1)

left[1]=a[0]
right[n-1]=a[n-1]

for i in range(1,n):
    left[i+1]=math.gcd(left[i],a[i])
    right[n-1-i]=math.gcd(right[n-i],a[n-i-1])

# print(left)
# print(right)
last=[0]*n
last[0]=right[1]

for i in range(1,n-1):
    last.append(math.gcd(left[i],right[n-i]))

last[n-1]=left[n-1]

print(max(last))

Submission status: Runtime Error

Solution code:
import fractions
from sys import stdin
data = [int(x) for x in stdin.readline().rstrip().split()]
acc_gcd = fractions.gcd(data[0],data[1])
for i in data:
    acc_gcd = fractions.gcd(acc_gcd,i)
print(acc_gcd)

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

left=[a[0]]
right=[a[n-1]]
for i in range(n-2):
    left.append(math.gcd(left[i],a[i+1]))
    right.append(math.gcd(right[i],a[n-2-i]))

# print(left)
# print(right)
last=[right[n-2],left[n-2]]

for i in range(n-2):
    last.append(math.gcd(left[i],right[n-3-i]))

print(max(last))

Submission status: Runtime Error

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

import math
from functools import reduce

cnt = sum([List[i]%2 for i in range(N)] )

if cnt==0 or N:
    temp = sorted(List)
    temp[0] = temp[1]
    print(reduce(math.gcd, temp))

elif cnt==1:
    odd = list(filter(lambda x: x%2==1, List))[0]
    List.remove(odd)
    print(educe(math.gcd, List))

elif cnt==N-1:
    even = list(filter(lambda x: x%2==0, List))[0]
    List.remove(even)
    print(educe(math.gcd, List))
    
else:
    print(1)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

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

for i in range(N):
        M = [A[i-1]]
        hoge = A[i]
        A[i] = A[i-1]
        for k in range(N):
                M.append(gcd(M[k],A[k]))
                print(M)

        if M[N] >= output:
                output = M[N]
        A[i]=hoge

print(output)

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()))
output=0


for i in range(N):
        hoge = A[i]
        A[i] = A[i-1]
        if gcd(A) >= output:
                output = gcd(A)
        A[i]=hoge

print(output)

Submission status: Runtime Error

Solution code:
# from fractions import gcd
from math import gcd

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

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


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

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

M = [0 for _ in range(N)]

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

print(max(M))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
forward = [0]
back =[0]
for i in range(0,n-1):
    forward.append(fractions.gcd(forward[i], a[i]))
    back.append(fractions.gcd(back[i], a[n-i-1]))

back.reverse()

ans = 0
for i in range(n):
    ans = max(ans, fractions.gcd(forward[i], back[i]))
print(ans)

Submission status: Runtime Error

Solution code:
import fraction
import copy
from functools import reduce

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

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0
for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r1 = max(r1,gcd_list(nl2))

print(str(r1))

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce

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

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0
for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r1 = max(r1,gcd_list(nl2))

print(str(r1))

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce

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

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0
for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r1 = max(r1,gcd_list(nl2))

print(r1)

Submission status: Runtime Error

Solution code:
import fraction
import copy
from functools import reduce

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

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0
for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r1 = max(r1,gcd_list(nl2))

print(r1)

Submission status: Runtime Error

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

import itertools
import fractions
if len(a)==2:
  print(max(*a))
else:
  print(max([fractions.gcd(*list(i)) for i in itertools.combinations(a,len(a)-1)]))

Submission status: Runtime Error

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

import itertools
import fractions
if len(a) > 2:
  print(max(*a))
else:
  print(max([fractions.gcd(*list(i)) for i in itertools.combinations(a,len(a)-1)]))

Submission status: Runtime Error

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

import itertools
import fractions

print(max([fractions.gcd(*list(i)) for i in itertools.combinations(a,len(a)-1)]))

Submission status: Runtime Error

Solution code:
import numpy

n = int(input())
a_list = [int(a) for a in input().split()]

left = [0]
right = [0]
for a in a_list:
    left.append(numpy.gcd(left[-1], a))

a_list.reverse()
for a in a_list:
    right.append(numpy.gcd(right[-1], a))

right.reverse()

m = []
for i in range(len(a_list)):
    m.append(numpy.gcd(left[i], right[i + 1]))

print(max(m))

Submission status: Runtime Error

Solution code:
import np

n = int(input())
a_list = [int(a) for a in input().split()]

left = [0]
right = [0]
for a in a_list:
    left.append(np.gcd(left[-1], a))
    
a_list.reverse()
for a in a_list:
    right.append(np.gcd(right[-1], a))

right.reverse()

m = []
for i in range(len(a_list)):
    m.append(np.gcd(left[i], right[i + 1]))
    
print(max(m))

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a_list = [int(a) for a in input().split()]

left = [0]
right = [0]
for a in a_list:
    left.append(math.gcd(left[-1], a))
    
a_list.reverse()
for a in a_list:
    right.append(math.gcd(right[-1], a))

right.reverse()

m = []
for i in range(len(a_list)):
    m.append(math.gcd(left[i], right[i + 1]))
    
print(max(m))

Submission status: Runtime Error

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

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

# L(i)はa0, a1 ..., aiの最大公約数
def L(i):
  if i == -1:
    return 0
  else:
    return gcd(L(i-1),a[i])

# R(i)はai, ai+1 ..., aN-1の最大公約数
def R(i):
  if i == n:
    return 0
  else:
    return gcd(R(i+1),a[i])

ans = 0
for i in range(n):
  ans = max(ans,gcd(L(i-1),R(i+1)))
  
print(ans)

Submission status: Runtime Error

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

def gcd(x,y):
  x,y = min(x,y),max(x,y)
  if x == 0:
    return y
  else:
    return gcd(y % x, x)
  
'''
以下のように書くと不正解(max()で比較する前にxが上書きされるから)
def gcd(x,y):
  x = min(x,y)
  y = max(x,y)
  print(x,y)
  if x == 0:
    return y
  else:
    return gcd(y % x, x)
'''


# L(i)はa0, a1 ..., aiの最大公約数
def L(i):
  if i == -1:
    return 0
  else:
    return gcd(L(i-1),a[i])

# R(i)はai, ai+1 ..., aN-1の最大公約数
def R(i):
  if i == n:
    return 0
  else:
    return gcd(R(i+1),a[i])

ans = 0
for i in range(n):
  ans = max(ans,gcd(L(i-1),R(i+1)))
  
print(ans)

Submission status: Runtime Error

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

M = [0]

def gcd(x,y):
  x,y = min(x,y),max(x,y)
  if x == 0:
    return y
  else:
    return gcd(y % x, x)
  
'''
以下のように書くと不正解(max()で比較する前にxが上書きされるから)
def gcd(x,y):
  x = min(x,y)
  y = max(x,y)
  print(x,y)
  if x == 0:
    return y
  else:
    return gcd(y % x, x)
'''


# L(i)はa0, a1 ..., aiの最大公約数
def L(i):
  if i == -1:
    return 0
  else:
    return gcd(L(i-1),a[i])

# R(i)はai, ai+1 ..., aN-1の最大公約数
def R(i):
  if i == n:
    return 0
  else:
    return gcd(R(i+1),a[i])

for i in range(n):
  M.append(gcd(L(i-1),R(i+1)))
  
print(max(M))

Submission status: Runtime Error

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

M = []

def gcd(x,y):
  x,y = min(x,y),max(x,y)
  if x == 0:
    return y
  else:
    return gcd(y % x, x)
  
'''
以下のように書くと不正解(max()で比較する前にxが上書きされるから)
def gcd(x,y):
  x = min(x,y)
  y = max(x,y)
  print(x,y)
  if x == 0:
    return y
  else:
    return gcd(y % x, x)
'''


# L(i)はa0, a1 ..., aiの最大公約数
def L(i):
  if i == -1:
    return 0
  else:
    return gcd(L(i-1),a[i])

# R(i)はai, ai+1 ..., aN-1の最大公約数
def R(i):
  if i == n:
    return 0
  else:
    return gcd(R(i+1),a[i])

for i in range(n):
  M.append(gcd(L(i-1),R(i+1)))
  
print(max(M))

Submission status: Runtime Error

Solution code:
N=int(input())
LA=list(map(int,input().split()))
ans=[]

from math import gcd
from functools import reduce
def multigcd(item):
    return reduce(gcd, item)

for n in range(N):
    L=LA[:n]+LA[n+1:]
    ans.append(multigcd(L))

print(max(ans))

Submission status: Runtime Error

Solution code:
N=int(input())
LA=list(map(int,input().split()))
ans=[]

from math import gcd
from functools import reduce
def func(item):
    return reduce(gcd, item)

for n in range(N):
    L=LA[:n]+LA[n+1:]
    ans.append(func(L))

print(max(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
nums = [int(i) for i in input().split()]
nums = sorted(list((set(nums))), reverse=True)
def compute_divs(n):
    divs = []
    if n == 1: return 1
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            divs.append(i)
            if i != n // i:
                divs.append(n//i)
    divs.append(n)
    return divs

if len(nums) == 1: ans = nums[0]
else:
    divs1 = compute_divs(nums[0])
    divs2 = compute_divs(nums[1])
    divs = sorted(list(set(divs1+divs2)))
    for i in reversed(divs):
        c= 0
        for j in range(len(nums)):
            if nums[j] % i != 0:
                c += 1
                if c == 2:
                    break
        if c <= 1:
            ans = i
            break
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
nums = [int(i) for i in input().split()]
nums = list((set(nums)))
def compute_divs(n):
    divs = []
    if n == 1: return 1
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            divs.append(i)
            if i != n // i:
                divs.append(n//i)
    divs.append(n)
    return divs

if len(nums) == 1: ans = nums[0]
else:
    divs1 = compute_divs(nums[0])
    divs2 = compute_divs(nums[1])
    divs = sorted(list(set(divs1+divs2)))
    for i in reversed(divs):
        c= 0
        for j in range(len(nums)):
            if nums[j] % i != 0:
                c += 1
                if c == 2:
                    break
        if c <= 1:
            ans = i
            break
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
nums = [int(i) for i in input().split()]
nums = list((set(nums)))
def compute_divs(n):
    divs = []
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            divs.append(i)
            if i != n // i:
                divs.append(n//i)
    divs.append(n)
    return divs

if len(nums) == 1: ans = nums[0]
else:
    divs1 = compute_divs(nums[0])
    divs2 = compute_divs(nums[1])
    divs = sorted(list(set(divs1+divs2)))
    for i in reversed(divs):
        c= 0
        for j in range(len(nums)):
            if nums[j] % i != 0:
                c += 1
                if c == 2:
                    break
        if c <= 1:
            ans = i
            break
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
nums = [int(i) for i in input().split()]
nums = list((set(nums)))
def compute_divs(n):
    divs = []
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            divs.append(i)
            if i != n // i:
                divs.append(n//i)
    divs.append(n)
    return divs

if len(nums) == 1: ans = nums[0]
else:
    divs1 = compute_divs(nums[0])
    divs2 = compute_divs(nums[1])
    divs = sorted(list(set(divs1+divs2)))
    print(divs)
    for i in reversed(divs):
        c= 0
        for j in range(len(nums)):
            if nums[j] % i != 0:
                c += 1
                if c == 2:
                    break
        if c <= 1:
            ans = i
            break
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcds(*numbers):
    return reduce(math.gcd, numbers)

def resolve():
    N = int(input())
    As = list(map(int, input().split(" ")))
    if N == 2:
        return max(As)

    gcdmax = 0
    for i in range(N):
        if i == N-1:
            gcd = gcds(*As[:i])
        else:
            gcd = gcds(*As[:i], *As[i+1:])
        gcdmax = max(gcdmax, gcd)

    return gcdmax

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

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcds(*numbers):
    return reduce(math.gcd, numbers)

def resolve():
    N = int(input())
    As = list(map(int, input().split(" ")))
    if N == 2:
        return max(As)

    gcdmax = 0
    for i in range(N):
        gcd = gcds(*As[:i], *As[i+1:])
        gcdmax = max(gcdmax, gcd)

    return gcdmax

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

Submission status: Runtime Error

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

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

for i in range(N):
	a = A.pop(i)
 	l.append(gcd_list(A))
	A.insert(i,a)
print(max(l))

Submission status: Runtime Error

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

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

for i in range(N):
  a = A.pop(i)
  l.append(gcd_list(A))
  A.insert(i,a)
print(max(l))

Submission status: Runtime Error

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

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

for i in range(N):
  a = A.pop(i)
  l.append(gcd_list(A))
  A.insert(i,a)
print(max(l))

Submission status: Runtime Error

Solution code:
N = int(input())
nums = [int(i) for i in input().split()]
from math import gcd
from functools import reduce
def compute_gcd(numbers):
    return reduce(gcd, numbers)
from copy import copy
gcds = []
for i in range(len(nums)):
    n = copy(nums)
    n.pop(i)
    gcds.append(compute_gcd(n))
print(max(gcds))

Submission status: Runtime Error

Solution code:
N = int(input())
nums = [int(i) for i in input().split()]
from math import gcd
from functools import reduce
def compute_gcd(numbers):
    return reduce(gcd, numbers)
from copy import copy
gcds = []
for i in range(len(nums)):
    n = copy(nums)
    n.pop(i)
    gcds.append(compute_gcd(n))
gcds = list(set(gcds))
print(gcds[-1])

Submission status: Runtime Error

Solution code:
N = int(input())
nums = [int(i) for i in input().split()]
from fraction import gcd
from functools import reduce
def compute_gcd(numbers):
    return reduce(gcd, numbers)
from copy import copy
gcds = []
for i in range(len(nums)):
    n = copy(nums)
    n.pop(i)
    gcds.append(compute_gcd(n))
gcds = list(set(gcds))
print(gcds[-1])

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
ans = A[0]
ansmax = 0
for skip in range(N):
    if skip == 0:
        start = 2
        ans = A[1]
    else:
        start = 1
        ans = A[0]
    for i in range(start, N):
        if skip == i:
            continue
        ans = math.gcd(ans, A[i])
    if ansmax < ans:
        ansmax = ans
print(ansmax)