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:
#!/usr/bin/env python3
#C
import numpy as np
import math
import re
from functools import reduce

n = int(input())

a = input()
a = re.split(" ",a)
a = list(map(int,a))
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

m = 0
for i in range(n):
    s = []
    for j in range(n):
        if j != i:
            s.append(a[j])
    x = gcd_list(s)
    if(x > m):
        m = x
print(m)

Submission status: Runtime Error

Solution code:
import fraction
n = int(input())
a = list(map(int, input().split(" ")))
x = []
for i in range(n):
    for j in range(i+1, n):
        x.append(fraction.gcd(a[i], a[j]))
print(max(x))

Submission status: Runtime Error

Solution code:
from copy import copy
import numpy as np

N = int(input())
Alist = list(map(int,input().split()))
a_list = []
for i in range(N):
    A_copy = copy(Alist)
    A_copy.pop(i)
    a_list.append(np.gcd.reduce(A_copy))

print(max(a_list))

Submission status: Runtime Error

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

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

ans = 1
for i in range(n):
    b = a[:i] + a[i + 1:]
    ans = max(ans, gcd_list(b))

print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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


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

ans = 1
for i in range(1, A[1]+1):
    if len(list(filter(lambda x: x % i != 0, A))) <= 1:
        ans *= i
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import copy

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

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

Atmp = copy.deepcopy(A)

max = 0
for i in range(N):
    Atmp = copy.deepcopy(A)
    Atmp.pop(i)
    g = gcd_list(Atmp)
    if max < g:
        max = g
print(max)

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()))
tempA = []
maxynum = 0

for i in range(N):
    tempA.extend(A[0:i])
    tempA.extend(A[i+1:])
    ynum = gcd_list(tempA)
    if ynum > maxynum:
        maxynum = ynum
    tempA.clear()

print(maxynum)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

N = int(input())
A = list(map(int, input().split(' ')))
count = 0
tmp = 0
for i in range(len(A)):
    A_list = A.copy()
    A_list.pop(i)
    result = reduce(math.gcd, A_list)
    if result > count:
        count = result
        tmp = i
print(count)

Submission status: Runtime Error

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

A.sort()
all_d = A[0]
max_d = max(divi(A[0],A[1]), divi(A[0],A[2])) if N > 2 else A[1]
for i in range(1,N):
    all_d = divi(all_d, A[i])
    if max_d < all_d:
        max_d = all_d
print(max_d)

Submission status: Runtime Error

Solution code:
import functools
import math

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

gcda = 0
for i in range(N):
    list2 = list1.copy()
    del list2[i]
    gcd = functools.reduce(math.gcd, list2)
    if gcd > gcda:
        gcda = gcd

print(gcda)

Submission status: Runtime Error

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

N = int(input())
A = [int(i) for i in input().split()]
G = []
for i in range(N):
    b = A.pop(0)
    G.append(gcd_list(A))
    A.append(b)
G.sort()
G[-1]

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce

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

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

C = []
for i in range(N):
    B = copy.copy(A)
    del B[i]
    C.append(gcd_list(B))
    
print(max(C))

Submission status: Runtime Error

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

import math
from functools import reduce

num = 0

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

if len(a) == 1:
    print(a[0])
else:
    for i in range(len(a)):
        num = max(num, gcd(a[:i] + a[i+1:]))

    print(num)

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 N:
	l=A
	l.pop(i)
	g_num=(gcd_list(l))
	if(g_num > ans):
		ans=g_num

print(ans)

Submission status: Runtime Error

Solution code:
import copy
import math
from functools import reduce

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

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

for i in range(n):
    tmp = copy.copy(a)
    del tmp[i]
    tmp_rtn = gcd_list(tmp)
    if tmp_rtn > rtn:
        rtn = tmp_rtn

print(rtn)

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()))
gcds = []
for i in range(n):
	b = []
	for k in range(n):
		if (i != k):
			b.append(a[k])
	gcds.append(gcd_list(b))
 
print (max(gcds))

Submission status: Runtime Error

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

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

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


a = sorted(a)

b = []
c = []

for value in a:
    if value % 2 != 0:
        b.append(value)
    else:
        c.append(value)

if len(b) == 0:
    a.remove(c[0])
    print(gcd_list(a))
else:
    a.remove(b[0])
    print(gcd_list(a))

Submission status: Runtime Error

Solution code:
"""
問題文

N個の整数 A1,A2,...,ANが黒板に書かれています。
あなたはこの中から整数を 1つ選んで、1 以上 109以下の好きな整数に書き換えます。
元の整数と同じ整数に書き換えても構いません。書き換えた後のN個の整数の最大公約数の最大値を求めてください。

制約
入力は全て整数である。
2≤N≤105
1≤Ai≤109
"""

"""
3 5 7
最大公約数: 1
最大の最大公約数: 1

8 4 6
最大公約数: 2
最大の最大公約数: 4
『aとbとcの最大公約数』　＝　『aとbの最大公約数』と『c』　の最大公約数
"""
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)

def main() : 
    N = int(input())
    a_list = input().split(" ")
    a_list = [int(i) for i in a_list]
    maxValue = 0
    for i in range(N) : 
        if i == 0 : sub_a_list = a_list[1:]
        elif i == N - 1 : sub_a_list = a_list[:N-1]
        else : sub_a_list = a_list[0 : i ] + a_list[i + 1 :] 
        rst = gcd(*sub_a_list)
        if maxValue < rst : maxValue = rst
    print(maxValue)
main()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from random import randint
import time

n = int(input())

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


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


gcd_l = [0]
gcd_r = []
for i in range(1,n+1):
    a_l = a[:i-1]
    a_r = a[i:]
    if a_l:
        gcd_l.append(gcd_list(a_l))
    if a_r:
        gcd_r.append(gcd_list(a_r))
gcd_r = gcd_r + [0]

ans = 0
for i in range(n):
    if gcd_l[i] == 0:
        gcd = gcd_r[i]
    if gcd_r[i] == 0:
        gcd = gcd_l[i]
    else:
        gcd = math.gcd(gcd_l[i],gcd_r[i])
    ans = max(gcd,ans)

print(ans)

Submission status: Runtime Error

Solution code:
import collections

def cal_divs(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
  
N = int(input())
A= list(map(int, input().split()))

divs = []
for i in range(N):
  divs.extend(cal_divs(A[i]))
  
c = collections.Counter(divs)

kouho = []
for div, n in c.most_common():
  if div == 1:
    pass
  elif n > N-2:
  	kouho.append(div)
  else:
    break

print(max(kouho))

Submission status: Runtime Error

Solution code:
#
import sys
import math
import numpy as np
import itertools


# ひとつ入力
n = int(input())
# リストに入れる
a = [int(i) for i in input().split()] 

hidari = [0]*n
migi   = [0]*n
hidari[0] = a[0]
for i in range(1,n):
    hidari[i]=math.gcd(hidari[i-1],a[i])
migi[n-1] = a[n-1]
for i in range(n-2,-1,-1):
    migi[i]=math.gcd(migi[i+1],a[i])

saidai=max(migi[1],hidari[n-2])
for i in range(1,n-1):
    saidai = max(saidai, math.gcd(hidari[i-1],migi[i+1]))
#    print(math.gcd(hidari[i-1],migi[i+1]))
#print(hidari,migi)
print(saidai)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int, input().split()))
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
max_gcd = 0
for i in range(len(a)):
    b = a.copy()
    b.pop(i)
    if gcd_list(b) > max_gcd:
        max_gcd = gcd_list(b)
print(max_gcd)

Submission status: Runtime Error

Solution code:
import math

n = int(input())

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

ans = 0;
for i in range(n):
    flag = False
    j = 0
    if(i==0):
        tmp = a[1]
    else:
        tmp = a[0]
    while(not(flag) and j!=n):
        if(j!=i):
            tmp = math.gcd(tmp, a[j])
        if(tmp==1):
            flag = True
        j += 1
    if(tmp>ans):
        ans = tmp
print(ans)

Submission status: Runtime Error

Solution code:
import functools, math


N = int(input())
A = list(map(int, input().split()))
gcd_ans = []
for i in range(N):
    A_sub = (A[0:i]+A[i+1:N]).copy()
    gcd = functools.reduce(math.gcd, A_sub)
    gcd_ans.append(gcd)
print(max(gcd_ans))

Submission status: Runtime Error

Solution code:
import math

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


if N == 2:
    print(max(A[0], A[1]))
else:
    a = math.gcd(A[0], A[1])
    b = math.gcd(A[0], A[2])
    c = math.gcd(A[1], A[2])
    if a == b and b == c:
        print(a)
    elif a == b:
        print(c)
    elif b == c:
        print(a)
    else:
        print(b)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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


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:
import math
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
def gcd(*numbers):
	return reduce(math.gcd, numbers)

ans = 0

for i in range(N):
	A0 = A[:i] + A[i+1:]
	gcd0 = gcd(*A0)
	if gcd0 > ans:
		ans = gcd0
print(ans)

Submission status: Runtime Error

Solution code:

n = int(input())

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


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


def gcd_list(li):
    g = gcd(li[0], li[1])
    for i in range(2, n):
        g = gcd(g, a[i])
    return g


g = gcd_list(a)
a = [a[i]//g for i in range(n)]


m = 1
for i in range(n):
    b = a[:]
    del b[i]
    gg = gcd_list(b)
    m = max(m, gg)


print(g * m)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

ans = 0
if n == 2:
    ans = max(aList)
else:
    for i in range(0,n-1):
        tmp = aList.pop(0)
        r = gcd(aList)
        if ans < r:
            ans = r
        aList.append(tmp)

print(ans)

Submission status: Runtime Error

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

def main():
    n = int(input())
    a = [int(a) for a in input().split()]

    maxv = 0
    for nn in range(n):
        gcdv = gcd_list(a[:nn]+a[nn+1:])
        if gcdv > maxv:
            maxv = gcdv
    print(maxv)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
from itertools import combinations
from functools import reduce

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


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

ans = 0

for A_product in combinations(A_list, N-1):
    if gcd(list(A_product)) > ans:
        ans = gcd(A_product)

print(ans)

Submission status: Runtime Error

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

n = int(input())
max_ = 0
lists = list(map(int,input().split()))

for i in range(len(lists)):
    cp = copy.copy(lists)
    cp.pop(i)
    n = len(cp)
    if n==1:
        element = cp[0]
    else:
        element = gcd(cp[0], cp[1])
        for i in range(2,n):
            element=gcd(element,cp[i])
    k = element
    if k>= max_:
        max_ = k
print(max_)

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce

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

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

max=0
for i in range(N):
    x = copy.deepcopy(A)
    del x[i]
    c = gcd_list(x)
    if c >= max:
        max = c
print(max)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int, input().split(" ")))
x = []
for i in range(n):
    for j in range(i+1, n):
        x.append(math.gcd(a[i], a[j]))
print(max(x))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
n=int(input())
a=list(map(int,input().spiit()))
def gcd(*numbers):
  return reduce(math.gcd,numbers)
A=gcd(a)
for i in range(n):
  del(a[i])
  B=gcd(a)
  if A<B:
    A=B
  else:
    A=A
print(A)

Submission status: Runtime Error

Solution code:
from math import gcd

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

if n == 1:
    ans = 1000000000
elif n == 2:
    ans = max(a)
else:
    l = [a[0]]
    for i in range(1, n):
        l.append(gcd(l[-1], a[i]))
    r = [a[-1]]
    for i in range(n - 1, -1, -1):
        r.append(gcd(r[-1], a[i]))
    r = list(reversed(r))
    ans = max(l[-2], r[1])
    for i in range(1, n - 1):
        ans = max(ans, gcd(l[i - 1], r[i + 1]))
print(ans)

Submission status: Runtime Error

Solution code:
import math
def gcd(numbers):
    # print(numbers)
    g=numbers[0]
    for i in range(n-1):
        g=math.gcd(g,numbers[i])
    return g

n=int(input())
a=list(map(int,input().split()))
gcd_without_i=[gcd(a[:i]+a[i+1:]) for i in range(n)]
# print(gcd_without_i)
print(max(gcd_without_i))

Submission status: Runtime Error

Solution code:
import math

def gcd_list(arr):

    ans = arr[0]
    for c in arr[1::]:
        ans = math.gcd(ans , c)
    return ans

N = int(input())

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

g = gcd_list(A)

for i in range(N):
    tmp = A.pop(0)
    if g < gcd_list(A):
        g = gcd_list(A)
    A.append(tmp)

print(g)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

ans = 0
valid = []

for i in range(N):
  valid = A[:]
  valid.pop(i-1)
  valid_number = reduce(math.gcd,valid)
  ans = max(ans,valid_number)

print(ans)

Submission status: Runtime Error

Solution code:
import math
import  functools

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

N = int(input())
A = [int(x) for x in input().split()]
a2 = A.copy()
max = 0
for i,_ in enumerate(A):
    A.pop(i)
    temp = gcd(A)
    max = temp if temp >= max else max
    A = a2.copy()


print(max)

Submission status: Runtime Error

Solution code:
import fractions
import numpy as np

n = int(input())
a = list(map(int, input().split()))
A = np.array(a)
ans = A[0]
c = []

for i in range(n):
    
    ind = np.ones(n, dtype=bool)
    ind[i] = False
    Ai = A[ind]
    ans = Ai[0]
    for j in range(1, n-1):
        c.append(fractions.gcd(ans, Ai[j]))

print(max(c))

Submission status: Runtime Error

Solution code:
import functools
import math

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

num = 1

for i in range(N):
    B = A[:]
    B.pop(i)

    gcd = functools.reduce(math.gcd, B)
    if num < gcd:
        num = gcd

print(num)

Submission status: Runtime Error

Solution code:
from functools import reduce
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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


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

ans = max(reduce(gcd, A[2:], A[0]), reduce(gcd, A[1:]))
print(ans)

Submission status: Runtime Error

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

if N == 2:
    print(max(A))
    exit()

maxa = max(A)
import fractions
d = []
for i in range(N):
    d.append(fractions.gcd(maxa , A[i]))
d = list(set(d))
d = sorted(d)
print(d[1])

Submission status: Runtime Error

Solution code:
import math

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

def GCD(numbers):
    x = numbers[0]
    for i in range(1,len(numbers)):
        x = math.gcd(x,numbers[i])
    
    return x

out = 0
for i in range(len(A)):
    l = A[:i] + A[i+1:]
    this_gcd = GCD(l)
    if this_gcd > out:
        out = this_gcd
        
print(out)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

N=int(input())
a_list = list(map(int, input().split()))
lst = []
for i, a in enumerate(a_list):
    tmp = a_list[:i] + a_list[i+1:]
    lst.append(reduce(math.gcd, tmp))
print(max(lst))

Submission status: Runtime Error

Solution code:
from heapq import heappush,heappop
import queue
import re
import math
import functools

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in range(n)]

def make2d_arr(h,w,val =INF):
    return [[val for i in range(w)]for i in range(h)]


N = int_raw()
A = ints_raw()


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

Submission status: Runtime Error

Solution code:
import math

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

a.sort()

if n == 2:
    print(a[1])
else:
    gcd1 = math.gcd(a[0],a[1])
    gcd2 = math.gcd(a[1],a[2])
    gcd3 = math.gcd(a[0],a[2])

    if gcd1 >= gcd2 and gcd1 >= gcd3:
        print(gcd1)
    elif gcd2 >= gcd1 and gcd2 >= gcd3:
        print(gcd2)
    else:
        print(gcd3)

Submission status: Runtime Error

Solution code:
from functools import reduce
from math import gcd

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

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

ans = -1

for i in range(N-1):
    g = gcd_list(A[:i] + A[i+1:])
    if g > ans:
        ans = g

g = gcd_list(A[:N-1])
if g > ans:
    ans = g

print(ans)

Submission status: Runtime Error

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

import functools
import math
num = 1

for i in range(N):
    B = A[:]
    B.pop(i)

    gcd = functools.reduce(math.gcd, B)
    if num < gcd:
        num = gcd

print(num)

Submission status: Runtime Error

Solution code:
N=int(input())
a_list = list(map(int, input().split()))
lst = []
for i, a in enumerate(a_list):
    tmp = a_list[:i] + a_list[i+1:]
    lst.append(reduce(math.gcd, tmp))
print(max(lst))

Submission status: Runtime Error

Solution code:
import fraction
# import math
from functools import reduce

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

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


a = sorted(a)

b = []
c = []

for value in a:
    if value % 2 != 0:
        b.append(value)
    else:
        c.append(value)

if len(b) == 0:
    a.remove(c[0])
    print(gcd_list(a))
else:
    a.remove(b[0])
    print(gcd_list(a))

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()))

print(gcd_list(A))

Submission status: Runtime Error

Solution code:
import functools
import math

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

def gcd_all(list):
    return gcd_all([math.gcd(*list[:2])] + list[2:]) if len(list) > 1 else list[0]


gcd = 0
for i in range(0, N):
    gcd_part = gcd_all(A[:i]+A[i+1:])
    if gcd < gcd_part:
        gcd = gcd_part
    
print(gcd)

Submission status: Runtime Error

Solution code:
import math
import copy
def gcds(lists):
  return reduce(math.gcd, lists)

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

for i in range(n):
  b = copy.copy(a)
  b.pop(i)
  r = max(gcds(b),r)

print(r)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int, input().split()))
import math
x=math.gcd(max(a), min(a))
a.remove(max(a))
y=math.gcd(max(a), min(a))
print(max(x, y))

Submission status: Runtime Error

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

nums = A[:]
#print(nums)
import math

def cal_gcd(sub_nums):
    gcd_tmp = sub_nums[0]
    for i, v in enumerate(sub_nums):
        if i == 0:
            continue
        gcd_tmp = math.gcd(v, gcd_tmp)
        #print(gcd_tmp)
    return gcd_tmp

ans = 1
import itertools
for v in itertools.combinations(nums, len(nums) - 1):
    #print(v)
    gcd_tmp = cal_gcd(v)
    #print(gcd_tmp)
    ans = max(ans, gcd_tmp)
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import math

N = int(input()) 
a = list(int(_) for _ in input().split()) 

ma = list(itertools.combinations(a,N-1))
mal = [math.gcd(*ma[i]) for i in range(N)]
print((max(mal)))

Submission status: Runtime Error

Solution code:
from functools import reduce
from math import gcd

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

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

ans = -1

for i in range(N):
    g = gcd_list(A[:i] + A[i+1:])
    if g > ans:
        ans = g

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

N = int(input())
As = [int(i) for i in input().split()]
As = np.array(As, dtype=int)

def recursive_gcd(nums):
  if len(nums) == 1:
    return nums[0]
  
  if len(nums) == 2:
    return math.gcd(nums[0], nums[1])
  
  topgcd = math.gcd(nums[0], nums[1])
  
  return recursive_gcd([topgcd] + nums[2:])

maxgcd = -1
for i in range(len(As)):
  mask = np.ones(len(As), dtype=bool)
  mask[i] = False
  newAs = As[mask]
  
  maxgcd = max(maxgcd, recursive_gcd(newAs))
  
print(maxgcd)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import functools
import math

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

def f(a,ans):
     ans = max(functools.reduce(math.gcd, a),ans)
     return ans
     
for i in range(n):
     ans = f(a[:i]+a[i+1:],ans)
print(ans)

Submission status: Runtime Error

Solution code:
import functools
import math

N = int(input())

A = list(map(int, input().split()))
max_A = max(A)
gcd_list = []
for i in range(N):
    tmp = A[i]
    A[i] = max_A
    gcd = functools.reduce(math.gcd, A)
    gcd_list.append(gcd)
    A[i] = tmp

print(max(gcd_list))
# 最大の値と変えてもいい

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import numpy as np

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

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

ans = 0
for i in range(N) :
    B = A[np.arange(len(A))!=i]
    g = gcd(*B)
    if g > ans :
        ans = g
print(ans)

Submission status: Runtime Error

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

import math
from functools import reduce

b = []

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

if len(a) == 1:
    print(a[0])
else:
    for i in range(len(a)):
        b.append(gcd(a[:i] + a[i+1:]))

    b.sort()
    print(b[-1])

Submission status: Runtime Error

Solution code:
import functools
import fraction

N = int(input())
a = list(map(int,input().split()))
ans = 1
for i in range(N):
	a_new = a[0:i]+a[i+1:N]
	gcd = functools.reduce(math.gcd,a_new)
	ans = max(ans,gcd)

print(ans)

Submission status: Runtime Error

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

import math
from functools import reduce

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

dp=[]
for i in range(n):
    aa=list(a)
    del aa[i]
    dp.append(gcd(*aa))

print(max(dp))

Submission status: Runtime Error

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

this_gcd = max(a)
gcd_list = []

for i in a:
    this_gcd = fractions.gcd(this_gcd, i)

for I in range(len(a)):
    i = a[I]
    tmp = i // this_gcd
    key = 1
    for j in range(2, int(fractions.sqrt(tmp)) + 1):
        if tmp % j == 0:
            key = 0

    if key:
        del a[I]
        break

this_gcd = max(a)
for i in a:
    this_gcd = fractions.gcd(this_gcd, i)

print(this_gcd)

Submission status: Runtime Error

Solution code:
n = int(input())

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

from fractions import gcd
from functools import reduce


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


g = gcd(a)
a = [a[i]//g for i in range(n)]


m = 1
for i in range(n):
    b = a[:]
    del b[i]
    gg = gcd(b)
    m = max(m, gg)


print(g * m)

Submission status: Runtime Error

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


maxa = max(A)
import fractions
d = []
for i in range(N):
    if A[i] != maxa:
        d.append(fractions.gcd(maxa , A[i]))
d = list(set(d))
if len(d) == 0:
    print(A[0])
    exit()
d = sorted(d)
print(d[1])

Submission status: Runtime Error

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

def lcm(a, b):
    return a*b//gcd(a,b)

n = int(input())
an = [int(i) for i in input().split(" ")]
an = sorted(list(set(an)))
if len(an) <= 1:
    print(max(an))
else:
    sample = []
    for a1 in an:
        for a2 in an:
            tmo = gcd(a1, a2)
            if a1 == a2 or tmo in sample:
                continue
            sample.append(gcd(a1, a2))

    sample = sorted(sample)
    print(sample[1])

Submission status: Runtime Error

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

N = int(input())
Alist = list(map(int,input().split()))
a_list = []
for i in range(N):
    A_copy = copy(Alist)
    A_copy.pop(i)
    a_list.append(gcd_list(A_copy))

print(max(a_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(map(int,input().split()))
gcds = []
for i in range(n):
	b = []
	for k in range(n):
		if (i != k):
			b.append(a[k])
	gcds.append(gcd_list(b))

print (max(gcds))

Submission status: Runtime Error

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

import math
from functools import reduce

b = []

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

for i in range(len(a)):
    b.append(gcd(a[:i] + a[i+1:]))

b.sort()
print(b[-1])

Submission status: Runtime Error

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

this_gcd = max(a)
gcd_list = []

for i in a:
    this_gcd = math.gcd(this_gcd, i)

for I in range(len(a)):
    i = a[I]
    tmp = i // this_gcd
    key = 1
    for j in range(2, int(math.sqrt(tmp)) + 1):
        if tmp % j == 0:
            key = 0

    if key:
        del a[I]
        break

this_gcd = max(a)
for i in a:
    this_gcd = math.gcd(this_gcd, i)

print(this_gcd)

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 = 1

for i in range(n):
	aa = a.copy()
	aa.pop(i)
	temp = gcd_list(aa)
	if(temp > ans):
		ans = temp

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

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

from fraction import gcd
from functools import reduce


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


g = gcd(a)
a = [a[i]//g for i in range(n)]


m = 1
for i in range(n):
    b = a[:]
    del b[i]
    gg = gcd(b)
    m = max(m, gg)


print(g * m)

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()))
gcd_without_i=[gcd(a[:i]+a[i+1:]) for i in range(n)]

print(max(gcd_without_i))

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_lst = [int(elem) for elem in input().split()]

res_lst = []
for i, a in enumerate(a_lst):
    new_lst = list(a_lst)
    new_lst.pop(i)
    res = gcd_list(new_lst)
    res_lst.append(res)
print(max(res_lst))

Submission status: Runtime Error

Solution code:
import functools
import math

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

gcd = 0
for i in range(0, N):
    gcd_part = functools.reduce(math.gcd, A[:i]+A[i+1:])
    if gcd < gcd_part:
        gcd = gcd_part
    
print(gcd)

Submission status: Runtime Error

Solution code:
import copy
import functools
import math

n=int(input())
lstA=list(map(int,input().split()))
maximum=max(lstA)
gcdlst=[]

for i in range(n):
    cplstA=copy.copy(lstA)
    del cplstA[i]
    gcdlst.append(functools.reduce(math.gcd, cplstA))

print(max(gcdlst))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

import math
from functools import reduce


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


def resolv(nums, cnt):
    result = []
    for i in range(cnt):
        result.append(gcd(nums[0:i] + nums[i+1:cnt]))
    return result


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

print(max(resolv(A, N)))

Submission status: Runtime Error

Solution code:
import fractions
import functools
def gcd_list(numbers):
    return functools.reduce(fractions._gcd, numbers)
n = int(input())
a = list(map(int,input().split()))
m = 1
for i in range(n):
    b = a[:i] + a[i+1:]
    x = gcd_list(b)
    if x > m:
        m = x
print(m)