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 numpy as np
N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A.copy(), reverse=True)

ans = 1
counts = [0] * (B[0]+1)
for d in range(B[0], B[-1]//2-1, -1):
    for b in B:
        if b % d == 0:
            counts[d] += 1
            if d != b // d:
                counts[b//d] += 1

    if counts[d] >= N-1:
        ans = d
        break

if ans == 1:
    for i in range(B[0]//2, 0, -1):
        if counts[i] >= N-1:
            ans = i

print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce

def gcd_base(x, y):
    if x >= y:
        while y != 0:
            x, y = y, x % y
        return x
    else:
        while x != 0:
            y, x = x, y % x
        return y

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

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

for i in range(N):
    GCD.append(gcd(A[:i]))
    A.append(a)

print(max(GCD))

Submission status: Runtime Error

Solution code:
import fraction
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]=fraction.gcd(ans[t],A[u+1])
            u=u+1
    else:
        ans[t]=A[1]
        y=1
        while y<N-1:
            ans[t]=fraction.gcd(ans[t],A[y+1])
            y=y+1
    t=t+1
print(max(ans))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# input
n = int(input())
num = [int(a) for a in input().split()]

num.sort(reverse=True)
k = [0] * int(n * (n - 1) / 2)

cnt = 0
for i in range(n - 1):
    for j in range(i+1, n):
        p = num[i]
        q = num[j]
        while 1:
            tmp = p % q
            if tmp == 0:
                k[cnt] = q
                cnt += 1
                break
            else:
                p = q
                q = tmp

if n < 4:
    k.sort(reverse=True)
    max = k[0]
else:
    max = 1
    for i in range(cnt):
        tmp = k.count(k[i])
        if tmp == n - 1 and k[i] > max:
            max = k[i]

print(max)

Submission status: Runtime Error

Solution code:
import fraction
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:
n = int(input())
A = list(map(int, input().split()))
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

if len(A) == 2:
    print(gcd(A[0], A[1]))
    exit()
b = set()
for i in range(2):
    a = 0
    for j in range(n):
        a = gcd(A[i],A[j])
        b.add(a)
b = sorted(b)
print(b[1])

Submission status: Runtime Error

Solution code:
import fractions
def main():
    N = int(input())
    *A, = map(int, input().split())
    A.sort()
    gcds = []
    for i in range(1,N):
        gcds.append(fractions.gcd(A[0],A[i]))
    gcds.sort()
    flag = True
    if len(gcds) == 1:
        print(max(A))
        flag = False
    i = 0
    maxi = 0
    while flag and i < len(gcds)-2:
        if gcds[i] == gcds[i + 1]:
            for j in gcds:
                if j % gcds[i] != 0:
                    break
                if j == len(gcds) - 1:
                    maxi = gcds[i]
                    flag = False
        elif gcds[i] != gcds[i + 1]:
            for j in gcds:
                if j % gcds[i + 1] != 0:
                    break
                if j == len(gcds) - 1:
                    maxi = gcds[i+1]
                    flag = False
        i += 1
            print(maxi)
main()

Submission status: Runtime Error

Solution code:
import numpy as np
import copy

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

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

if N<=2:
    print(max(A))
else:
    gcdss = []
    for i,a in enumerate(A):
        A_temp = copy.deepcopy(A)
        A_temp.pop(i)
        gcds = []
        for i in range(len(A_temp)-1):
            gcd_temp = gcd(A_temp[i],A_temp[i+1])
            gcds.append(gcd_temp)
            if gcd_temp == 1:
                break
        gcdss.append(min(gcds))
    print(max(gcdss))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A.copy(), reverse=True)

ans = 1
counts = [0] * (B[0]+1)
for d in range(B[0], B[-1]//2-1, -1):
    for b in B:
        if b % d == 0:
            counts[d] += 1
            if d != b // d:
                counts[b//d] += 1

    if counts[d] >= N-1:
        ans = d
        break

if ans == 1:
    print(counts)
    for i in range(B[0]//2, 0, -1):
        if counts[i] >= N-1:
            ans = i

print(ans)

Submission status: Runtime Error

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

A.sort()
cnt = [] 
bad = 0
j = True
for i in range(1, A[1]):
    for n in range(N):
        if bad==2:
            cnt.append(0)
            j = False
            break
        elif A[n]%i != 0:
            bad += 1
    if j:
        cnt.append(i)



print(max(cnt))

Submission status: Runtime Error

Solution code:
N = int(input())
listA = list(map(int, input().split()))
ans = 0
count = 0
pre_count = 0
maxnumber = max(listA)
for i in range(0, maxnumber):
	for j in range(0, N):
		divnum = listA[j] % i 
		if divnum == 0:
			count++
		if count > pre_count:
			pre_count = count
			ans = i
	count = 0
print(ans)

Submission status: Runtime Error

Solution code:
import functools
import fractions

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
    A = list(set(A))
    N = len(A) + 1
  else:
    # N = 3
    # A = [7,6,8]
    # N = 3
    # A = [12,15,18]
    N = 2
    A = [1000000000,1000000000]

  x = 0
  for i in range(N):
    if N == 1 : 
      tmp = 1000000000
    elif N == 2 :
      tmp = functools.reduce(fractions.gcd, A)
    else:
      if i+1=N:
        tmp = functools.reduce(fractions.gcd, A[0:i])
      else:
        tmp = functools.reduce(fractions.gcd, A[0:i]+A[i+1:])
    if tmp > x:
      x = tmp
  
  print(x)
  
main()

Submission status: Runtime Error

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

A.sort()
mini, minj = 0,1
mingcd = 10*9
for i in range(0, N - 1):
    for j in range(i + 1, N):
        tmp = gcd(A[i],A[j])
        if tmp <= mingcd:
            mini, minj = i, j
Ai = A[i]
Aj = A[j]
A.remove(Ai)
A.remove(Aj)
ans = A[0]
for i in A:
    ans = gcd(i, ans) 
ans = max(gcd(Aj, ans), gcd(ans, Ai))
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
import functools
import sys
sys.setrecursionlimit(100000000)

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

if len(a) == 2:
  print(max(a))
  sys.exit()
  
gcd_a = functools.reduce(fractions.gcd, a)
a=[i//gcd_a for i in a]

cnt = 0
gcd_0 = functools.reduce(fractions.gcd, a[1:])
for i in range(1,len(a)):
  if fractions.gcd(a[0],a[i]) == 1:
    so = i
    cnt+=1
    if cnt == 2:
      print(max(gcd_a,gcd_0*gcd_a))
      sys.exit()
      
if cnt == 0:
  print(gcd_a)
    sys.exit()

a_i = [i for i in a if i != a[so]]
gcd_i = functools.reduce(fractions.gcd, a_i)

print(max(gcd_0,gcd_i)*gcd_a)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(int, input().split())
Amax = max(A)
count1 = 1
count2 = 2
count3 = 1

def f(n):
    return n%count2

for i in range(Amax-2):
    A2 = list(map(f, A))
    if sum(A2)==0:
        count1 = count1 * count2
    if A2.count(0)==len(A2)-1:
        count3 = count2
    count2 += 1
    
    
    
print(count1*count3)

Submission status: Runtime Error

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

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

valueList = [a[0]]
maxList = []

g = a[0]
valueList.append(g)
g = a[1]
for k in range(i+1, n):
  g = gcd(g, a[k])
maxList.append(g)
  

for i in range(1,n):
  g = a[0]
  for j in range(i):
    g = gcd(g,a[j])
  valueList.append(g)
  g = valueList[i]
  for k in range(i+1, n):
    g = gcd(g, a[k])
  maxList.append(g)
    
print(max(maxList))

Submission status: Runtime Error

Solution code:
from fractions import gcd as g
 
r=reduce
 
 
n=int(raw_input())
a=map(int,raw_input().split())
if len(set(a))<n:
	print r(g,a)
	exit()
 
e,o=[],[]
n1,n2=0,0
for i in a:
	if i&1:
		o.append(i)
		n2+=1
	else:
		e.append(i)
		n1+=1
 
if n1>1 and n2>1:
	print 1
elif n1==1 and n2==1:
	print max(e+o)
else:
	if n1==1:
		print r(g,o)
		exit()
	if n2==1:
		print r(g,e)
		exit()
 
	a.sort()
	d=[]
	s=set()
	for i in xrange(1,n):
		e=g(a[0],a[i])
		s.add(e)
		d.append(e)
 	
 	if len(s)==1:
 		print d[0]
	if len(s)>2:
		print -1
	else:
		n1,n2=list(s)
		n1,n2=d.count(n1),n2(n2)
		if n1>0 and n2>0:
			print r(d,a)
		elif n1==1 or n2==1:
			print max(list(s))
		else:
			print 1

Submission status: Runtime Error

Solution code:
N = map(int, input())
A = map(int, input().split())
A = list(A)
A.append(A[-1])
each_GCD = []
for idx in range(len(A)-1):
    each_GCD.append(computeGCD(A[idx], A[idx+1]))
min_idx = each_GCD.index(min(each_GCD))
if min_idx < len(each_GCD)-1:
    pre = each_GCD[min_idx-1]
    nex = each_GCD[min_idx+1]
    if pre - nex >= 0:
        c = computeGCD(A[min_idx], A[min_idx+2])
        if nex > c:
            print(nex)
        else:
            print(c)
    else:
        c = computeGCD(A[min_idx+1], A[min_idx-2])
        if pre > c:
            print(pre)
        else:
            print(c)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

n = int(input())
a = []
tmp = input().split()
for i in range(n):
    a.append(int(tmp[i]))

if n == 2:
    if a[0] > a[1]:
        print(a[0])
    else:
        print(a[1])
    exit()

ans = 0
for i in range(0, n - 1):
    print(i, a, a[:i], a[i + 1:])
    tmp = a[:i] +  a[i + 1:]
    new_ans = reduce(math.gcd, tmp)
    if new_ans > ans:
        ans = new_ans

print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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


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


max_gcd = 0

for i in range(N):
    popped = A.pop(i)
    tmp_max_gcd = gcd_list(A)
    if tmp_max_gcd > max_gcd:
        max_gcd = tmp_max_gcd
    A.insert(i, popped)

print(max_gcd)

Submission status: Runtime Error

Solution code:
import fractions
import itertools

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

al = list(set(list(itertools.combinations(l, n-1))))

c = []

if len(al) > 1:
    for j in range(len(al)):
        a = list(al[j])
        ans = a[0]
        c.append((list(map(lambda x: fractions.gcd(ans,x), a[1:]))))

    print(max(c)[0])
    
else:
    print(fractions.gcd(l[0],l[1]))

Submission status: Runtime Error

Solution code:
import fractions
import copy
from functools import reduce
  
N= int(input())
A =list(map(int, input().split()))
A_2 =  list(set(A))
gcd = []
 
for i in range(len(A_2)):
  A_3 = copy.copy(A_2)
  gcd.append(reduce(fractions.gcd, A_2.remove(A_2[i])))
  A_2 = copy.copy(A_3)
print(max(gcd))

Submission status: Runtime Error

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

if len(A) == 1:
    print(A[0])
    exit()

ls = []
for i in range(len(A)):
    for j in range(len(A)):
        tmp = fractions.gcd(A[i], A[j])
        if tmp not in A:
            ls.append(tmp)

print(max(ls) if len(ls) < 1 else 1)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 27 21:17:40 2019

@author: Wataru
"""

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

#%%
import sys
sys.setrecursionlimit(100000)
def euclid(x,y):
    
    if x<y:
        x,y=y,x
    
    while y>0:
        r=x%y
        x=y
        y=r
    return x
   
    
Ntmp=len(A)//2
Atmp=[1]*Ntmp
for i in range(Ntmp):
    Atmp[i]=euclid(A[2*i],A[2*i+1])
if len(A)%2>0:
    Atmp=Atmp+[euclid(A[-1],A[0])]

min_idx=Atmp.index(min(Atmp))

if min_idx<Ntmp:
    if euclid(A[2*min_idx],max(Atmp))>euclid(A[2*min_idx+1],max(Atmp)):
        Atmp[min_idx]=A[2*min_idx]
    else:
        Atmp[min_idx]=A[2*min_idx+1]
else:
    if euclid(A[-1],max(Atmp))>euclid(A[0],max(Atmp)):
        Atmp[min_idx]=A[-1]
    else:
        Atmp[min_idx]=A[0]        
    
def rec_gcd(A):
    Ntmp=len(A)//2
    Atmp=[1]*Ntmp

    if Ntmp==1:
        return euclid(A[0],A[1])
    else:
        for i in range(Ntmp):
            Atmp[i]=euclid(A[2*i],A[2*i+1])
        if len(A)%2>0:
            Atmp=Atmp+[euclid(A[-1],A[0])]
    
        return rec_gcd(Atmp)
    
print(rec_gcd(Atmp))

Submission status: Runtime Error

Solution code:
def fermat(n):
    if n % 2 == 0 or n == 1:
        return 0 
    if pow(2, n-1, n) == 1:
        return 1


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


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


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


if n < 3:
    exit(print(max(a)))
interim_max = 0
for i in range(n-1):
    prime_n += fermat(a[i])
    if prime_n > 2:
        exit(print(1))
    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:
N = int(input())
As = [int(i) for i in input().split()]
answer = 0
for i in range(len(As)):
    As_copy =As.copy()
    _ = As_copy.pop(i)
    res = As_copy[0]
    for Ai in As_copy:
        res = calc(Ai, res)
    if res > answer:
        answer = res
print(answer)

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 = list(map(int, input().split()))
ans = []
for i in range(N-1):
    b_list = a_list
    c = b_list[i]
    for l in range(N):
        c = gcd(c, b_list[l])
    ans.append(c)
ans.sort()
print(ans[1])

Submission status: Runtime Error

Solution code:
import copy
import math
from functools import reduce

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

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

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

n = int(input())
a = list(map(int, input().split()))
a.sort()
rtn_2 = 1
rtn = gcd_list(a)
a_2 = copy.copy(a)
if not rtn == 1:
    a_2 = [x / rtn for x in a]
flg = True

for x in a_2:
    if is_prime(x):
        a_2.remove(x)
        flg = False
        break

if flg and not rtn == 1:
    for i in range(a_2):
        tmp = copy.copy(a_2)
        del tmp[i]
        tmp_rtn = gcd_list(tmp)
        if tmp_rtn > rtn_2:
            rtn_2 = tmp_rtn

rtn_2 = gcd_list(a_2) if len(a_2) > 1 else 1

print(int(rtn * rtn_2))

Submission status: Runtime Error

Solution code:
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))
A.argsort()

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

list_koyaku1=[]
list_koyaku11=[]       
         
if N==2:
    ans=max(A)

else:
    b=min(A)
    c=max(A)
    if gcd(c,b)==1:
        b=A[-2]
    
    for a in A:
        list_koyaku1.append(gcd(a,b))

    for a in list_koyaku1:
        list_koyaku11.append(gcd(a,c))
    
    number_prime=list_koyaku11.count(1)
    
    if number_prime>1:
        ans=1
    else:
        ans=max(list_koyaku11)

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
#C
import numpy as np
import math
import re
import functools
def gcd_list(x):
    return functools.reduce(math.gcd, x)

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

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 math

N = int(input())
As = [int(elm) for elm in input().split(" ")] 


def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass

if N >= 3:
    gs = []
    for i in range(0, (N//2)*2 , 2):
        g = math.gcd(As[i], As[i+1])
        gs.append(g)
    if N % 2 == 1:
        gs.append(As[N-1])

    while len(gs) != 2:
        #print(gs)
        new_gs = []
        N1 = len(gs)
        #print("len",len(gs), (N1//2)*2)
        for i in range(0, (N1//2)*2, 2):
            g = math.gcd(gs[i], gs[i+1])
            new_gs.append(g)
        if N1 % 2 == 1:
            new_gs.append(gs[-1])
        gs = new_gs

    g1, g2 = gs
    d1 = divisor(g1) 
    d2 = divisor(g2) 
    ds = sorted(d1 + d2, reverse=True)

    #print(gs)
    #print(ds)
    for d in ds:
        count = sum([int(A % d == 0) for A in As])
        if count >= N-1:
            out = d
            break

else:
    out = max(As)

print(out)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
r=0

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

def dfs(L,r,flag):
    for i,a in enumerate(L):
        tmp=fractions.gcd(r,a)
        if flag and r!=tmp:
            LR.append(dfs(L[i+1:],r,False))
        r=tmp
    return r

if len(LA)==2:
    print(max(LA))
else:
    dfs(LA,LA[0],True)
    dfs(LA[1:],LA[1],False)

    print(max(LR))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
N = int(input())
A = input().split()
A = [int(a) for a in A]
B = []
for n in range(N):
  for i in range(1, (10^9)+1):
    A[n] = i
    b = reduce(math.gcd, A)
    B.append(b)
B_max = max(B)
print(B_max)

Submission status: Runtime Error

Solution code:

from collections import defaultdict


def make_divisors(x):
    divisors = []
    for i in range(1, int(x ** 0.5) + 1):
        if x % i == 0:
            divisors.append(i)
            if i != x // i:
                divisors.append(x // i)

    return divisors


n = int(input())
a = list(map(int, input().split()))
divs = defaultdict(int)
divs_ = defaultdict(int)
la = len(a)
maxdiv = 1
for y in make_divisors(a[0]):
    divs[y] += 1
for y in make_divisors(a[1]):
    divs[y] += 1
if la == 2:
    for k, v in divs.items():
        if v >= 1:
            maxdiv = max(maxdiv, k)
    print(maxdiv)
    exit()
for y in make_divisors(a[2]):
    divs[y] += 1
divs_ = {k: v for k, v in divs.items() if v >= 2}
c = 4
for x in a[3:]:
    d = make_divisors(x)
    for y in d:
        if divs_[y] >= c - 2:
            divs_[y] += 1
    c += 1
for k, v in divs_.items():
    if v >= la - 1:
        maxdiv = max(maxdiv, k)
print(maxdiv)

Submission status: Runtime Error

Solution code:
import fractions

N=int(input())
a_list = [int(i) for i in input().split()]
a_list.sort()
b_list = a_list[:]
del b_list[-1]
ans1 = b_list[0]
for i in range(N-1):
	ans1 = fractions.gcd(ans1, b_list[i])

max_number = a_list[-1]
min_number = a_list[-1]
min_index = N
for i in range(N-1):
	gcd = fractions.gcd(max_number,a_list[i])
	if gcd < min_number:
		min_index = i
		min_number = gcd

del a_list[min_index]
ans2 = a_list[0]
for j in range(N-1):
	ans2 = fractions.gcd(ans2, a_list[j])
print(max(ans1,ans2))

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = [int(_) for _ in input().split()]
a.sort()

def GCD(x, y):
    while y > 0:      
        x, y = y, x % y
    return x

if n == 2:
    print(a[1])
else:
    odd = 0
    even = 0
    for num in range(n):
        if a[num] % 2 ==0:
            even += 1
            onlye = a[num]
        else: 
            odd += 1
            onlyo = a[num]
    if odd >= 2 and even >= 2:
        print(1)
    else:
        if odd == 1:
            a.remove(onlyo)
        elif even == 1:
            a.remove(onlye)
        for i in range(n):
            if i == 0:
                prev = GCD(a[1], a[2])
            elif i == 1:
                prev = GCD(a[0], a[2])
            else:
                prev = GCD(a[0], a[1])
            prev = GCD(prev, a[j])
            if prev > ans:
                ans = prev
        print(ans)

Submission status: Runtime Error

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

num = 1
for i in range(len(A)):
  B = A[ : i] + A[i + 1:]
  g = functools.reduce(math.gcd, B)
  if (g > num):
    num = g
print(num)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1
is_prime(1)

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

base = gcd_list(Value)

for i in range(N):
    if is_prime(int(Value[i] / base)) or int(Value[i] / base) = 1 :
        del Value[i]
        break
        
print(gcd_list(Value))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc125_a
import fractions, functools, itertools

# input
n = int(input())
A = [int(s) for s in input().split()]
# get ans
def search_booby(B):
    b0 = [fractions.gcd(B[0], a) for a in B[1:]]
    b0.sort()
    return b0[1]
def gcd_list(l):
    return functools.reduce(fractions.gcd, l)
B = itertools.cycle(A)
Bs = itertools.tee(B, 2)
Bs = (list(itertools.islice(B, i, i+n)) for i, B in enumerate(Bs))
Bs = map(search_booby, Bs)
ans = max(Bs)
# output
print(ans)

Submission status: Runtime Error

Solution code:
import copy as cp
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_all(a_list):
    if len(a_list)<1:
      return
    gcd_num = gcd(a_list[0],a_list[1])
    for i in range(2, len(a_list)):
        gcd_num = gcd(gcd_num, a[i])
    return gcd_num

max_gcd = 0
for i in range(N):
    a_cp = cp.copy(a)
    del a_cp[i]
    max_gcd = max(max_gcd, gcd_all(a_cp))
print(max_gcd)

Submission status: Runtime Error

Solution code:
from sys import stdin
from math import gcd



rs = lambda: stdin.readline().strip()
ri = lambda: int(rs())
rsl = lambda: stdin.readline().split()
rim = lambda: map(int, rsl())
ril = lambda: list(rim())


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


def findGCD(lst):
    ret = 1
    for i in range(len(lst)-1):
        ret = max(ret, gcd(lst[i], lst[i+1]))
    return ret


def findLCM(lst):
    ret = max(lst)
    for i in range(len(lst)-1):
        ret = min(ret, lcm(lst[i], lst[i+1]))
        print(lcm(lst[i], lst[i+1]))
    return ret


N = ri()
integers = list(rim())
gc = findGCD(integers)
cnt = 0
for num in integers:
    if num % (gc*2) != 0:
        cnt += 1

if cnt > 1:
    print(gc)
else:
    print(gc*2)

Submission status: Runtime Error

Solution code:
import math
import random

def computeGCD(x, y):
    if x > y:
        small = y
    else:
        small = x
    for i in range(1, small + 1):
        if ((x % i == 0) and (y % i == 0)):
            gcd = i

    return gcd


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

tmpgcd = list()
for i in range(2):
    sample = random.choices(a, k=2)
    tmpgcd.append(computeGCD(sample[0], sample[1]))

# print('hey')

tmpgcd = sorted(tmpgcd)
mini = tmpgcd[1]
# print(mini, tmpgcd)
result = 0
for i in range(mini, -1, -1):
    tmp = [x % i for x in a]
    tmp = [x for x in tmp if x != 0]
    if len(tmp) <= 1:
        result = i
        break

print(result)

Submission status: Runtime Error

Solution code:
import math
import sys

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

if N == 2:
    print(max(A[0], A[1]))
    sys.exit(0)

G1 = [0 for i in range(N)]
G2 = [0 for i in range(N)]

G1[0] = A[0]
G2[N-1] = A[N-1]
#G1[1] = math.gcd(A[0], A[1])
#G2[N-2] = math.gcd(A[-1], A[-2])
for i in range(1, N):
    print(G2[N-i-1], A[N-i-2])
    G1[i] = math.gcd(G1[i-1], A[i])
    G2[N-i-1] = math.gcd(G2[N-i], A[N-i-1])

min_g = max(G1[1], G2[-2])
for i in range(1, N-1):
    print(math.gcd(G1[i-1], G2[i+1]))
    min_g = max(min_g, math.gcd(G1[i-1], G2[i+1]))

print(min_g)

Submission status: Runtime Error

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

import math
from functools import reduce

ans = []

if n == 2:
    a = list(numbers)
    print(max(numbers))

else:
    for i in range(n):
        a = list(numbers)
        a.append(max(a))
        del a[i]
        ans.append(reduce(math.gcd, a))

print(max(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)
    return divisors
  
def check(num, kouho, N, i):
    ret = {}
    for val in kouho.keys():
        if num%val == 0:
            ret[val] = kouho[val] + 1
        else ret[val] == i:
            ret[val] = kouho[val]
        
    return ret
  
N = int(input())
A= list(map(int, input().split()))
pri_flag = True

if N > 4:
    divs = []
    for i in range(3):
    divs.extend(cal_divs(A[i]))
    kouho = {}
    c = collections.Counter(divs)
    for div, n in c.most_common():
    kouho[div] = n

    kouho = {k: v for k, v in kouho.items() if v > 1}

    for i,num in enumerate(A[3:]):
        if len(kouho) == 1:
            print(1)
            pri_flag = False
            break
        kouho = check(num, kouho, N, i+3)
    
    if pri_flag:
        print(max(kouho))
        
else:
    divs = []
    kouho = {}
    for i in range(N):
        divs.extend(cal_divs(A[i]))
        c = collections.Counter(divs)
    for div, n in c.most_common():
        kouho[div] = n
    kouho = {k: v for k, v in kouho.items() if v > N-2}
    print(max(kouho))

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
A=list(set(A))
maxi=10**9
allyp=[]
for i in range(len(A)):
    divesor=[]
    a=A[i]**0.5+1
    for j in range(1,int(a)+1):
        if A[i]%j==0:
            divesor.append(j)
            divesor.append(int(A[i]/j))
    A[i]=divesor
    allyp+=A[i]
    if maxi>int(max(A[i])):
        maxi=int(max(A[i]))
allyp=list(set(allyp))
allyp.sort(reverse=True)
for i in allyp:
    flag=1
    for j in range(len(A)):
        if int(i) not in int(A[j]):
            flag-=1
    if flag >=0:
        print(int(i))
        break

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(int, input().split())
Amin = max(A)
count1 = 1
count2 = 2
count3 = 1

def f(n):
    return n%count2

for i in range(Amin-2):
    A2 = list(map(f, A))
    if sum(A2)==0:
        count1 = count1 * count2
    if A2.count(0)==len(A2-1):
        count3 = min(A2)
    count2 += 1
    
    
    
print(count1*count3)

Submission status: Runtime Error

Solution code:
import numpy as np
N =int(raw_input())
A =map(int ,raw_input().split())

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
def gcd2(A,S):
    r = gcd(A[0],A[1])
    for i in range(len(A)-2):
        while(r>S):
            r = gcd(A[i+2],r)
    return r
S = 0
if len(A) ==2:
    print int(max(A))
else:
    l = int(len(A)/2)
    L = A[:l]
    L2 =A[l:]
    a = gcd2(L,max(A))
    b = gcd2(L2,max(A))
    for i in range(L[0]):
        k = L.pop(i)
        S =max(S,gcd2(L[0],S))
        if b == S:
            break
        A.insert(i,k)
    print int(S)

Submission status: Runtime Error

Solution code:
import itertools
import fractions
N=int(input())
As=list(map(int, input().split()))
ls=list(itertools.combinations(As,N-1))
from functools import reduce
from math import gcd
def gcd(*numbers):

    return reduce(gcd, numbers)
for i in range(len(ls)):
        if gcd(ls[i]) > now:
            now = gcd(ls[i])
print(now)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = np.array([int(x) for x in input().split(' ')])
A.sort()

if N > 2:
    x = []
    for n, m in [tuple(A[0:2]), tuple(A[1:3]), (A[0], A[2])]: 
        while n != 0:
            l = n
            n = m % n
            m = l
        x.append(m)
    x.sort(reverse=True)
else:
    x = [A[-1], 1]

y = x.pop(0)
while y > 1:
    if sum(A % y != 0) < 2:
        break
    for i in range(2, y):
        if y % i == 0:
            y = y / i
            break
    if x[0] == y:
        x.append(1)
        y = x.pop(0)
    elif x[0] > y:
        x.append(y)
        y = x.pop(0)
        x.sort(reverse=True)

print(y)

Submission status: Runtime Error

Solution code:
import fractions

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

a.sort()
f = 0

if n == 2:
    print(a[1])
else:
    f = 0
    gcd = a[0]
    for i in range(1,n-1):
        if f == 2:
            gcd = 1
            break
        else:
            if fractions.gcd(gcd,a[i]) != 1:
                gcd = fractions.gcd(gcd, a[i])
            else:
                f += 1

print(gcd)

Submission status: Runtime Error

Solution code:
import fractions
N = int(input())
A = list(map(int, input().split()))
# まずはA[0]以外のgcdをansとしておく
ans = A[1]
for i in range(2, N):
	ans = fractions.gcd(ans, A[i])
# つぎにA[0]と他の要素の2数のgcdをリストアップし、それが一番小さくなるindexをkとする
G = [A[0]]
for j in range(1, N):
	G.append(fractions.gcd(A[0], A[j]))
k = G.index(min(G))
# A[k]以外のgcdをtmpとしておく
if k == N - 1:
	B = A[: N - 1]
elif K == 0:
	B = A[1:]
else:
	B = A[: k] + A[k + 1:]
tmp = B[0]
for l in range(1, N - 1):
	tmp = fractions.gcd(tmp, B[l])
# ansとtmpの大きい方を出力
print(max(ans, tmp))

Submission status: Runtime Error

Solution code:
import math

N=int(input())
li=list(map(int,input().split()))
lis=li
maxi=li

for x in range(N):
    e=math.gcd(max(li),max(li))
    lis=li
    lis[x]=min(li)
    for i in range(N):
        if x==i:
            continue
        else:
            e=math.gcd(e,lis[i])
    maxi[x]=e

maxer=max(maxi)
print(maxer)

Submission status: Runtime Error

Solution code:
import fractions
import functools
import sys
sys.setrecursionlimit(100000000)

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

if len(a) == 2:
  print(max(a))
  sys.exit()
  
gcd_a = functools.reduce(fractions.gcd, a)
a=[i//gcd_a for i in a]

cnt = 0
gcd_0 = functools.reduce(fractions.gcd, a[1:])
for i in range(1,len(a)):
  if fractions.gcd(a[0],a[i]) == 1:
    so = i
    cnt+=1
    if cnt == 2:
      print(max(gcd_a,gcd_0*gcd_a))
      sys.exit()

a_i = [i for i in a if i != a[so]]
gcd_i = functools.reduce(fractions.gcd, a_i)

print(max(gcd_0,gcd_i)*gcd_a)