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:
n = int(input())
l = list(map(int, input().split()))
l = set(l)
#print(l)

from itertools import combinations
a = list(combinations(l, n-1))
#print(a)

from fractions import gcd
from functools import reduce

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

g = []
for i in range(len(a)):
    g.append(gcd_list(a[i]))

print(max(g))

Submission status: Runtime Error

Solution code:
import fractions

N=int(input())

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

M=[2]
while M[-1]<N:
    M.append(M[-1]*2)

tgt=sum(M)-M[0]
A=A+[A[-1]]*(M[-1]-len(A))
A=A[::-1]

for i in range(tgt-1):
    A.append(fractions.gcd(A[2*i],A[2*i+1]))

A=A[::-1]

print(A)

Submission status: Runtime Error

Solution code:
import math
import functools
import copy
def gcd_list(num_list):
    return functools.reduce(math.gcd, num_list)


N = int(input())
A = list(map(int, input().split()))
A.sort()
A1 = copy.deepcopy(A)
A2 = copy.deepcopy(A)
A1.pop(0)
A2.pop(1)
print(max(gcd_list(A1), gcd_list(A2)))

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce


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


n = int(input())
num_list = list(map(int,input().split()))
gcd = [1 for _ in range(n-1)]
for i in range(n-1):
    num = num_list[:i] + num_list[(i + 1):]
    gcd[i] = gcd_list(num)

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())
num_list = list(map(int,input().split()))
gcd = [1 for _ in range(n-1)]
for i in range(n-1):
    num = num_list[:i] + num_list[(i + 1):]
    gcd[i] = gcd_list(num)

print(max(gcd))

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce

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

    def pleaceAC():
        yield reduce(gcd, A[1:])
        yield reduce(gcd, A[:-1])
        for i in range(1,N-1):
            a = reduce(gcd, A[:i])
            b = reduce(gcd, A[i+i:])
            yield gcd(a, b)

    print(max(pleaceAC()))


main()

Submission status: Runtime Error

Solution code:
import copy

import math

def longgcd(S):
    if len(S)==2:
        return math.gcd(S[0],S[1])
    else:
        x=S[0]
        for i in range(0,N):
            x=math.gcd(x,S[i])
        return x

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

m=0

for i in range(0,N):
    B=copy.copy(A)
    B[i]=0
    x=longgcd(B)
    if x>m:
        m=x
print(m)

Submission status: Runtime Error

Solution code:
import copy

def gcd(n,m):#n,mは正の整数、最大公約数　許容は？
    if n==0:
        return m
    elif m==0:
        return n
    elif n>m:
        n=n%m
        return gcd(n,m)
    else:
        m=m%n
        return gcd(n,m)

def longgcd(S):
    if len(S)==2:
        return gcd(S[0],S[1])
    else:
        s=S[len(S)-1]
        S.remove(S[len(S)-1])
        return gcd(s,longgcd(S))

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

m=0

for i in range(0,N):
    B=copy.copy(A)
    B[i]=0
    x=longgcd(B)
    if x>m:
        m=x
print(m)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
N,*a=map(int,open(0).read().split())
_max=0
for i in a:
    b=a[:]
    b.remove(i)
    _max=max(_max,reduce(math.gcd,b))
print(_max)

Submission status: Runtime Error

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

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

b = list(combinations(a, n-1))

gcd_a = [reduce(gcd, list(x)) for x in b]
print(max(gcd_a))

Submission status: Runtime Error

Solution code:
from math import gcd

def bit_length(self):
    s = bin(self)
    s = s.lstrip('-0b')
    return len(s)

def segfunc(x, y):
    return gcd(x, y)
    
def init(init_val):
    for i in range(N):
        seg[i+num-1] = init_val[i]
    for i in range(num-2, -1, -1):
        seg[i] = segfunc(seg[2*i+1], seg[2*i+2])

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

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

N = int(input())
a = tuple(map(int, input().split()))

# identity element
ide_ele = 0

# least 2-powered value greater than N
num = bit_length(2**(N-1))
seg = [ide_ele]*2*num

init(a)
ans = -1
for i in range(N):
    ans = max(ans, gcd(query(0, i), query(i+1, N)))
print(ans)

Submission status: Runtime Error

Solution code:
def gcdf(a,n,a0):
    a.sort()
    a0=a[0]
    a=[int(x%a0) for x in a if x%a0 != 0]
#    print("a2:",a)
    if len(a)==0:
        return a0
    else:
        a.append(a0)
        a0=min(a)
        return gcdf(a,n,a0) 

#n=8
#a=[746130, 1385670, 4849845, 881790, 3233230, 1939938, 570570, 510510]
#ans=[19]
#n=2
#a=[1000000000, 1000000000]
#n=5
#a=[15, 18, 24, 36, 81]
#n=3
#a=[7, 6, 8]
n=int(input())
a=[]
for i in map(int,input().split()):
    a.append(i)

#print(a)
if n==2:
    print(max(a))
elif n<=2**10:
    gcdv=0
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        a0=acpy[0]
        gcdx=gcdf(acpy,n-1,a0)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)
else:
    a.sort()
    ns=int(n/4)
    a1=a[0:ns]
    a2=a[ns:ns*2]
    a3=a[ns*2:ns*3]
    a4=a[ns*3:n]
#    print(a1)
#    print(a2)
#    print(a3)
#    print(a4)
    gcdv=0
    a10=a1[0]
    a20=a2[0]
    a30=a3[0]
    a40=a4[0]
    gcd1=gcdf(a1,len(a1),a10)
    gcd2=gcdf(a2,len(a2),a20)
    gcd3=gcdf(a3,len(a3),a30)
    gcd4=gcdf(a4,len(a4),a40)
    for i in range(ns):
#        acpy=list(a1)
        acpy=a1.copy()
        acpy.append(gcd2)
        acpy.append(gcd3)
        acpy.append(gcd4)
        del acpy[i]
#        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),a10)
        if gcdx>gcdv:
            gcdv=gcdx
#    print(gcdv,a1)
    for i in range(ns):
#        acpy=list(a2)
        acpy=a2.copy()
        acpy.append(gcd1)
        acpy.append(gcd3)
        acpy.append(gcd4)
        del acpy[i]
#        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),a20)
        if gcdx>gcdv:
            gcdv=gcdx
#    print(gcdv,a2)
    for i in range(ns):
#        acpy=list(a3)
        acpy=a3.copy()
        acpy.append(gcd1)
        acpy.append(gcd2)
        acpy.append(gcd4)
        del acpy[i]
#        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),a30)
        if gcdx>gcdv:
            gcdv=gcdx
#    print(gcdv,a3)
    for i in range(ns):
#        acpy=list(a4)
        acpy=a4.copy()
        acpy.append(gcd1)
        acpy.append(gcd2)
        acpy.append(gcd3)
        del acpy[i]
#        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),a40)
        if gcdx>gcdv:
            gcdv=gcdx
#    print(gcdv,a4)
    print(gcdv)

Submission status: Runtime Error

Solution code:
#ABC125C
N=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
    if a>b:a,b=b,a
    while a%b:
        a,b=b,a%b
    return b
def gcd_list(A):
    if len(A)<2:return A
    res=gcd(A[0],A[1])
    for i in range(len(A)-2):
        res=gcd(res,A[i+2])
    return res
res=0
for i in range(N):
    Ai=A[:]
    Ai.pop(i)
    res=max(res,gcd_list(Ai))
print(res)

Submission status: Runtime Error

Solution code:
def gcdf(a,n,gcdv):
#    print("a:",a)
    a0=a[0]
    ramin=10**9
    ramin0=20**9
    while ramin0!=ramin:
        ramin0=ramin
        for i in range(n):
            a[i]=a[i]%a0
            if a[i]==0:
                a[i]=a0
            if ramin>a[i]:
                ramin=a[i]
            if ramin<=gcdv:
                return gcdv
        a0=min(a)
#        print("a:",a,ramin)
    return ramin


#n=2
#a=[1000000000, 1000000000]
#n=4
#a=[15, 18, 24, 36]
n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)

#print(a)
if n==2:
    print(max(a))
elif n>=16:
    a.sort()
    ns=int(n/4)
    a1=a[0:ns]
    a2=a[ns:ns*2]
    a3=a[ns*2:ns*3]
    a4=a[ns*3:n]
    print(a1)
    print(a2)
    print(a3)
    print(a4)
    gcdv=0
    gcd1=gcdf(a1,len(a1),gcdv)
    gcd2=gcdf(a2,len(a2),gcdv)
    gcd3=gcdf(a3,len(a3),gcdv)
    gcd4=gcdf(a4,len(a4),gcdv)
    for i in range(ns):
#        acpy=list(a1)
        acpy=a1.copy()
        acpy.append(gcd2)
        acpy.append(gcd3)
        acpy.append(gcd4)
        del acpy[i]
        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv,a1)
    for i in range(ns):
#        acpy=list(a2)
        acpy=a2.copy()
        acpy.append(gcd1)
        acpy.append(gcd3)
        acpy.append(gcd4)
        del acpy[i]
        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv,a2)
    for i in range(ns):
#        acpy=list(a3)
        acpy=a3.copy()
        acpy.append(gcd1)
        acpy.append(gcd2)
        acpy.append(gcd4)
        del acpy[i]
        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv,a3)
    for i in range(ns):
#        acpy=list(a4)
        acpy=a4.copy()
        acpy.append(gcd1)
        acpy.append(gcd2)
        acpy.append(gcd3)
        del acpy[i]
        print(i,acpy)
        gcdx=gcdf(acpy,len(acpy),gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv,a4)
    print(gcdv)
    
else:
    gcdv=0
    a.sort()
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=gcdf(acpy,n-1,gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)

Submission status: Runtime Error

Solution code:
def gcdf(a,n,gcdv):
#    print("a:",a)
    a0=a[0]
    ramin=10**9
    ramin0=20**9
    while ramin0!=ramin:
        ramin0=ramin
        for i in range(n):
            a[i]=a[i]%a0
            if a[i]==0:
                a[i]=a0
            if ramin>a[i]:
                ramin=a[i]
            if ramin<=gcdv:
                return gcdv
        a0=min(a)
#        print("a:",a,ramin)
    return ramin


#n=2
#a=[1000000000, 1000000000]
#n=4
#a=[15, 18, 24, 36]
n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)

#print(a)
if n==2:
    print(max(a))
elif n<-16:
    ns=int(n/8)
    a1=[0:ns]
    a2=[ns:ns*2]
    a3=[ns*2:ns*3]
    a4=[ns*3:n]
    gcdv=0
    gcd1=gcdf(a1,len(a1),gcdv)
    gcd2=gcdf(a2,len(a2),gcdv)
    gcd3=gcdf(a3,len(a3),gcdv)
    gcd4=gcdf(a4,len(a4),gcdv)
    
else:
    gcdv=0
    a.sort()
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=gcdf(acpy,n-1,gcdv)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)

Submission status: Runtime Error

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

def gcdf(a,n):
    a0=a[0]
    ramin=10**9
    ramin0=20**9
    while ramin0!=ramin:
        ramin0=ramin
        for i in range(1,n):
            ra=a[i]%a0
#            print(ra,a0,i,ramin)
            if ramin>ra and ra!=0:
                ramin=ra
        a0=ramin
    return ramin


#n=2
#a=[1000000000, 1000000000]
n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)
#print(a)
if n==2:
    print(max(a))
else:
    gcdv=0
#    a.sort()
    for i in range(n):
        acpy=list(a)
        del acpy[i]
#        gcdx=gcdf(acpy,n-1)
#        gcdx=gcd(acpy)
#        gcdx=functools.reduce(gcd,acpy)
        gcdx=functools.reduce(math.gcd,acpy)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)

Submission status: Runtime Error

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

n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)
#print(a)
if n==2:
    print(max(a))
else:
    gcdv=0
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=functools.reduce(math.gcd,acpy)
        if gcdx>gcdv:
            gcdv=gcdx
    print(gcdv)

Submission status: Runtime Error

Solution code:
from fractions import gcd

n=int(input())

a=[]
for i in map(int,input().split()):
    a.append(i)
#print(a)
if n==2:
    print(max(a))
else:
    for i in range(n):
        acpy=list(a)
        del acpy[i]
        gcdx=gcd(acpy)
        if gcdx>gcd:
            gcd=gcdx
    print(gcd)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
  if a*b == 0:
    return max(a,b)
  if a<b:
    a,b = b,a
  return gcd(b,a%b)
n = int(input())
ls = list(map(int,input().split()))
length = 2**((n-1).bit_length())
calc = gcd
unit = 0
Seg = [unit for i in range(length*2-1)]
def init():
  for i in range(n):
    Seg[i+length-1] = ls[i]
  for i in range(length//2,-1,-1):
    Seg[i] = calc(Seg[2*i+1],Seg[2*i+2])
def update(i,x):
  i += length-1
  Seg[i] = x
  while i>0:
    i = (i-1)//2
    Seg[i] = calc(Seg[2*i+1],Seg[2*i+2])
def query(a,b,k,l,r):
  if r<=a or b<=l:
    return unit
  if l<=a and b<=r:
    return Seg[k]
  else:
    vl = query(a,b,2*k+1,l,(l+r)//2)
    vr = query(a,b,2*k+2,(l+r)//2,r)
    return calc(vl,vr)

init()
ans = []
for i in range(n):
  update(i,0)
  ans.append(query(0,n,0,0,length))
  update(i,ls[i])
print(max(ans))

Submission status: Runtime Error

Solution code:
# Nの最小値を Max にして、全部の数字が割り切れるかどうかを探索する。ってのはどうだろう
# どんなに頑張ってもO(N^2)だからあとは下から攻めるか上から攻めるかみたいなところではあるが…
N = int(input())
An = [a for a in map(int, input().split())]
An.sort()
Max = An[0]
ans = 0
for i in range(Max//2 ,Max + 1):
  cnt = 0
  for A in An:
    if A%i != 0:
      cnt += 1
  if cnt <= 1:
    ans = i
print(ans)

Submission status: Runtime Error

Solution code:
import os, sys, re, math

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

def common_gcd(ex_idx):
    ret = 0
    for i in range(N):
        if i != ex_idx:
            if ret == 0:
                ret = A[i]
            else:
                ret = math.gcd(ret, A[i])
    return ret

ret = 1
for j in range(N):
    ret = max(ret, common_gcd(j))

print(ret)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100001)

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

# 一人消してgcd
n = int(input())
nl = sorted(list(map(int, input().split(' '))))
rl = nl[::-1]
sumnl = [nl[0]]
sumrl = [rl[0]]
for i in range(1, len(nl)):
    sumnl.append(gcd(sumnl[-1], nl[i]))
    sumrl.append(gcd(sumrl[-1], rl[i]))
sumrl = sumrl[::-1]
if len(sumnl) == 1:
    print(sumnl[0])
else:
    print(max([gcd(sumnl[i],sumrl[i+2]) for i in range(len(sumrl) - 2)]))

Submission status: Runtime Error

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

# 一人消してgcd
n = int(input())
nl = sorted(list(map(int, input().split(' '))))
rl = nl[::-1]
sumnl = [nl[0]]
sumrl = [rl[0]]
for i in range(1, len(nl)):
    sumnl.append(gcd(sumnl[-1], nl[i]))
    sumrl.append(gcd(sumrl[-1], rl[i]))
sumrl = sumrl[::-1]
print(max([gcd(sumnl[i],sumrl[i+2]) for i in range(len(sumrl) - 2)]))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100001)
 
# 一人消してgcd
n = int(input())
l = sorted(list(map(int, input().split(' '))))
def gcd(b, s):
  return s if b % s == 0 else gcd(s, b % s)
 
memo = {}
mmm = 0
def ggcd(l, i, skip, current):
  global mmm
  if i == len(l) or current == 1 or current <= mmm:
    if mmm < current:
      mmm = current
    return current
  key = (i, skip)
  if key not in memo:
    if i == skip:
      memo[key] = ggcd(l, i+1, skip, current)
    else:
      memo[key] = ggcd(l, i+1, skip, gcd(l[i], current))
  return memo[key]
if len(l) == 1:
  print(l[0])
else:
  [ggcd(l, 0, skip, l[1] if skip == 0 else l[0]) for skip in range(len(l))]
  print(mmm)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100001)
 
# 一人消してgcd
n = int(input())
l = sorted(list(map(int, input().split(' '))))
def gcd(b, s):
  return s if b % s == 0 else gcd(s, b % s)
 
memo = {}
mmm = 0
def ggcd(l, i, skip, current):
  global mmm
  if i == len(l) or current == 1 or current <= mmm:
    if mmm < current:
      mmm = current
    return current
  key = (i, skip)
  if key not in memo:
    if i == skip:
      memo[key] = ggcd(l, i+1, skip, current)
    else:
      memo[key] = ggcd(l, i+1, skip, gcd(l[i], current))
  return memo[key]
[ggcd(l, 0, skip, l[1] if skip == 0 else l[0]) for skip in range(len(l))]
print(mmm)

Submission status: Runtime Error

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


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

for i in range(N):
    a = gcd(r, A[i]) if r != 0 else A[i]
    if a < r:
        b = i
    r = a

r3 = 0
for i in range(N):
    if i == b - 1:
        continue
    r3 = gcd(r3, A[i]) if r3 != 0 else A[i]

r4 = 0
for i in range(N):
    if i == b:
        continue
    r4 = gcd(r4, A[i]) if r4 != 0 else A[i]

d = sorted([(gcd(A[i], A[i + 1]), i) for i in range(N - 1)])
t = d[0][1]
r1 = 0
for i in range(N):
    a = A[i-1] if i == t + 1 else A[i]
    if r1 == 0:
        r1 = a
    else:
        r1 = gcd(r1, a)
r2 = 0
for i in range(N):
    a = A[i+1] if i == t else A[i]
    if r2 == 0:
        r2 = a
    else:
        r2 = gcd(r2, a)
print(max(r1, r2, r3, r4))

Submission status: Runtime Error

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

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

memo = {}
def doit(i, f):
    if i == len(a) - 1:
        return a[i]
    if not (i, f) in memo:
        ret = gcd(a[i], doit(i + 1, f))
        if f == 0:
            ret = max(ret, doit(i + 1, 1))
        memo[(i, f)] = ret
    return memo[(i, f)]

print(doit(0, 0))

Submission status: Runtime Error

Solution code:
N = int(input())
As = [int(s) for s in input().split(' ')]
As.sort()
As = list(set(As))
A_max = max(As)

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

ret = 1
if len(As) == 2:
    # A1 A2
    ret = gcd(As[0], As[1])
elif len(As) == 3:
    # A1 A2 A3
    ret = max(gcd(As[0], As[1]), gcd(As[0], As[2]),gcd(As[1], As[2]))
else:
    # A1 A2 ... An-1 An
    ret1 = max(gcd(As[0], As[1]), gcd(As[0], As[-2]),gcd(As[1], As[-2]))
    ret2 = max(gcd(As[1], As[-2]), gcd(As[1], As[-1]),gcd(As[-1], As[-2]))
    ret3 = max(gcd(As[0], As[1]), gcd(As[1], As[-2]),gcd(As[0], As[-2]))
    ret4 = max(gcd(As[0], As[1]), gcd(As[1], As[-1]),gcd(As[0], As[-1]))
    ret = max(ret1, ret2, ret3, ret4)
print(ret)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100001)

# 一人消してgcd
n = int(input())
l = sorted(list(map(int, input().split(' '))))
def gcd(b, s):
  return s if b % s == 0 else gcd(s, b % s)

memo = {}
mmm = 0
def ggcd(l, i, skip, current):
  global mmm
  if i == len(l) or current == 1 or current <= mmm:
    if mmm < current:
      mmm = current
    return current
  key = (i, skip, current)
  if key not in memo:
    if i == skip:
      memo[key] = ggcd(l, i+1, skip, current)
    else:
      memo[key] = ggcd(l, i+1, skip, gcd(l[i], current))
  return memo[key]
[ggcd(l, 0, skip, l[1] if skip == 0 else l[0]) for skip in range(len(l))]
print(mmm)

Submission status: Runtime Error

Solution code:
l_ans = [0] * n
g = 0
for i in range(1, n):
    g = gcd(g, v[i-1])
    l_ans[i] = g
r_ans = [0] * n
g = 0
for i in range(1, n):
    g = gcd(g, v[n-i])
    r_ans[i] = g
r_ans.reverse()
ans = 1
for i in range(n):
    ans = max(ans, gcd(l_ans[i], r_ans[i]))
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce

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

def gcd_list(numbers):
    return reduce(gcd, numbers)
m = list()
for i in range(n):
    m.append(gcd_list(As[:i]+As[i+1:]))
print(max(m))

Submission status: Runtime Error

Solution code:
import fractions 
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(0,N):
  ans=a[i]
  for j in range(1,N-1):
      ans=fractions.gcd(ans,a[j+i])
  B.append(ans)
print(max(B))

Submission status: Runtime Error

Solution code:
N = int(input())
A=sorted(list(map(int,input().split())))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def gcdlist(lista):
    if len(lista) == 1:
        return lista[0]
    else:
        from functools import reduce
        return reduce(gcd,lista)
first = A.pop(0)
ans = []
second = A[0]
gcda = gcdlist(A[1:])
for i in range(first,second+1):
    ans.append(gcd(i,gcda))
print(max(ans))

Submission status: Runtime Error

Solution code:
#ABC125_C
import fractions
from functools import reduce
 
def gcd(nums):
    return reduce(fractions.gcd,nums)
 
N=int(input())
A=list(map(int,input().split()))
ans=1
       
for i in range(N):
    temp=A.copy()
    temp.reduce(temp[i])
    if gcd(temp) > ans:
        ans=gcd(temp)
print(ans)

Submission status: Runtime Error

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

import numpy as np
import fractions
from functools import reduce

from copy import deepcopy


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

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

    bools = np.ones(N, dtype=bool)

    gcd_val = 0
    ans = 0
    for i in range(N):
        A_cop = deepcopy(A)
        bl_cop = deepcopy(bools)

        fal = [i]
        bl_cop[fal] = False

        gcd_val = gcd_list(A_cop[bl_cop])

        if ans == 0 or ans < gcd_val:
            ans = gcd_val

    print(ans)

main()

Submission status: Runtime Error

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

L = [0]*(N+1)
R = [0]*(N+1)

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

M = []
for i in range(N-1):
    M.append(math.gcd(L[i],R[i+1]))
    
print(max(M))

Submission status: Runtime Error

Solution code:
import copy
import math
from functools import reduce

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

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

ans = 0
for i in range(N):
    tmp = copy.copy(A)
    tmp.pop(i)
    ans = max(ans, gcd(*tmp))

print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

N = int(input())
A = str(input())
A = A.split()
A_list = []
for i in range(N):
    A_list.append(int(A[i]))

max_count = 0
for i in range(N):   
    A_change = []
    for j in range(N):
        A_change.append(int(A_list[j]))
    A_change.pop(i)
    val = gcd_list(A_change)
    if val > max_count:
        max_count = val

print(max_count)

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 = [i for i in map(int, input().split())]

gcd_max = 0
for i in range(N):
  gcd = gcd_list([A[l] for l in range(N) if l != i])
  if gcd_max < gcd:
    gcd_max = gcd

print(gcd_max)

Submission status: Runtime Error

Solution code:
import math
from itertools import accumulate

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

L = [0]+list(accumulate(a, math.gcd))
R = list(accumulate(reversed(a), math.gcd))[::-1]+[0]


ans = 0

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

if n == 2:
    print(max(a))
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import math
from itertools import accumulate

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

L = [0]+list(accumulate(a, math.gcd))
R = list(accumulate(reversed(a), math.gcd))[::-1]+[0]

ans = 0

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

print(L)
print(R)
print(ans)

Submission status: Runtime Error

Solution code:
import math
from itertools import accumulate

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

L = [0]+list(accumulate(a, math.gcd))
R = list(accumulate(reversed(a), math.gcd))[::-1]+[0]

ans = 0

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


print(ans)

Submission status: Runtime Error

Solution code:
import math
from itertools import accumulate

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

L = list(accumulate(a, math.gcd))
R = list(accumulate(reversed(a), math.gcd)) 

ans = 0
if n == 2:
    print(max(a))
else:
    for i in range(1,n):
        ans = max(math.gcd(L[i],R[i]),ans)
        print(max(ans))

Submission status: Runtime Error

Solution code:
import math
from itertools import accumulate

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

L = list(accumulate(a, math.gcd))
R = list(accumulate(reversed(a), math.gcd)) 

ans = 0
for i in range(1,n):
    ans = max(math.gcd(L[i],R[i]),ans)
    
print(ans)

Submission status: Runtime Error

Solution code:


from math import gcd
from functools import reduce # reduceの使い方覚える、ついでにaccumulateも

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

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

result = []
for i in range(n):
  numbers = A[:]
  numbers.pop(i)
  result.append(divider(numbers))
print(max(result))

Submission status: Runtime Error

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

#output
import numpy as np
from functools import reduce
from fractions import gcd
A = np.array(A)
np.gcd.reduce(A)

answer = 0
for i in range(N):
    temp = A[i]
    A[i] = 0
    answer = max(answer, np.gcd.reduce(A))
    A[i] = temp

print(answer)

Submission status: Runtime Error

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

#output
import numpy as np
from functools import reduce
A = np.array(A)
np.gcd.reduce(A)

answer = 0
for i in range(N):
    temp = A[i]
    A[i] = 0
    answer = max(answer, np.gcd.reduce(A))
    A[i] = temp

print(answer)

Submission status: Runtime Error

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

#output
import numpy as np
A = np.array(A)
np.gcd.reduce(A)

answer = 0
for i in range(N):
    temp = A[i]
    A[i] = 0
    answer = max(answer, np.gcd.reduce(A))
    A[i] = temp

print(answer)

Submission status: Runtime Error

Solution code:
import copy
import fractions
N=int(input())
A=list(map(int,input().split()))
ans=[]
def dfs(A):
  l=[]
  if len(A)==1:
    return A[0]
  for i in range(0,len(A),2):
    l.append(fractions.gcd(A[i],A[i+1]))
  return dfs(l)
  
  
for i in range(N):
  s=copy.deepcopy(A)
  s.pop(i)
  ans.append(dfs(s))

print(max(ans))

Submission status: Runtime Error

Solution code:
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a%b)
    }
}

fn main() {
    let N: usize = read_line().parse().unwrap();
    let A = read_vec();

    let mut left = vec![0; N];
    let mut right = vec![0; N];

    left[0] = A[0];
    for i in 1..N {
        left[i] = gcd(left[i-1], A[i]);
    }
    right[N-1] = A[N-1];
    for i in (0..N-1).rev() {
        right[i] = gcd(right[i+1], A[i]);
    }

    let mut max = right[1];
    for i in 1..N-1 {
        max = std::cmp::max(max, gcd(left[i-1], right[i+1]));
    }
    max = std::cmp::max(max, left[N-2]);
    println!("{}", max);
}

Submission status: Runtime Error

Solution code:
from math import gcd

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

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

ans = gcd_from_right[1]
gcd_from_left = A[0]
for i in range(1, N-1):
    ans = max(ans, gcd(gcd_from_left, gcd_from_right[i+1]))
    gcd_from_left = gcd(gcd_from_left, A[i])
ans = max(ans, gcd_from_left)
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
from functools import reduce


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


n = int(input())
lst = list(map(int, input().split()))
lst.sort()

v = 0
index = 0
# 2値の最大公約数を求める
for i in range(n):
  arr = lst[:i] + lst[i + 1:len(lst)]
  g = gcd(*arr)
  if g > v:
    v = g
    index = i

print(v)

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce
n=int(input())
h=[int(a) for a in input().split()]
ans=0
for i in range(n):
  del h[i]
  ans=max(reduce(gcd,h),ans)
print(ans)

Submission status: Runtime Error

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

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

ans = 0
for i in range(n):
    ans = max(math.gcd(left[i], right[i+1]), ans)

print(ans)

Submission status: Runtime Error

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

N = int(input())
A = list(map(int,input().split()))
print("I didn't solve")
import sys
import math
input = sys.stdin.readline

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

Submission status: Runtime Error

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

N = int(input())
A = list(map(int,input().split()))
print("I didn't solve)

Submission status: Runtime Error

Solution code:
print("I didn't solve)

Submission status: Runtime Error

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

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

import fractions
from functools import reduce
import numpy as np

def gcd_list(a):
    return reduce(fractions.gcd, a)

left = [0]*n
right = [0]*n

for i in range(1, n):
    left[i] = np.gcd.reduce(a[:i])

for i in range(n-2, -1, -1):
    right[i] = np.gcd.reduce(a[i+1:])

ans = 0
for i in range(n):
    ans = max(ans, gcd_list([left[i], right[i]]))
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
array = np.array(list(map(int, input().strip().split())))

print(max([np.gcd.reduce(array[[i for i in range(n) if i != j]]) for j in range(n)]))