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

sw = 0
for i in range(N):
    w = A[0 if i != 0 else 1]
    for j in range(N):
        if j != i:
            w = math.gcd(w, A[j])
    sw = max(sw, w)

print(sw)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import copy
import math
from functools import reduce


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


n = input()
a = list(map(int, input().split()))
a.sort()
b = []
c = 0
for i in range(len(a)):
    b = copy.copy(a)
    b[i] = max(a)
    t = gcd(*b)
    if c < t:
        c = t

print(c)

Submission status: Runtime Error

Solution code:
import sys

n = int(input())
li = list(map(int,input().split()))
li.sort()
ans = int(li[n - 1] - li[0])
if (li[0] == li[n - 1]):
    print(li[0])
    sys.exit()
if(((li[n - 1] % ans) == 0) and ((li[0] % ans) == 0)):
    print(ans)
    sys.exit()
else:
    if((li[1] % (li[n - 1] - li[1])) == 0):
        print(int(li[n - 1] - li[1]))
        sys.exit()
    else:
        print((li[n - 2] -li[0]))

Submission status: Runtime Error

Solution code:
import functools
import math

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

for i in range(N):
    B = A.copy()
    del B[i]
    gcd[i] = functools.reduce(math.gcd, B)

print(max(gcd))

Submission status: Runtime Error

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


def get(base, others):
    lists = filter(lambda x: x > 1, [gcd(base, i) for i in others])
    if not lists:
        return None
    elif len(lists) == 1:
        return lists[0]
    return sorted(lists)[1]


raw_input()
al = [int(i) for i in raw_input().split()]

a = get(al[0], al[1:])
b = get(al[1], [al[0]] + al[2:])
if len(al) >= 3:
    c = get(al[2], [al[0], al[1]] + al[3:])
else:
    c = None

print(max(*[i for i in [a, b, c] if i]))

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(int,input().split()))
import math
if n > 2:
    a = math.gcd(s[0],s[1])
    b = math.gcd(s[1],s[2])
    c = math.gcd(s[2],s[0])

    large = max(a,b,c)
    small = min(a,b,c)
    p = large
    q = []
    if n == 3:
        print(large)
    else:
        for i in range(n-3):
            p = math.gcd(p,s[i+3])
            q.append(math.gcd(small,s[i+3]))
        q.sort()
        print(max(p,q[1]))
else:
    print(max(s))

Submission status: Runtime Error

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

n=int(input())
v=[int(x) for x in input().split()]
k=0
for i in range(n):
    d=v[i]
    v[i]=0
    l=gcd_list(v)
    if l>int(k):
        k=l
    v[i]=d
print(int(k))

Submission status: Runtime Error

Solution code:
n = input()
A = input().split(" ")

n = int(n)
A_tmp = []
for a in A:
    A_tmp.append(int(a))
A = A_tmp

def euclid(a, b):
    if b == 0:
        return(a)
    
    if a > b:
        return euclid(b, a%b)
    else:
        return euclid(a, b%a)

if n == 2:
    if A[0] > A[1]:
        print(A[0])
    else:
        print(A[1])
else:
biggest = 0
    for i in range(n):
        print("else" + str(i))
        index = []
        for j in range(n):
            if i == j:
                pass
            else:
                index.append(j)

        tmp = euclid(A[index[0]], A[index[1]])
        print(tmp)
        for j in range(n-1):
            tmp = euclid(tmp ,A[index[j]])
        print(tmp)

        if tmp > biggest:
            biggest = tmp
    print(biggest)

Submission status: Runtime Error

Solution code:
import math
N=int(input())
A=list(map(int,input().split()))
t=0
ans=[0]*N
while t<N:
    u=0
    if t!=0:
        ans[t]=A[0]
        while u<N-1:
            if u+1!=t:
                ans[t]=math.gcd(ans[t],A[u+1])
            u=u+1
    else:
        ans[t]=A[1]
        y=1
        while y<N-1:
            ans[t]=math.gcd(ans[t],A[y+1])
            y=y+1
    t=t+1
print(max(ans))

Submission status: Runtime Error

Solution code:
import math as m
n,a=int(input()),list(map(int,input().split()))
b,c=[],[]
for i in range(n):
	b.append(m.gcd(b[i-1],a[i-1]) if i else 0)
	c.append(m.gcd(c[i-1],a[n-i]) if i else 0)
print(max([m.gcd(b[i],c[n-i-1]) for i in range(n)]))

Submission status: Runtime Error

Solution code:
import math

def get_gcd(x,n):
    if n==1:
        print(x[0])
    else:
        element = math.gcd(x[0], x[1])
        if n==2:
            return element
        else:
            for i in range(2,n):
                element = math.gcd(element,x[i])
            return element

n = int(input())
a = [int(i) for i in input().split()]
interim_max = 0
for i in range(n):
    max_gcd = get_gcd(a[:i]+a[i+1:], n-1)
    if interim_max < max_gcd:
        interim_max = max_gcd
print(interim_max)

Submission status: Runtime Error

Solution code:
import functools

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

for i in range(N):
    B = A.copy()
    del B[i]
    gcd[i] = functools.reduce(functools.gcd, B)

print(max(gcd))

Submission status: Runtime Error

Solution code:

n = int(input())

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


from functools import lru_cache
import sys
if n == 2:
    print(max(a))
    sys.exit()


@lru_cache(maxsize=100000)
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


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


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

    m = gcd_list_2(a)
    print(g * m)


max_gcd(a)

Submission status: Runtime Error

Solution code:
import sympy as sp
import copy

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

def calc_gcd(list):
    ans = list[0]
    for i in range(1,n-1):
        ans = sp.gcd(ans,list[i])
    return ans

#a = [1,2,3,4,5,6,7]

for j in range(n):
    b= copy.copy(a)
    b.pop(j)
    nlist.append(calc_gcd(b))

#print(nlist)
print(max(nlist))

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=[]
B.append(A[0])
for i in range(N-1):
    B.append(A[i+1]-A[i])

B.sort()
B[1]+=B[0]
B[0]=B[1]
Ans=B[0]

for i in range(N):
    a=max(Ans,B[i])
    b=min(Ans,B[i])
    r=a%b
    while r>0:
        a=b
        b=r
        r=a%b
    Ans=b
print(Ans)

Submission status: Runtime Error

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

min=10000000000000000000
min2=0
cnt=0
for i in range(N):
    if A[N-i-1] < min:
        cnt+=1
        min=A[N-i-1]
    if cnt == N-1:
        min2=min

cnt=0
for i in range(N):
    if A[i] % min == 0:
        cnt+=1
if cnt == len(A) or cnt == len(A)-1:
    quit()

a = min2
for i in range(min):
    cnt=0
    cnt2=0
    for i in range(N):
        if A[i] % a == 0:
            cnt+=1
        if cnt == len(A) or cnt == len(A)-1:
            print(a)
            quit()

    a -= 1

Submission status: Runtime Error

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

glist = []
for i in range(N):
    a = deepcopy(A)
    a.pop(i)
    g = a[0]
    for j in range(N-1):
        g = math.gcd(g, a[j])
        if g == 1:
            break
    glist.append(g)

print(max(glist))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
import copy

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

B = copy.copy(A)

gcd_array = []
for i in range(N):
    B.pop(i)
    C = copy.copy(B[1:])
    C.append(B[0])
    gcd = 100000000000000000000
    for b, c in zip(B, C):
        tmp = math.gcd(b, c)
        if tmp < gcd:
            gcd = tmp
    gcd_array.append(gcd)

    B = copy.copy(A)
print(max(gcd_array))

Submission status: Runtime Error

Solution code:
import numpy as np

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

num = 1

for i in range(np.max(A)):
  B = [m for m in A if m // (i + 1) != 0]
  if len(B) == 0 or len(B) == 1:
    num = (i + 1)
    
print(num)

Submission status: Runtime Error

Solution code:
import math

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

ans_list = []
for i in range(N):
    if N != 2:
        ans_list.append(math.gcd(*v_list[:i] + v_list[i+1:]))
    else:
        ans_list = v_list

print(max(ans_list))

Submission status: Runtime Error

Solution code:
import math

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

A.sort()
#print(math.gcd(6, 7))
if N >= 3:
    ans = max(math.gcd(A[0], A[1]), math.gcd(A[1], A[2]), math.gcd(A[0], A[2]))
elif N == 2:
    ans = max(A[0], A[1])
else:
    ans = 1000000000

print(ans)

Submission status: Runtime Error

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

n = int(input())
an = [int(i) for i in input().split(" ")]
an = sorted(list(set(an)))
if len(an) <= 2:
    print(max(an))
else:
    sample = []
    for i in range(len(an)):
        for j in range(i+1, len(an)):
            tmo = gcd(an[i], an[j])
            sample.append(gcd(an[i], an[j]))

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

Submission status: Runtime Error

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

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

ans = 1
if n == 2:
    print(max(a))
else:
    for i in range(n):
        b = a[:i] + a[i + 1:]
        element = gcd(b[0], b[1])
        if n == 3:
            ans = max(ans, element)
        else:
            for j in range(2, n - 1):
                element = gcd(element, b[i])
            ans = max(ans, element)
    print(ans)

Submission status: Runtime Error

Solution code:
# from math import gcd
import math
N = int(input())
A = list(map(int,input().split()))
# N=3
# A=[12 ,15 ,18]
l=[0]*N
r=[0]*N
l[0]=A[0]
r[0]=A[N-1]
for i in range(1,N-1):
    l[i]=math.gcd(l[i-1],A[i])
    r[i]=math.gcd(r[i-1],A[N-1-i])    
gcdlist = [l[N-2],r[N-2]]
for i in range(N-2):
    gcdlist.append(math.gcd(l[i],r[N-3-i]))
# print(gcdlist)
print(max(gcdlist))

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])
elif n == 3:
    gcd1 = math.gcd(a[0],a[1])
    gcd2 = math.gcd(a[1],a[2])
    gcd3 = math.gcd(a[0],a[2])
    ans = [gcd1, gcd2, gcd3]
    ans.sort()

    print(ans[-1])

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

    for i in range(3,n):
        if math.gcd(gcd1, a[i]) < gcd1:
            gcd1 = math.gcd(gcd1, a[i])

    for i in range(3,n):
        if math.gcd(gcd2, a[i]) < gcd2:
            gcd2 = math.gcd(gcd2, a[i])

    for i in range(3,n):
        if math.gcd(gcd3, a[i]) < gcd3:
            gcd3 = math.gcd(gcd3, a[i])

    ans = [gcd1, gcd2, gcd3]
    ans.sort()

    print(ans[-1])

Submission status: Runtime Error

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

def gcd(a,b):
    x = max(a, b)
    y = min(a, b)
    if x%y == 0:
        return y
    else:
        while x % y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z
    
def gcd_list(list):
    p = 1
    for i in range(len(list)-1):
        if i == 0:
            p = gcd(list[0], list[1])
        else:
            p = gcd(z,list[i+1]) 
    return p

if N == 2:
    print(gcd(A[0], A[1]))
else:
    for i in range(N):
        l = copy.copy(A)
        l.pop(i)
        ans = max(gcd_list(l), ans)
    print(ans)

Submission status: Runtime Error

Solution code:
import math
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())
a = list(map(int,input().split()))
gcds = []

maxt = 0
for i in range(n):
	b = []
	for k in range(n):
		if (i != k):
			b.append(a[k])
	tmp = b[0]

	for bi in b[1::]:
		tmp = math.gcd(tmp,bi)
		
	if maxt < tmp:
		maxt = tmp
 
print (maxt)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
counter = {}
max_count = 0


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


for i in range(n):
    for j in make_divisors(a[i]):
        counter[j] = counter[j] + 1 if j in counter else 1
        max_count = max(max_count, counter[j]) if j != 1 else 0

counter = {k: v for k, v in counter.items() if v == max_count}

print(max(counter))

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
c = 0
alim = min(a)
for i in range(1,alim+1):
    for j in range(0,N):
        #print(str(a[j]%i))
        if a[j]%i != 0:
            c += 1
    #print(c)
    if c == 1:
        o = i
    c = 0
print(o)

Submission status: Runtime Error

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

min=10000000000000000000
min2=0
cnt=0
for i in range(N):
    if A[N-i-1] < min:
        cnt+=1
        min=A[N-i-1]
    if cnt == N-1:
        min2=min

cnt=0
for i in range(N):
    if A[i] % min == 0:
        cnt+=1
if cnt == len(A) or cnt == len(A)-1:
    quit()

a = min2
print(a)
for i in range(min):
    cnt=0
    cnt2=0
    for i in range(N):
        if A[i] % a == 0:
            cnt+=1
        if cnt == len(A) or cnt == len(A)-1:
            print(a)
            quit()

    a -= 1

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

def get_gcd(alist):
    return reduce(math.gcd, alist)

max_gcd = 0
for i in range(N):
    A_=[]
    for j in range(N):
        if j != i:
            A_.append(A[j])
    gcd = get_gcd(A_)
    if max_gcd < gcd:
        max_gcd = gcd
print(max_gcd)

Submission status: Runtime Error

Solution code:
import math
import functools

max = 0
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    box = a.pop(0)
    A = functools.reduce(math.gcd, a)
    if A > max:
        max = A
    a.append(box)
print(max)

Submission status: Runtime Error

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

import math
from functools import reduce
import copy

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

b = []
for i in range(n):
    #a_tmp = []
    a_tmp = copy.copy(a)
    a_tmp.pop(i)
    b.append(gcd(*a_tmp))
b.sort(reverse=True)
print(b[0])

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)

gcds = [gcd_list(a[:i]+a[i+1:]) for i in range(n)]

print(max(gcds))

Submission status: Runtime Error

Solution code:
from math import gcd
N = int(input())
A = list(map(int,input().split()))
# N=3
# A=[12 ,15 ,18]
l=[0]*N
r=[0]*N
l[0]=A[0]
r[0]=A[N-1]
for i in range(1,N-1):
    l[i]=gcd(l[i-1],A[i])
    r[i]=gcd(r[i-1],A[N-1-i])    
gcdlist = [l[N-2],r[N-2]]
for i in range(N-2):
    gcdlist.append(gcd(l[i],r[N-3-i]))
# print(gcdlist)
print(max(gcdlist))

Submission status: Runtime Error

Solution code:
import functools
import fractions

N = int(input())
a_list = list(map(int, input().split()))
gcd_list = []
for i in range(N):
    copied = a_list
    copied.pop(i)
    gcd = functools.reduce(fractions.gcd, copied)
    gcd_list.append(gcd)

print(max(gcd_list))

Submission status: Runtime Error

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

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

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

gcds = []
for i in range(N):
    A_ = copy(A)
    A_.pop(i)
    gcds.append(gcd(*A_))

print(max(gcds))

Submission status: Runtime Error

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


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

if n==2:
	print(max(a))
	quit()

a = sorted(a)

gcds = []
for i in range(n-1):
	for j in range(1, n):
		cur = gcd(a[i], a[j])
		count = 0
		for k in range(n):
			if a[k]%cur != 0:
				count += 1
				if count>=2:
					break
		if count <= 1:
			gcds.append(cur)

gcds = list(set(gcds))
if len(gcds)==1:
	print(gcds[0])
else:
	gcds = sorted(gcds)
	print(gcds[1])

Submission status: Runtime Error

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

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

for i in range(1, 10**9):
  count = 0
  for j in range(len(a)):
    if a[j] % i != 0:
      count += 1
      index = j
  if count == 1:
    ans_list = []
    for m in range(len(a)):
      if m != index:
        ans_list.append(a[m])
    element = gcd(ans_list[0], ans_list[1])
    for i in range(2,len(ans_list)):
      element=gcd(element,ans_list[i])
    print(element)
    sys.exit()

Submission status: Runtime Error

Solution code:
import math

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

max_gcd = 0
for i in range(N-1):
  for j in range(i+1, N):
    tmp = math.gcd(int(A[i]), int(A[j]))
    if max_gcd < tmp:
      max_gcd = tmp

print(max_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(" ")))
res = []
for i in range(n):
    tmp = a[:]
    del tmp[i]
    res.append(gcd_list(tmp))

print(max(res))

Submission status: Runtime Error

Solution code:
import math
import  _functools

max = 0
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    box = a.pop(0)
    A = functools.reduce(math.gcd, a)
    if A > max:
        max = A
    a.append(box)
print(max)

Submission status: Runtime Error

Solution code:
import math

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

print(math.gcd(max(A), min(A)))

Submission status: Runtime Error

Solution code:
import math

from functools import reduce

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

maxv = 0

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

for i in range(N):
    test = Value.copy()
    del test[i]
    if maxv <= gcd_list(test):
        maxv = gcd_list(test)
        
print(maxv)

Submission status: Runtime Error

Solution code:
import fractions
import functools

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

gcd = functools.reduce(fractions.gcd, a[1:])
for i in range(1,n):
  if a[i] % gcd == 0:
  	a_tmp = [j for j in a if j != a[i]]
  	gcd = max(gcd,functools.reduce(fractions.gcd, a_tmp))

print(gcd)

Submission status: Runtime Error

Solution code:
import sys
import os
import math
import itertools
import math
from functools import reduce

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

n = int(input())
nums = [int(i) for i in input().split()]
gcds = []
for num in nums:
    tmp = nums.copy()
    tmp.remove(num)
    gcds.append(gcd(*tmp))
print(max(gcds))

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().strip().split(' ')))

s = gcd_list(a)
a2 = []
for i in range(n):
  a2 = a[0:i]+a[i+1:n]
  l = gcd_list(a2)
  if s < l:
    s = l
print(s)

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()))
max=1
for i in range(n):
    q=gcd_list(a[:i]+a[i+1:])
    if q>max:
        max=q
print(max)

Submission status: Runtime Error

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


# ユークリッド互除法の関数の定義
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


max_A = max(A)
gcd_list = []
if N == 1:
    print(A[0])
else:
    element = gcd(A[0], A[1])
    if N == 2:
        print(element)
        exit()
    else:
        for i in range(N):
            tmp = A[i]
            A[i] = max_A
            for j in range(2, N):
                element = gcd(element, A[i])
            gcd_list.append(element)
            A[i] = tmp
print(max(gcd_list))
# 最大の値と変えてもいい

Submission status: Runtime Error

Solution code:
from functools import reduce
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
memo={}
def _gcd(a, b):
    key = tuple(sorted(a, b))
    if key in memo:
        return memo[key]
    x = gcd(a, b)
    memo[key] = x
    return x
print(max(reduce(_gcd, (a[i] for i in range(n) if i != j)) for j in range(n)))

Submission status: Runtime Error

Solution code:
import math
N=int(input())
A=list(map(int,input().strip().split(' ')))
if N==1:
    print(A[0])
else:    




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

    GG2=[0]*N
    GG2[-1]=A[-1]

    for i in range(2,N+1):
        GG2[-i]=math.gcd(GG2[-(i-1)],A[-i])

    ans=[0]*N

    ans[0]=GG2[1]
    ans[-1]=GG[N-1]
    #print(GG)
    #print(GG2)

    for i in range(1,N-1):
        ans[i]=math.gcd(GG[i-1],GG2[i+1])
    #print(ans)  
    print(max(ans))

Submission status: Runtime Error

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

def hcfnaive(a,b): 
  if(b==0): 
    return a 
  else: 
    return hcfnaive(b,a%b) 
      
def gcd(numbers):
  if len(numbers)==2:
    return hcfnaive(numbers[0],numbers[1])
  elif len(numbers)==1:
    return numbers[0]
  else:
    numbers[0]=hcfnaive(numbers[0],numbers[1])
    numbers.pop(1)
  return gcd(numbers)

ans=0
for i in range(n):
  num2=copy.copy(num)
  num2.pop(i)
  a=gcd(num2)
  if a>ans:
    ans=a
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(int,input().split()))
import math
if n > 2:
    a = math.gcd(s[0],s[1])
    b = math.gcd(s[1],s[2])
    c = math.gcd(s[2],s[0])

    s1 = max(a,b,c)
    t1 = min(a,b,c)
    p = s1
    q = []
    if n == 3:
        print(s1)
    else:
        for i in range(n-3):
            p = math.gcd(p,s[i+3])
            q.append(math.gcd(t1,s[i+3]))
        q.sort()
        print(max(p,q[1]))
else:
    print(max(s))

Submission status: Runtime Error

Solution code:
N = int(input())
A=list(map(int,input().split()))
tmp=[]
if N<10:
  ans=[]
  def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
  for i in range(N):
    tmp=copy.copy(A)
    tmp.pop(i)
    ans.append(gcd_list(tmp))
  print(max(ans))
else:
  for i in range(N-1):
    tmp.append(fractions.gcd(A[0],A[i+1]))
    tmp.append(fractions.gcd(A[1],A[i+2]))
  print(mode(tmp))

Submission status: Runtime Error

Solution code:
import functools
import math
n = int(input())
a = list(map(int,input().split()))
gcd = []
for N in range(n):
    b = a.copy()
    b.remove(b[N])
    gcd.append(functools.reduce(math.gcd, b))
print(max(gcd))

Submission status: Runtime Error

Solution code:
import copy
import fractions


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    gcd_list = []
    if n == 1:
        print(10**10 - 1)
    else:
        for i in range(len(a_list)):
            cp_list = copy.copy(a_list)
            del cp_list[i]
            gcd_tmp = cp_list.pop()
            gcd_list.append(multiple_gcd(gcd_tmp, cp_list))
        print(max(gcd_list))


def multiple_gcd(gcd, num_list):
    if len(num_list) == 0:
        return gcd
    return multiple_gcd(fractions.gcd(gcd, num_list.pop()), num_list)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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




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


print(max)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

def get_gcd(alist):
    return reduce(math.gcd, alist)
  
max_gcd = 0
for i in range(N):
    A_=[]
    for j in range(N):
        if j != i:
            A_.append(A[j])
    gcd = get_gcd(A_)
    if max_gcd < gcd:
        max_gcd = gcd
print(max_gcd)

Submission status: Runtime Error

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

ans = 0
if n==2:
    print(max(aa))
else:
    for i in range(n):
        temp_list = aa.copy()
        temp_list.pop(i)
        temp = temp_list[0]
        for j in range(n-1):
            temp = gcd(temp, temp_list[j])
        # print(aa[i], temp)
        ans = max(ans, temp)
    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):
    b=copy.copy(a)
    del b[i]
    gcd=functools.reduce(math.gcd,b)
    ans=max(ans,gcd)
print(ans)

Submission status: Runtime Error

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

nums = A[:]
import math

def cal_gcd(i, flag, ans):
    if i == len(nums):
        return ans
    ans_0 = -1
    if flag == False:
        ans_0 = cal_gcd(i+1, True, ans)
    
    if ans == 0:
        ans = nums[i]
    #print(i)
    ans = math.gcd(ans, nums[i])
    ans_1 = cal_gcd(i+1, flag, ans)
    return max(ans_0, ans_1)
    
ans = cal_gcd(0, False, 0)
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
N = int(input())
A = [int(x) for x in input().split()]

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

max_gcd = 1
for i in range(N):
    max_gcd = max(max_gcd, gcd(*(A[0:i] + A[i+1:])))

print(max_gcd)

Submission status: Runtime Error

Solution code:
import functools
import math
n=input()
n=int(n)
a=input().split()
a=[int(i) for i in a]
ncount=2
count=0
gll=list()
for i in range(n):
    s=a[i]
    del a[i]
    gcd = functools.reduce(math.gcd, a)
    gll.append(gcd)
    a.insert(i,s)
print(max(gll))

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int gcd(int a, int b){
    if(a < b){
        int tmp = a;
        a = b;
        b = tmp;
    }
    int r = a % b;
    if(r == 0)return b;
    return gcd(b, r);
}

int main(){
    int N;
    cin >> N;

    int A[N];
    for(int i = 0; i < N; i++)cin >> A[i];

    int ans = 1;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N-1; j++){
            if(j == i)continue;
            int g = gcd(A[j], A[j+1]);
            if(g > ans)ans = g;
        }
    }
    cout << ans;
    return 0;
}

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

if __name__ == '__main__':
    N = int(input())
    A_list = list(map(int, input().split()))

    answer = 0

    for i in range(0, len(A_list)-1):
        A_list_copy = A_list
        A_list_copy.pop(i)

        gcd_number = gcd_list(A_list_copy)

        if answer < gcd_number:
            answer = gcd_number

    print(answer)

Submission status: Runtime Error

Solution code:
import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

kouho = []
n = ni()
li = na()
flag = 0
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    kouho.append(fractions.gcd(li[0], li[1]))
    kouho.append(fractions.gcd(li[1], li[2]))
    kouho.append(fractions.gcd(li[2], li[0]))
    for i in range(3,n):
        if len(kouho) == 0:
            print(i)
            break
        for num in kouho:
            if li[i] % num != 0:
                kouho.remove(num)
    print(max(kouho))

Submission status: Runtime Error

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
b=a
c=[0]*n
ans=a[0]
for i in range(n):
    for j in range(n):
        if j==i:
            if j==0:
                ans=a[1]
        else:
            #print(j)
            ans=math.gcd(ans,a[j])
   # a[i]=b[i]
        c[i]=ans
    ans=a[0]
#print(c)
print(max(c))

Submission status: Runtime Error

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

import math
from functools import reduce
from copy import copy

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

gcds=[]
for i in range(N):
    A_=copy(A)
    A_=pop(i)
    gcds.append(gcd(*A_))

print(max(gcds))

Submission status: Runtime Error

Solution code:
import math

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

ans_list = []
for i in range(N):
    ans_list.append(math.gcd(*v_list[:i] + v_list[i+1:]))

print(max(ans_list))

Submission status: Runtime Error

Solution code:
# coding:utf-8
import math


def main():
    N = int(input())
    num = list(map(int, input().split()))
    # num.sort()
    # print(num)
    # print(num[0:0])
    gcd = 0
    for i in range(len(num)):
        temp_list = num[0:i]+num[i+1:]
        temp_gcd = temp_list[0]
        for i in temp_list:
            temp_gcd = math.gcd(temp_gcd, i)
        # temp_gcd = functools.reduce(math.gcd, temp_list)
        if temp_gcd > gcd:
            gcd = temp_gcd
    print(gcd)
    # ans = 0
    # print()


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

import math
import heapq
from functools import reduce

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

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

ms = []

for i in range(N):
	nl = As[0:i] + As[i+1:N]
	ms.append(gcd_list(nl))

m1,m2 = heapq.nsmallest(2,(list(set(ms))))

print(m2)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
Alist = list(map(int, input().split()))
def gcds(numbers):
    if len(numbers) == 2:
        return math.gcd(*numbers)
    else:
        n1 = math.gcd(numbers[0], numbers[1])
        return gcds(* [n1]+numbers[2:])
if len(Alist)>2:
    gcdlist = [gcds(Alist[:i]+Alist[i+1:]) for i in range(N)]
    print(max(gcdlist))
else:
    gcds(Alist)