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
from functools import reduce
n = int(input())
a = input().split()
a = [int(i) for i in a]
b = []
if n > 2:
    for i in range(n):
        f = a[i]
        e = [x for x in a if x != f]
        b.append(reduce(math.gcd, e))
    print(max(b))
else:
    print(reduce(math.gcd, a))

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

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

print(max(ans_list))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

import fraction
from functools import reduce

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

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

print(max(dp))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

gcd = gcd_list(A)

for i in range(N):
    for j in range(10^9):
        A[i] = j
        if gcd_list(A) > gcd:
            gcd = gcd_list(A)
        else :
            pass

print(gcd)

Submission status: Runtime Error

Solution code:
# Correct, but it takes too long time
from functools import reduce
import math

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

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

l = set()
for i in range(n):
    a_reduced = a[:i] + a[i+1:]
    l.add(gcd_mul(*a_reduced))

print(max(l))

Submission status: Runtime Error

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

def ngcd(li):
    temp=gcd(li[0], li[1])
    if len(li)-3 >=0:
        for i in range(len(li)-2):
            temp=gcd(temp, li[i+2])
    return temp
    """

import math
from functools import reduce

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

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

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

t=a[0]
t2=a[1]
out=0
f=1
min=10**9+1
for i in range(0, len(a)):
  gcd2=gcd(t, a[i])
  if gcd2<min:
    min=gcd2
    out=i
    #print(t, a[i],out, min)
"""
min=10**9+1
for i in range(0, len(a)):
  gcd2=gcd(t2, a[i])
  if gcd2<min:
    min=gcd2
    out=i
    print(t2, a[i],out, min)


print(out)
"""

"""
  if not (a[i]%t==0 or t %a[i]==0):
    if f:
      out=i
      f=0
    elif not f:
      out=0
"""
if not len(a)==2:
  temp=a[0:out]
  temp.extend(a[out+1:])
  #print(temp)
  itemp=ngcd(temp)
  itemp2=ngcd(a[1:])
  #print(itemp, itemp2)
  print(max(itemp, itemp2))
else:
  print(max(a[0], a[1]))


"""
max=0
for i in range(len(a)):
    temp=a[0:i]
    temp.extend(a[i+1:])
    itemp=ngcd(temp)
    if max < itemp:
        max=itemp

print(max)
"""

Submission status: Runtime Error

Solution code:
n = input()
lst = [int(s) for s in input().split()]

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

def gcdm(*arg):
    if len(arg) == 2:
        return gcd(*arg)
    arg = list(arg)
    a = arg.pop()
    b = arg.pop()
    return gcdm(gcd(a,b), *arg)

res = list()
if len(lst) == 2:
    res.append(gcd(*lst))
else:
    for i in range(len(lst)):
        temp=lst.pop(i)
        res.append(gcdm(*lst))
        lst.insert(i,temp)
print(max(res))

Submission status: Runtime Error

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


def gcd_lis(l):
    res = 0
    for i in range(len(l)-1):
        if i == 0:
            res = gcd(l[i],l[i+1])
        else:
            res = gcd(res,l[i+1])
    return res

def gcd_lis2(l):
    tmpd = copy.deepcopy(l)
    if len(l) == 1:
        return l[0]
    else:
        tmpd.append(gcd(tmpd.pop(),tmpd.pop()))
        return gcd_lis2(tmpd)

n = int(input())
lis = list(map(int,input().split()))
lis = list(set(lis))
reslis = []
reslis.append(gcd_lis2(lis))
if len(lis) == 1:
    print(lis[0])
elif len(lis) != 2:
    for i in range(n):
        tmp = copy.deepcopy(lis)
        del tmp[i]
        reslis.append(gcd_lis2(tmp))
    print(max(reslis))

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)):
        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=max(A[i])
allyp=list(set(allyp))
allyp.sort(reverse=True)
for i in allyp:
    flag=1
    for j in range(N):
        if i not in A[j]:
            flag-=1
    if flag >=0:
        print(i)
        break

Submission status: Runtime Error

Solution code:
import math

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

for i in range(n):
    if i == 0:
        b = a[1:]
    elif i == n-1:
        b = a[:n-1]
    else:
        tmp1 = a[:i]
        tmp2 = a[i+1:]
        b = []
        b.extend(tmp1)
        b.extend(tmp2)
    current = b[0]
    for j in range(n-1):
        current = math.gcd(current, b[j])
    if max < current:
        max = current
print(max)

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):
    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:
import math
from functools import reduce

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

N=int(input())
A=list(map(int,input().split()))
B=A[:]
maxi=gcd(A)
for i in range(N):
    for j in range(gcd(A),max(A)+1):
        B[i]=j
        #print("{} {}".format(B,gcd(B)))
        if(maxi<gcd(B)):
            maxi=gcd(B)
    B=A
    
print(maxi)

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 = [int(x) for x in input().split()]
AA = []
for i in A:
    if(not i in AA):
        AA+=[i]
AA.sort()
cand = -1
mingcd = gcd_list(AA)
if(len(AA)==2):
    print(max(AA))
else:
    for i in range(len(AA)-1):
        if(mingcd==gcd(AA[i],AA[i+1])):
            if(i<len(AA)-2):
                if(mingcd==gcd(AA[i],AA[i+2])):
                    cand = i
                else:
                    cand = i+1
                break
            else:
                cand = i+1
    if(cand==-1):
        cand = len(AA)-1
    print(gcd_list(AA[:cand]+AA[cand+1:]))

Submission status: Runtime Error

Solution code:
import math, copy

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

dp = [a[1], a[0], math.gcd(a[0], a[1])]
for i in range(2, n):
    for j in range(i+1):
        if j != i:
            dp[j] = math.gcd(a[i], dp[j])
    dp += [math.gcd(a[i], dp[i])]


print(max(dp))

Submission status: Runtime Error

Solution code:
import math
import itertools
from functools import reduce

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



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


c = itertools.combinations(A, N-1)

a_max = gcd(*A)
for i in c:
    a_max = max(a_max, gcd(*list(i)))

print(a_max)

Submission status: Runtime Error

Solution code:
import fractions

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

kouho = [a[0]]

for i in range(n - 1):
    hoge = []
    for j in range(len(kouho)):
        hoge.append(fractions.gcd(a[i + 1], kouho[j]))
    if min(kouho) == max(hoge):
        kouho = [max(hoge)]
    """
    elif len(hoge) == 1:
        kouho = [hoge[0], kouho[0]]
    """
    else:
        kouho = hoge

a1 = max(kouho)

a[0], a[1] = a[1], a[0]

kouho = [a[0]]

for i in range(n - 1):
    hoge = []
    for j in range(len(kouho)):
        hoge.append(fractions.gcd(a[i + 1], kouho[j]))
    if min(kouho) == max(hoge):
        kouho = [max(hoge)]
    """
    elif len(hoge) == 1:
        kouho = [hoge[0], kouho[0]]
    """
    else:
        kouho = hoge

a2 = max(kouho)

print(max(a1, a2))

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)
  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):
    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:
import math
from functools import reduce


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


if __name__ == '__main__':
    max = 0

    N = int(input())

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

    for i in range(N):
        A_ = A[:]
        A_.pop(i)
        A_without_ith = A_
        gcd_ = gcd(*A_without_ith)
        max = gcd_ if gcd_ > max else max

    print(max)

Submission status: Runtime Error

Solution code:
def fermat(n):
    if n % 2 == 0:
        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)))
for _ in range(30000):
    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:
import math
import os
import random
import re
import sys
from collections import defaultdict


def  gcd(x, y):
    while(y):
        x, y = y, x%y
    return x

def second_smallest(numbers):
    m1, m2 = float('inf'), float('inf')
    for x in numbers:
        if x <= m1:
            m1, m2 = x, m1
        elif x < m2:
            m2 = x
    return m2

def solve(n, a):
    if n < 1:
        return 0
    if n == 1:
        return a[0]
    if n == 2:
        return gcd(a[0], a[1])

    dp = [False for _ in range(int(second_smallest(a)) + 1)]

    gcd0 = gcd(a[0], a[1])
    dp[gcd0] = True
    gcd1 = gcd(gcd0, a[2])
    if gcd1 == gcd0:
        zero = gcd(a[1], a[2])
        one = gcd(a[0], a[2])
        if zero > one:
            dp[zero] = True
            gcd0 = zero
        else:
            dp[one] = True
            gcd0 = one
    dp[gcd0] = True
    for i in range(1,n):
        gcd0 = gcd(gcd0, a[i])
        dp[gcd0] = True

    count = 0
    start = 0
    for i in range(len(dp)):
        if dp[i] == True:
            start = i
            break
    if start == len(dp):
        return start
    for i in range(start+1, len(dp)):
        if dp[i] == True:
            return i
    return start

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    print(solve(n,a))

Submission status: Runtime Error

Solution code:
from copy import copy
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 = list(set(a))

gcds = []
for i in range(len(a)):
	temp = copy(a)
	temp.pop(i)

	num1 = temp[0]
	num2 = temp[1]
	result = gcd(num1, num2)
	for j in range(2, len(temp)):
		if result in gcds:
			break
		result = gcd(result, temp[j])
	
	if result not in gcds:
		gcds.append(result)

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = sorted([int(i) for i in input().split()])
ma = A[1]
nums = []
waru = []
for i in range(2,ma+1):
    for n in nums:
        if i%n==0:
            nums.append(i)
            break
    tof = [a%i==0 for a in A]
    if sum(tof)>=N-1:
        waru.append(i)
    nums.append(i)
print(waru[-1])

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
import math
N = int(input())
A = list(map(int, input().split()))
A.sort()

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)

    divisors.sort(reverse=True)
    return divisors

if N == 2:
    print(max(A))
else:
    min1 = min(A)
    div1 = make_divisors(min1)
    c = 0
    for i in div1:
        for a in A:
            if a % i == 0:
                c += 1
        if c == N-1 or c == N:
            g = i
            break
        c = 0

    m = 0
    for i in range(1, N-1):
        gcd = math.gcd(A[i], A[i+1])
        if gcd > m:
            m = gcd
    print(max(g, m))

Submission status: Runtime Error

Solution code:
from collections import deque

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


import fractions
from functools import reduce

ans=0
GCD_target=gcd_list(A)
#print("GCD_target = {}".format(GCD_target))

for i in range(N):
   #copied_A = A[:]
   remove=A.popleft()
   proc=lambda x: reduce(fractions.gcd, x)
   GCD_current= proc(list(A)) #gcd_list(list(A))
   A.append(remove)
   #print(GCD_current)
   ans=max(ans,GCD_current)

print(ans)

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
Als = [int(x) for x in input().split()]

import math
from functools import reduce



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



a = []
for i in range(N):
    Als2 = Als[:]
    Als2.pop(i)
    a.append(gcd_list(Als2)) 

print(max(a))

Submission status: Runtime Error

Solution code:
n = int(input())

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

# n が 2なら 大きい方を出力して終わり

def euclid(m, n):
  if n == 0:
    return m
  new_m = n
  new_n = m % n
  return euclid(new_m, new_n)

def array_euclid(numbers):
  n = len(numbers)
  v = numbers[n-1] % numbers[n-2]
  if v == 0:
    if n == 2:
      return numbers[0]
    
    numbers.pop()
    return array_euclid(numbers)

  numbers[n-1] = numbers[n-2]
  numbers[n-2] = v
  return array_euclid(numbers)

#print(array_euclid(a))

if n == 2:
  print(euclid(a[0], a[1]))
if n > 2:
  max_list = []
  for i in range(n):
    a2 = a[:]
    a2.pop(i)
    max_list.append(array_euclid(a2))
  print(max(max_list))



# n が3になるまでやって、大きい方が答え？

#for i in range(n-1):


#print(euclid(a[0],a[1]))

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:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
box = [0]*10**5

def make_divisors(k):
    divisors = []
    for i in range(1, int(k**0.5)+1):
        if k % i == 0:
            divisors.append(i)
            if i != k // i:
                divisors.append(k//i)
    return divisors
for i in a:
    for j in make_divisors(i):
        box[100000-j]+=1 
if n-1 in box:
    print(100000 - box.index(n-1))
else:
    print(100000 - box.index(n))

Submission status: Runtime Error

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

n=int(input())
v=[int(x) for x in input().split()]
b=0
c=int(min(v))
d=int(min(v))
e=0
f=0
for i in range(n):
    if v[i] !=c:
      l=fractions.gcd(c,v[i])
      if l==1:
        b +=1
      else:l>1 and l<d
        e=d
        d=l
if b>2:
  print(1)
else:
  print(int(e))

Submission status: Runtime Error

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

N = input()
As =  list(map(int, input().split()))
sorted(As, reverse=True)
ans = As[0]
r = []
for a in As[1:]:
  r.append(gcd(ans, a))
c = 0
res = []
for r1 in sorted(list(r), reverse = True):
  t = True
  c = 0
  for a in As:
    if(a % r1 != 0):
      c += 1
      if(c == 2):
        t = False
        break
  if(t):
    res.append(r1)
  if(len(res) > 2):
    break
if(len(res) < 2):
  print(res[0])
else:
  print(sorted(res)[1])

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

print(y)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

n = int(input())
an = list(map(int, input().split()))
cpn = an
i = 0
j = 0
ans = 1
tmp = 0


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


for j in range(n):
    i = 0
    for i in range(n):
        if gcd_list(cpn) > ans:
            ans = gcd_list(cpn)
        tmp = cpn[i]
        cpn[i] = cpn[i] - (j + 1)
        if gcd_list(cpn) > ans:
            ans = gcd_list(cpn)
        cpn[i] = tmp

print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

gcd = gcd_list(A)

for i in range(N):
    for j in range(10^9):
            A[i] = j
            if gcd_list(A) > gcd:
                gcd = gcd_list(a)
            else :
                pass

print(gcd)

Submission status: Runtime Error

Solution code:
import fractions

N = int( input() )
A = list( map( int ,input().split()) )
Al = []
if len(A) >= 4:
    for lop in range(3,len(A),4):
        A1 = fractions.gcd(A[lop-3],A[lop-2])
        A2 = fractions.gcd(A[lop-3],A[lop-1])
        A3 = fractions.gcd(A[lop-3],A[lop])
        A4 = fractions.gcd(A[lop-2],A[lop-1])
        A5 = fractions.gcd(A[lop-2],A[lop])
        A6 = fractions.gcd(A[lop-1],A[lop])
        Al.append(max(A1,A2,A3,A4,A5,A6))
    if len(A) % 4 > 0:
        A1 = fractions.gcd(A[len(A)-3],A[len(A)-2])
        A2 = fractions.gcd(A[len(A)-3],A[len(A)-1])
        A3 = fractions.gcd(A[len(A)-3],A[len(A)])
        A4 = fractions.gcd(A[len(A)-2],A[len(A)-1])
        A5 = fractions.gcd(A[len(A)-2],A[len(A)])
        A6 = fractions.gcd(A[len(A)-1],A[len(A)])
        Al.append(max(A1,A2,A3,A4,A5,A6))
    print(min(Al))
elif len(A) == 3:
    A1 = fractions.gcd(A[0],A[1])
    A2 = fractions.gcd(A[0],A[2])
    A3 = fractions.gcd(A[1],A[2])
    print(max(A1,A2,A3))
else:
    print(max(A))

Submission status: Runtime Error

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

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)

    # divisors.sort()
    return divisors

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

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

else:
    pn = primes(max(A))
    ans_num = 0
    ans = 1
    for i in pn:
        count = 0
        for j in range(N):
            if A[j] % i != 0:
                count += 1
        
        if count < N-1:
            ans *= i


    print(str(ans))

Submission status: Runtime Error

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


def gcd_lis(l):
    res = 0
    for i in range(len(l)-1):
        if i == 0:
            res = gcd(l[i],l[i+1])
        else:
            res = gcd(res,l[i+1])
    return res

def gcd_lis2(l):
    tmpd = copy.deepcopy(l)
    if len(l) == 1:
        return l[0]
    else:
        tmpd.append(gcd(tmpd.pop(),tmpd.pop()))
        return gcd_lis2(tmpd)

n = int(input())
lis = list(map(int,input().split()))
lis = list(set(lis))
reslis = []
reslis.append(gcd_lis2(lis))
if len(lis) != 2:
    for i in range(n):
        tmp = copy.deepcopy(lis)
        del tmp[i]
        reslis.append(gcd_lis2(tmp))
    print(max(reslis))
elif len(lis) == 1:
    print(lis[0])

Submission status: Runtime Error

Solution code:
from functools import reduce
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 = reduce(math.gcd, B)
  if g > num:
    num = g
    
print(num)

Submission status: Runtime Error

Solution code:
from collections import Counter
from functools import reduce
import copy
import bisect
import fractions
import math
import statistics
import sys
import time
from sympy import isprime
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # Greatest Common Divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # Least Common Multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


n = II()
# a = LI()
a = sorted(LI())
maxi = -INF
ans = 1

for i in range(n):
    if isprime(a[i]) == True:
        del a[i]
        print(GCD_LIST(a))
        exit()

while True:
    div = GCD_LIST(a)
    a = list(map(lambda x: x // div , a))
    if div == 1:
        for j in range(n):
            if isprime(a[j]) == True or 1 in a:
                    del a[j]
                    print(ans * GCD_LIST(a))
                    exit()
        del a[0]
        print(ans * GCD_LIST(a))
        exit()
        
    ans *= div

# test = [i for i in range(100000)]
# start = time.time()
# print(GCD_LIST(test))
# for i in range(n):
#     tmp = copy.copy(a) 
#     del tmp[i]
#     maxi = max(maxi,GCD_LIST(tmp))
# print(maxi)


#for i in range(len(test)):
#    tmp = copy.copy(test) 
#    del tmp[i]
#    maxi = max(maxi,GCD_LIST(tmp))
#    print(i)
#print(maxi)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
count = 0
B = []
b = 0

A.sort()
b = A[0]

while True:

    if len(A) == 1:
        break
    
    else:
        for i in range(len(A)):
            A[i] = A[i] % b
        
        A = set(A)
        A = list(A)
    
        for j in range(len(A)):
                if int(A[j]) != 0:
                    B.append(int(A[j]))
    
        B.sort()
    
        b = B[0]
        b_max = B[-1]


print(b_max)

Submission status: Runtime Error

Solution code:
import fractions
import itertools

def gcd_list(list_,n):
  if n == len(list_)-2:
    #print("return!")
    #print(list_[n],list_[n+1])
    return fractions.gcd(list_[n],list_[n+1])
  #print(list_[n])
  gcd_max = fractions.gcd(list_[n],gcd_list(list_,n+1))
  return gcd_max

N = int(input())
A_ = list(map(int,input().split()))
A_list = list(itertools.combinations(A_,N-1))
#print(A_list)
gcd_max = 0

if N > 2:
  for i in A_list:
    tmp = gcd_list(i,0)
    if gcd_max < tmp:
      gcd_max = tmp
else:
  gcd_max = max(A_)
print(gcd_max)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
box = [0]*10**5
def make_divisors(k):
    divisors = []
    for i in range(1, int(k**0.5)+1):
        if k % i == 0:
            divisors.append(i)
            if i != k // i:
                divisors.append(k//i)

    # divisors.sort()
    return divisors
for i in a:
    for j in make_divisors(i):
        box[100000-j]+=1 
if n-1 in box:
    print(100000-box.index(n-1))
else:
  
    print(100000 - box.index(n))

Submission status: Runtime Error

Solution code:
def saidai(a,b):
    amari = a % b
    if amari != 0:
        return saidai(b,amari)
    else:
        return b
def saidai_f(a):
    a.sort(reverse=True)
    if len(a) == 1:
        return a[0]
    a.insert(0,saidai(a.pop(0),a.pop(0)))
    return saidai_f(a)

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

a=list(set(a))
for i in range(n):
    for ii in range(n):
        if i!=ii:
            hoge.append(a[ii])
    hoge.sort(reverse=True)
    ans.append(saidai_f(hoge))
    hoge=[]
ans.sort(reverse=True)
print(ans[0])

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

N=int(input())
A=list(map(int,input().split()))
B=A[:]
maxi=gcd(A)
for i in range(N):
    for j in range(1,max(A)+1):
        B[i]=j
        #print("{} {}".format(B,gcd(B)))
        if(maxi<gcd(B)):
            maxi=gcd(B)
    B=A
    
print(maxi)

Submission status: Runtime Error

Solution code:
import fractions

N = int( input() )
A = list( map( int ,input().split()) )
Al = []
if len(A) >= 3:
    for lop in range(3,len(A),4):
        A1 = fractions.gcd(A[lop-3],A[lop-2])
        A2 = fractions.gcd(A[lop-3],A[lop-1])
        A3 = fractions.gcd(A[lop-3],A[lop])
        A4 = fractions.gcd(A[lop-2],A[lop-1])
        A5 = fractions.gcd(A[lop-2],A[lop])
        A6 = fractions.gcd(A[lop-1],A[lop])
        Al.append(max(A1,A2,A3,A4,A5,A6))
    if len(A) % 4 > 0:
        A1 = fractions.gcd(A[len(A)-3],A[len(A)-2])
        A2 = fractions.gcd(A[len(A)-3],A[len(A)-1])
        A3 = fractions.gcd(A[len(A)-3],A[len(A)])
        A4 = fractions.gcd(A[len(A)-2],A[len(A)-1])
        A5 = fractions.gcd(A[len(A)-2],A[len(A)])
        A6 = fractions.gcd(A[len(A)-1],A[len(A)])
        Al.append(max(A1,A2,A3,A4,A5,A6))
    print(min(Al))
elif len(A) == 3:
    A1 = fractions.gcd(A[0],A[1])
    A2 = fractions.gcd(A[0],A[2])
    A3 = fractions.gcd(A[1],A[2])
    print(max(A1,A2,A3))
else:
    print(max(A))

Submission status: Runtime Error

Solution code:
from functools import reduce
from math import gcd

n=int(input())
a_s=list(map(int,input().split()))
mx=0
for i in range(n):
    b=a_s[:i]+a_s[i+1:]
    g=reduce(gcd,b)
    if g>mx:
        mx=g
print(mx)

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

print(y)

Submission status: Runtime Error

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
j=0
f=0
X = (N*(N-1))//2
v = [0] * X

def gcd(c,d):
        while d!=0:
            c,d=d,c%d
        return c

i=0

for i in range(N):
    for k in range(N):
        j = i+1
        if i+1 > N-1:
            j=0

    c = a[i]
    d = a[j]
    
    v[i] = gcd(c,d)
    f = v[i]

for i in range(len(v)-1):
    if v[i+1]>v[i]:
        f=v[i+1]



print(f)

Submission status: Runtime Error

Solution code:
n = input()
lst = [int(s) for s in input().split()]

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

def gcdm(*arg):
    if len(arg) <= 1:
        return arg[0]
    arg = list(arg)
    a = arg.pop()
    b = arg.pop()
    return gcdm(gcd(a,b), *arg)

res = list()
if len(lst) == 2:
    res.append(gcd(*lst))
for i in range(len(lst)):
    temp=lst.pop(i)
    res.append(gcdm(*lst))
    lst.insert(i,temp)
print(max(res))

Submission status: Runtime Error

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

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


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


def calc_gcd(arr):
    if len(arr) <= 0:
        return 0
    arr2 = copy.copy(arr)
    return gcd(calc_gcd(arr2[:len(arr)-1]), arr[-1])


ans = 1

B = copy.copy(A)

gcd_array = []
for i in range(N):
    B.pop(i)
    gcd_array.append(calc_gcd(B))
    B = copy.copy(A)

print(max(gcd_array))

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


N = ri()
integers = list(rim())

lowest = [float('-inf'), float('-inf')]
for i in range(len(integers)-1):
    for j in range(i+1, len(integers)):
        temp = gcd(integers[i], integers[j])
        if temp > min(lowest):
            lowest[lowest.index(min(lowest))] = temp

print(max(lowest))