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:
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq


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

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

maxX=-1
for i, ai in enumerate(A):
        x=10**20
        l=list(A)
        l0, l1=(l[1][1], l[2][1]) if i == 0 else (l[0][1], l[2][1]) if i == 1 else (l[0][1], l[1][1]) 
        if (3 if i <= 2 else 2) == len(A):
                print("XXX")
                maxX=-1
        else:
                x=math.gcd(l0, l1)
                for (j, lj) in l[(3 if i <= 2 else 2):]:
                        if i != j:
                                x=math.gcd(x, lj)
        maxX=max(x, maxX)
print(maxX)

Submission status: Runtime Error

Solution code:
import math

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


def c(l):
    if len(l) < 3:
        print(max(l[0], l[1]))
        return
    g0 = math.gcd(l[0], l[1])
    g1 = math.gcd(l[1], l[2])
    g2 = math.gcd(l[0], l[2])
    g = max(g0, g1, g2)
    ss = []
    for a in AS:
        if a % g != 0:
            ss.append(a)
    if len(ss) > 1:
        ss.append(g)
        c(ss)
    else:
        print(g)


c(AS)

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:
    print(max(lis))
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:
# -*- coding: utf-8 -*-
import math
import copy

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


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


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

print(max(gcd_array))

Submission status: Runtime Error

Solution code:
# GCD on Blackboard
"""
リストのどの要素を抜いた時に最大公約数が最大値をとるか調べて、
その時の最大公約数を出力する。
"""

from functools import reduce

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


def get_gcd(a, b):
    """
    ユークリッド互除法により最大公約数を求める。
    """
    if a < b:
        a, b = b, a

    elif a % b == 0:
        return b

    return get_gcd(b, a % b)


def get_gcd_l(l):
    """
    リストの要素の最大公約数を求める。
    """
    return reduce(get_gcd, l)


def answer(l):
    """
    どの要素を抜いた時に最大公約数が最大値をとるか調べる。
    """
    len_l = len(l)
    answers = []  # 答えの案

    for i in range(len_l): # 要素を1個ずつ消してみる。
        temp_l = []
        temp_l += l[0 : i]
        temp_l += l[i+1 : len_l]
        answers.append(get_gcd_l(temp_l))
        if i != 0 & answers[i-1] < answers[i]:
            break
    ans = max(answers)
    return ans


def main():
    """
    答えを出力する。
    """
    print(answer(A))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import fractions
import functools

N=int(input())
A=list(map(int,input().split()))
A=sorted(A,reverse=True)
gcdA=functools.reduce(fractions.gcd,A)
ans=gcdA
B=A
for i in range(N):
    num=B[i]
    del B[i]
    gcdB=functools.reduce(fractions.gcd,B) 
    gcd=max(gcdA,gcdB)
    if gcd>ans:
        ans=gcd
        B[i]=num
    else:
        B[i]=num
print(ans)

Submission status: Runtime Error

Solution code:
import math, copy
def gcd(list):
    ans = list[0]
    for i in range(1, len(list)):
        ans = math.gcd(ans, list[i])
    return ans
N = int(input())
A = [int(x) for x in input().split()]
if N == 2:
    print(max(A[0], A[1]))
else:
    tmp = 0
    for i in range(N):
        list = copy.copy(A)
        del list[i]
        if tmp < gcd(list):
            tmp = gcd(list)
    print(tmp)

Submission status: Runtime Error

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

for i in range(1,N+1):
    x = A[-i]
    del A[-i]
    gcd = functools.reduce(math.gcd, A)
    ans = max(gcd,ans)
    A.append(x)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
As = [int(i) for i in input().split()]
import functools
import math
ans = 0
for i in range(n):
    tmpa = As[:i] + As[i + 1:]
    gcd = functools.reduce(math.gcd, tmpa)
    # print(gcd)
    ans =max(ans, gcd)
print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        temp = a % b
        a = b
        b = temp
    return a
def blackbord(n,a):
    return max(list(hcf(a[i],j) for i in range(len(a)) for j in a[0:i] + a[i + 1:]))
n = int(input())
a=list(map(int, input().split()))
print(blackbord(n,a))

Submission status: Runtime Error

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

import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
N=int(input())
A=list(map(int,input().split()))

print(N)
print(A)

print(gcd(27, 18, 9))

Submission status: Runtime Error

Solution code:
import fractions
import itertools
n = int(input())
x = list(map(int,input().split()))
p = list(itertools.combinations(x,len(x)-1))
ar = 0
for n in range(0,len(p)):
    ar=max(fractions.gcd(p[n][0],p[n][1]),ar)

print((ar))

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.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:
A = [int(x) for x in input().split()]
seki = 1

for x in range(2,int(1000000000**0.5)+1):
    count = 0

    for y in range(N):
        if A[y] % x != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = x

for i in range(N):
    count = 0
    if A[i] < 1000000000**0.5+1:
        break
    for j in range(N):
        if A[i] % A[j] != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = A[i]



print(seki)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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

GCD = []
for i in range(N):
    A_copy = []
    for j in range(N):
        if i != j:
            A_copy.append(A[j])
    GCD.append(gcd_list(A_copy))
GCD.append(gcd_list(A))
print(max(GCD))

Submission status: Runtime Error

Solution code:
N = int(input())

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

import math
from functools import reduce

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 0
l = []
for i in range(max(a))[::-1]:
    if len(a) == 2:
        ans = i
        break
    o1 = a[0] % i
    o2 = a[1] % i
    o3 = a[2] % i
    if o1+o2 == 0 or o1+o3 == 0 or o2+o3==0:
        ans = i
        break
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
import functools
import sys

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
for i in range(1,len(a)):
  if fractions.gcd(a[0],a[i]) == 1:
    so = i
    cnt+=1
    if cnt == 2:
      print(gcd_a)
      sys.exit()

gcd_0 = functools.reduce(fractions.gcd, a[1:])
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:
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)

gcds = sorted(gcds)

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

Submission status: Runtime Error

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

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

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

else:
    if gcd(A[0], A[1]) > gcd(A[1], A[2]):
        x = 2
    elif gcd(A[0], A[1]) < gcd(A[1], A[2]):
        x = 0
    elif gcd(A[0], A[2]) > gcd(A[1], A[2]):
        x = 1
    elif gcd(A[0], A[2]) < gcd(A[1], A[2]):
        x = 0
    else:
        A2 = A.copy()
        for i in range(2, N - 1):
            A2[i + 1] = gcd(A2[i], A2[i + 1])
            if A2[i] > A2[i + 1]:
                x = i + 1
                break

    del A[x]
    for i in range(N - 2):
        A[i + 1] = gcd(A[i], A[i + 1])
    print(A[-1])

Submission status: Runtime Error

Solution code:
import numpy as np

def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def split_a(n, alist):
    curr = 0
    for i in range(n):
        ar1 = alist[:i]
        ar2 = alist[i+1:]

        temp = mygcd(ar1, ar2)
        if curr < temp:
            curr = temp

    return curr


def mygcd(ar1, ar2):
    if not ar1:
        return np.gcd.reduce(ar2)

    if not ar2:
        return np.gcd.reduce(ar1)

    return np.gcd.reduce(ar1 + ar2)

if __name__ == '__main__':
    n, alist = read_input()
    print(split_a(n, alist))

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()]
st = time()
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)

print(interim_max)

Submission status: Runtime Error

Solution code:
import math

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


def c(l):
    if len(l) < 3:
        print(max(l[0], l[1]))
        return
    g0 = math.gcd(l[0], l[1])
    g1 = math.gcd(l[1], l[2])
    g2 = math.gcd(l[0], l[2])
    g = max(g0, g1, g2)
    ss = []
    for a in AS:
        if a % g != 0:
            ss.append(a)
    if len(ss) > 1:
        c([g, *ss])
    else:
        print(g)


c(AS)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

n=int(input())
array = list(map(int, input().split())) 
array=list(set(array))
array.sort(reverse=True)


max=-100

for i in range(n):
    copy_array=array.copy()
    if(max>array[i]):
        break
    copy_array.pop(i)
    tmp_gcd=gcd(*copy_array)
    # print(copy_array)
    if(max<tmp_gcd):
        max=tmp_gcd
    
print(max)

Submission status: Runtime Error

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

i=2
b=[1]#a=0
c=[1]
d=[]
while True:
    a = 0
    for j in range(N):
        if A[j] % i != 0:
            a += 1
        if a > 1:
            d.append(i) #black list
            break

    print(i,A,a)

    if a == 0:
        b.append(i) #white list
        for j in range(len(A)):
            A[j] = int(A[j] / i)
        i = 2
    if a == 1:
        c.append(i) #gray list
    if a > 0:
        i += 1
    
    k=0
    while True:
        if k >= len(d):
            break
        if i % d[k] == 0:
            i += 1
            k = -1
        k += 1


    if i > min(A):
        break

bs = 1
for i in range(len(b)):
    bs *= b[i]
print(bs * max(c))

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 fraction
from functools import reduce



def gcd_list(numbers):
    return reduce(fractions.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:
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:
    print(gcd(lis[0],lis[1]))
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:
# -*- coding: utf-8 -*-
n = int(input())

a = list(map(int, input().split()))
box = [0]*10**6

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:
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 = []
  max_list.append(array_euclid(a[:]))
  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:
def euclid(a,b):
    if a%b == 0:
        return b
    else:
        return euclid(b,a-b)

def solve():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort(reverse=False)
    value=1
    before=1
    for i in range(len(A)):
      for j in range(i+1,len(A)):
        _value = euclid(A[j],A[i])
        if value < _value:
          before=value
          value=_value
          
    print(max(before,value))


solve()

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))
a=[i for i in a if i != 0]
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 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 : 
      x = A[0]
    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:
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        temp = a % b
        a = b
        b = temp
    return a



def blackbord(n,a):
    if n==2 and a[0]==a[1]:
        return a[0]
    else:
        return max(list(hcf(a[i],j) for i in range(len(a)) for j in a[0:i] + a[i + 1:]))
n = int(input())
a=list(map(int, input().split()))
print(blackbord(n,a))

Submission status: Runtime Error

Solution code:
import math

def gcdlist(numlist):
    l = len(numlist)
    re = math.gcd(numlist[0], numlist[1])
    for i in range(2,l):
        re = math.gcd(re, numlist[i])
    return re

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

ans = 0

maxA = max(Alist)
for i in range(N):
    Ai = Alist[i]
    Alist[i] = maxA
    Agcd = gcdlist(Alist)
    if ans < Agcd:
        ans = Agcd
    Alist[i] = Ai

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=input().split()
a=[int(i) for i in a]
b=max(a)
c=max(a)-min(a)

if n==2:
    print(b)
    exit()

for i in range(b,0,-1):
    count=0
    for j in range(n):
        if a[j]%c==0:
            count+=1
    if count>=n-1:
        print(c)
        exit()

print(1)

Submission status: Runtime Error

Solution code:
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq


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

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

maxX=-1
for i, ai in enumerate(A):
        x=10**20
        l=list(A)
        l0, l1=(l[1][1], l[2][1]) if i == 0 else (l[0][1], l[2][1]) if i == 1 else (l[0][1], l[1][1]) 

        x=math.gcd(l0, l1)
        for (j, lj) in l[(3 if i <= 2 else 2):]:
                if i != j:
                        x=math.gcd(x, lj)
        maxX=max(x, maxX)
print(maxX)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
x = [0] * N
y = [0] * N
tmp = A[0]
for i in range(1, N):
    t = math.gcd(tmp, A[i])
    x[i] = int(tmp / t)
    tmp = t
tmp = A[N - 1]
for i in range(N - 2, -1, -1):
    t = math.gcd(tmp, A[i])
    y[i] =  int(tmp / t)
    tmp = t
m = 0
for i in range(1, N - 1):
    a = math.gcd(x[i], y[i])
    if m < a:
        m = a
print(tmp * max(m, y[0], x[N - 1]))

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] * n

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 = 0
    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 math

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

for i in range(n):
    for j in range(n-1):
        if j != i and j != i-1:
            rec = math.gcd(a[j], a[j+1])
            if gmax > rec:
                break
            else:
                gmax = rec
        elif j == i-1 and j < n-2:
            rec = math.gcd(a[j], a[j+2])
            if gmax > rec:
                break
            else:
                gmax = rec

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

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

n=int(input())
array = list(map(int, input().split())) 
# array=list(set(array))
array.sort(reverse=True)


max=-100

for i in range(n):
    copy_array=array.copy()
    if(max>array[i]):
        break
    copy_array.pop(i)
    tmp_gcd=gcd(*copy_array)
    # print(copy_array)
    if(max<tmp_gcd):
        max=tmp_gcd
    
print(max)





############################################################################


import fractions
from functools import reduce
 
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
 
n=int(input())
array = list(map(int, input().split())) 
array=list(set(array))
array.sort(reverse=True)
 
 
max=-100
 
for i in range(n):
    copy_array=array.copy()
    if(max>array[i]):
        break
    copy_array.pop(i)
    tmp_gcd=gcd(*copy_array)
    # print(copy_array)
    if(max<tmp_gcd):
        max=tmp_gcd
    
print(max)

Submission status: Runtime Error

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


def gcd(vs):
    while True:
        m = min(vs)
        vs = [v % m for v in vs if v % m != 0] + [m]
        if len(vs) == 1:
            return vs[0]


gcds = []
As = list(set(As))
for i in range(len(As)):
    gcds.append(gcd(As[:i] + As[i + 1:]))

print(max(gcds))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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

GCD = []
for i in range(N):
    A_copy = []
    for j in range(N):
        if i != j:
            A_copy.append(A[j])
    GCD.append(gcd_list(A_copy))

print(max(GCD))

Submission status: Runtime Error

Solution code:
import numpy as np
huga = list(map(int, input().split()))
unchi=list(map(int, input().split()))
n=len(unchi)

import sys
if n==2:
  if unchi[0]>=unchi[1]:
    print(unchi[0])
    sys.exit()
  else:
    print(unchi[1])
    sys.exit()    
import numba

@numba.jit
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)
kouyaku=1
geri =[[0 for i in range(n)] for j in range(n)]
for i in range(0,n):
  for j in range(n):
    geri[i][j]=unchi[j]


    
for i in range(n):
  sore=geri[i]
  sore.pop(i)
  if len(sore)==2:
    u=gcd(sore[0],sore[1])
  else:
    u=sore[0]
    for j in range(1,len(sore)):
      u=gcd(u,sore[j])

  if u>=kouyaku:
  	kouyaku=u
print(kouyaku)

Submission status: Runtime Error

Solution code:
import math
import numpy as np
n=int(input())
a=[int(i) for i in input().split()]
a=list(set(a))
n=len(a)

ans=0
if n<3: print(max(a))
else:
    for i in range(n):
        b=np.array([x for x in a if not x==a[i]])
        while len(b)>1:
            d=math.gcd(b[0],b[1])
            b=np.delete(b,0)
            b[0]=d
        c=b[0]
        if ans<c: ans=c
    print(ans)

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:
from copy import deepcopy
import fractions
from functools import reduce
 
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
  
# 整数の入力
a = int(input())
# 数値のリスト化
xList = [int(i) for i in input().split()]
keisanList = deepcopy(xList)
saidai = max(xList)
saidaiKoyakuSu = 0
koyakuSu = 0
listIndex = 0

for i in range(a):
    keisanList = copy.deepcopy(xList)
    keisanList[i] = saidai
    koyakuSu = gcd_list(keisanList)
    if(saidaiKoyakuSu < koyakuSu):
        saidaiKoyakuSu = koyakuSu
    if(koyakuSu >= keisanList[i]):
        break
print(saidaiKoyakuSu)

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:
    gcds = []
    for i in range(len(A)-1):
        if i == 0:
            gcds.append(gcd(A[0],A[1]))
        else:
            gcds.append(gcd(gcds[-1],A[i]))
    gcds = np.asarray(gcds)
    
    index = []
    for idx,n in enumerate(gcds.min() == gcds):
        if n==True:
            index.append(idx)
    a = []
    for i in index:
        if i+1 in index:
            None
        else:
            a.append(i+1)
    for i in a:
        index.append(i)
    gcds = []
    for idx in index:
        A_temp = copy.deepcopy(A)
        A_temp.pop(idx)
        gcds_temp = []
        for i in range(len(A_temp)-1):
            if i ==0:
                gcds_temp.append(gcd(A_temp[0],A_temp[1]))
            else:
                gcds_temp.append(gcd(gcds_temp[-1],A_temp[i]))
        gcds.append(min(gcds_temp))
    print(max(gcds))

Submission status: Runtime Error

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

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

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

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

        tmp = math.gcd(A[index[0]], A[index[1]])
        for j in range(n-1):
            tmp = math.gcd(tmp ,A[index[j]])

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

Submission status: Runtime Error

Solution code:
import math

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

A_list.append(A_list[0])

minValue = 9999999999
secondValue = 9999999999
secondCount = 0
thirdValue = 9999999999

for i in range(N):
    v = A_list[i]
    w = A_list[i+1]
    result = math.gcd(v, w)
    if minValue > result:
        minValue = result
        minIndex = i
    elif secondValue > result:
        thirdValue = secondValue
        secondValue = result
        secondIndex = i
        secondCount = 1
    elif secondValue == result:
        secondCount += 1
    elif thirdValue > result:
        thirdValue = result

if len(A_list) == 3:
    ans = math.gcd(A_list[0], A_list[1])
elif secondCount == 1 and (abs(minIndex - secondIndex) == 1 or abs(minIndex - secondIndex) == N-1):
    ans = thirdValue
else:
    ans = secondValue

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def split_a(n, alist):
    curr = 0
    for i in range(n):
        ar1 = alist[:i]
        ar2 = alist[i+1:]

        temp = mygcd(ar1, ar2)
        if curr < temp:
            curr = temp

    print(curr)


def mygcd(ar1, ar2):
    if not ar1:
        return np.gcd.reduce(ar2)

    if not ar2:
        return np.gcd.reduce(ar1)

    return np.gcd.reduce(ar1 + ar2)

if __name__ == '__main__':
    n, alist = read_input()
    split_a(n, alist)

Submission status: Runtime Error

Solution code:
    N = int(input())
    A_list = input().split()
    A_list_i = [int(s, 0) for s in A_list]
    max_gcd = 1
    min_gcd = [10000000000, -1]
    for i in range(N-1):
        for j in range(i+1, N):
            if A_list_i[i] == A_list_i[j]:
                temp = A_list_i[i]
            elif A_list_i[i] > A_list_i[j]:
                temp = A_list_i[i] % A_list_i[j]
            else:
                temp = A_list_i[j] % A_list_i[i]
            if temp > max_gcd:
                max_gcd = temp
            if temp < min_gcd[0]:
                min_gcd[0] = temp
                if A_list_i[i] > A_list_i[j]:
                    min_gcd[1] = i
                else:
                    min_gcd[1] = j
    A_list_i[min_gcd[1]] = max_gcd
    temp = 0
    max_gcd = 1
    for i in range(N-1):
        for j in range(i+1, N):
            if A_list_i[i] == A_list_i[j]:
                temp = A_list_i[i]
            elif A_list_i[i] > A_list_i[j]:
                temp = A_list_i[i] % A_list_i[j]
            else:
                temp = A_list_i[j] % A_list_i[i]
            if temp > max_gcd:
                max_gcd = temp            
    print('%d' % max_gcd)

Submission status: Runtime Error

Solution code:
import math

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:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
Als = [int(x) for x in input().split()]

import fraction
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 = list(map(int,input().split()))

l = []
for i in range(n):
    for j in range(1,A[i]):
        if A[i] % j == 0:
            l.append(j)
L = []
for k in range(min(A)):
    if l.count(k) == n-1:
        L.append(k)
if n == 2:
    print(max(A))
else:        
    print(max(L))