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:
# -*- coding: utf-8 -*-
# # 整数の入力
# a = int(input())
# # スペース区切りの整数の入力
# b, c = map(int, input().split())
# # 文字列の入力
# s = input()
# # 出力
# print("{} {}".format(a+b+c, s))
import numpy as np
def GCD(a,b):
    if a == b:
        return a
    elif a<b:
        tmp = a
        a = b
        b = tmp
    while True:
        r = a%b
        a = b
        b = r
        if b == r:break
    return r
def split_GCD(list):
    if type(list) is int:
        return list
    elif len(list) == 2:
        return GCD(list[0],list[1])
    else:
        list_a = list[:len(list)//2]
        list_b = list[len(list)//2:]
        a = split_GCD(list_a)
        b = split_GCD(list_b)
        return(GCD(a,b))

N = int(input())
A = list(map(int,input().split()))	#1 2 3 4 5 ... n  li=[1,2,3,4,5,...,n]
r_li = []
for i in range(N):
    tmp_li = A.copy()
    tmp_li.pop(i)
    r_li.append(split_GCD(tmp_li))
print(max(r_li))

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

C = list(itertools.combinations(A, 2))

num_max = 0
for i in range(len(C)):
    temp = gcd(*C[i])
    if temp > num_max:
        num_max = temp

print(num_max)

Submission status: Runtime Error

Solution code:
import math
import os
import random
import re
import sys

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



def solve(n, a):
    if n == 2:
        return gcd(a[0], a[1])
    dp = [False for _ in range(10001)]
    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
        else:
            dp[one] = 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
    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:
"""
問題文

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

制約
入力は全て整数である。
2≤N≤105
1≤Ai≤109
"""

"""
3 5 7
最大公約数: 1
最大の最大公約数: 1

8 4 6
最大公約数: 2
最大の最大公約数: 4
『aとbとcの最大公約数』　＝　『aとbの最大公約数』と『c』　の最大公約数

A1 , A2 , A3 ... An

gcd(A1 , A2 , A3 ... An-1) * N
= gcd * N * N
= gcd * N^2

gcd(A1 , A2 , A3 ... An-1)
gcd(A1 , A2 , A3 ... An-2 , An) = gcd(A1 , A2 , A3 ... An-2) , An
"""
import math
from fractions import gcd  # for Ver.3.4 or lower.
from functools import reduce
gcd_map = {}
def GCD(numbers , startIndex , endIndex):
    if len(numbers) == 0 : return 0
    if len(numbers) == 1 : return numbers[0]
    if len(numbers) == 2 : return gcd_sub(numbers[0] , numbers[1])
    else : 
        set_index = (startIndex , endIndex)
        if set_index in gcd_map : 
            return gcd_map[set_index]
        value = GCD(numbers[1:] , startIndex + 1 , endIndex)
        gcd_map[set_index] = value
        return value

def gcd_sub(a , b) : 
    rst = gcd(a , b)
    return rst

def main() : 
    N = int(input())
    a_list = input().split(" ")
    a_list = [int(i) for i in a_list]
    maxValue = 0
    for i in reversed(range(N)) : 
        if i == 0 : 
            prev_list = a_list[1:]
            after_list = []
        elif i == N - 1 : 
            prev_list = []
            after_list = a_list[:N-1]
        else : 
            prev_list = a_list[0 : i ]
            after_list = a_list[i + 1 :] 
        rst = gcd(GCD(prev_list , 0 , i - 1) , GCD(after_list , i + 1 , N - 1))
        if maxValue < rst : maxValue = rst
    print(maxValue)
main()

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 = gcd(a_list[i], a_list[i+1])
    ans.append(b)
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 = gcd(a_list[i], a_list[i+1])
    ans.append(b)
if N == 2:
    print(max(a_list))
else:
    ans.sort()
    print(ans[2])

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)

def spaceinput():
    return list(map(int,input().split(" ")))


N=int(input())
a=sorted(spaceinput())



notrewrite=[-1]*N
rewrite=[-1]*N
best=[-1]*N

notrewrite[0]=rewrite[0]=best[0]=a[0]
for i in range(1,N):

    notrewrite[i]=gcd(notrewrite[i-1],a[i])
    rewrite[i]=notrewrite[i-1]
    best[i]=max([notrewrite[i],rewrite[i],gcd(a[i],best[i-1])])
    #print([notrewrite[i],rewrite[i]])

print(best[N-1])

Submission status: Runtime Error

Solution code:
import numpy as np
N = map(int, input().split())
numbers = np.array((map(int, input().split())))
# numbers = np.array([7, 6, 8])
# numbers = np.array([12, 15, 18])
# numbers = np.array([1000000000, 1000000000])
# N = len(numbers)


def calculate_maximum_sub_gcd(numbers):
    sub_gcds = np.array([sub_gcd(numbers[:i], numbers[i+1:]) for i in range(N)])
    return np.max(sub_gcds)


def sub_gcd(left, right):
    return np.gcd(np.gcd.reduce(left), np.gcd.reduce(right))


print(calculate_maximum_sub_gcd(numbers))

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

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

Submission status: Runtime Error

Solution code:
from functools import reduce
inf = 10**10
import sys
input = sys.stdin.readline
def gcd_list(numbers):
    return reduce(math.gcd,numbers)
n = int(input())
a = list(map(int,input().split()))
index = inf
if n == 2:
    print(max(a))
else:
    a.sort()
    if math.gcd(a[0],a[n-1]) == 1:
        print(max(gcd_list(a[1:n]),gcd_list(a[0:n-1])))
    else:
        for i in range(1,n-1):
            ans = math.gcd(a[0],a[n-1])
            if math.gcd(a[i]-a[0],a[n-1]-a[i]) <= ans:
                index = i
                ans = math.gcd(a[i]-a[0],a[n-1]-a[i])
        print(gcd_list(a[0:i]+a[i+1:n]))

Submission status: Runtime Error

Solution code:
import math
import sys

sys.setrecursionlimit(10**9)
N = int(input())
A = list(map(int, input().split()))
A.sort()
mx = 10 ** 9
idx = 0
g = []
for i in range(N-1):
    tmp = math.gcd(A[i], A[i+1])
    #print(A[i], A[i+1], tmp)
    if tmp < mx:
        mx = tmp
        idx = i
    g.append([tmp, i])
g.sort(key=lambda x:x[0])
#print(g)
if N > 2:
    if g[0][1] + 1 == g[1][1]:
        A.remove(A[g[0][1]+1])
    else :
        tmp1 = math.gcd(A[g[0][1]], A[g[1][1]])
        tmp2 = math.gcd(A[g[0][1]+1], A[g[1][1]])
        A.remove(A[g[0][1]] if tmp1 < tmp2 else A[g[0][1]+1])
else :
    A = [max(A)]
import functools

print(functools.reduce(math.gcd, A))

Submission status: Runtime Error

Solution code:
N =int(input())

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

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

ans_lst = []
n = N - 1
if N == 1:
    print(A_lst[0])
elif N == 2:
    print(max(A_lst[0], A_lst[1]))
else:
    for i in range(N):
        B_lst +=  A_lst
        del B_lst[i]
        element = gcd(B_lst[0], B_lst[1])
        if n == 2:
            ans_lst.append(element)
        else:
            for i in range(2, n):
                element = gcd(element, B_lst[i])
            ans_lst.append(element)
    print(max(ans_lst))

Submission status: Runtime Error

Solution code:
#C - GCD on Blackboard
import math

def gcdList(num):
    print(num)
    if len(num) == 1:
        return num[0]
    else:
        return math.gcd(num.pop(), gcdList(num))
    
n = int(input())
a = list(map(int, input().split()))
ans = 0

for i in range(n):
    ans = max(ans, gcdList(a[:i]+a[i+1:]))
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import copy
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
N = int(input())
A=list(map(int,input().split()))
max_ = 1
for j,i in enumerate(A):
    replace = i
    B = copy.deepcopy(A)
    B.pop(j)
    h=gcd_list(B)
    for t in range(1,h+1):
        g=make_divisors(t)
        if max(g)==h:
            if h> max_:
                max_=h
            break
print(max_)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
n = int(input())
a = list(map(int,input().split()))
ans = 1
for i in range(n):
	b = a[:]
	del b[i]
	c = gcd_list(b)
	if c > ans:
		ans = c
print(ans)

Submission status: Runtime Error

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

  def gcd(m, n):
    while n:
      m, n = n, m%n
    return m

  res = set()
  k = max(A)
  for i in range(N):
    res.add(gcd(A[i], k))
  print(list(res)[N-1])

ans()

Submission status: Runtime Error

Solution code:
import math
N=int(input())
A=list(map(int, input().split()))
Z=0
for i in range(N):
    if i==0:
        ans=A[1]
        for j in range(2,N):
            ans=math.gcd(ans,A[j])
        

    else :
        B=A.copy()
        B[i]=B[0]
        Z=B[0]
        for k in range(1,N):
            Z =math.gcd(Z,B[k])
            
    
    if ans >Z:
        ans=ans
    else:
        ans=Z

print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

Submission status: Runtime Error

Solution code:
from sympy import isprime
import math

def calc_is(n):
    return isprime(n)

def calc_odd(n):
    if(n % 2 != 0):
        return True
    else:
        return False

N = int(input())
A = [int(i) for i in input().split()]
index_min = A.index(min(A))
index_max = A.index(max(A))
check = list(map(calc_is,A))
check_odd = list(map(calc_odd,A))
answer = 0
if(check.count(True) >= 2):
    answer = 1
elif(check.count(True) == 1):
    index_is = check.index(True)
    A[index_is] = max(A)
    answer = A[0]
    for i in range(1,N):
        answer = math.gcd(answer,A[i])
elif(check_odd.count(True) == 1):
    index_odd = check_odd.index(True)
    A[index_odd] = max(A)
    answer = A[0]
    for i in range(1, N):
        answer = math.gcd(answer, A[i])
else:
    A[index_min] = A[index_max]
    answer = A[0]
    for i in range(1, N):
        answer = math.gcd(answer, A[i])
print(answer)

Submission status: Runtime Error

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

# 整数の入力
a = int(input())
# 数値のリスト化
xList = [int(i) for i in input().split()]
keisanList = copy.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
        listIndex = i

xList[listIndex] = saidai
print(gcd_list(xList))

Submission status: Runtime Error

Solution code:
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

n = int(input())
a = list(map(int,input().split()))
a.append(0)
a.append(0)
a.sort(reverse=True)
ans1 = 0
ans2 = 0
ans3 = 0

result = make_divisors(a[0] - a[2])
for i in range(len(result)):
	next = 0
	for j in range(n):
		if((j != 1) & (a[j] % result[i] != 0):
			next = 1
			break
	if(next == 0):
		ans1 = result[i]
		break

result = make_divisors(a[0] - a[1])
for i in range(len(result)):
	next = 0
	for j in range(n):
		if((j != 2) & (a[j] % result[i] != 0):
			next = 1
			break
	if(next == 0):
		ans2 = result[i]
		break

result = make_divisors(a[1] - a[2])
for i in range(len(result)):
	next = 0
	for j in range(n):
		if((j != 0) & (a[j] % result[i] != 0):
			next = 1
			break
	if(next == 0):
		ans3 = result[i]
		break
max = ans1
if(ans2 > max):
	max = ans2
if(ans3 > max):
	max = ans3
print(max)

Submission status: Runtime Error

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

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

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

for i in range(len(A)):
    A_poped = copy.copy(A)
    A_poped.pop(i)
    tmp = gcd_list(A_poped)
    if tmp > ret_max:
        ret_max = tmp
        
print(ret_max)

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)

def spaceinput():
    return list(map(int,input().split(" ")))


N=int(input())
a=sorted(spaceinput())



notrewrite=[-1]*N
rewrite=[-1]*N
best=[-1]*N

notrewrite[0]=rewrite[0]=best[0]=a[0]
for i in range(1,N):

    notrewrite[i]=gcd(notrewrite[i-1],a[i])
    rewrite[i]=notrewrite[i-1]
    best[i]=max([notrewrite[i],rewrite[i],gcd(a[i],best[i-1])])
    print([notrewrite[i],rewrite[i]])

print(best[N-1])

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


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

result = 0
for i in range(n):
    withoutI = a[:i]+a[i+1:]
    tmp = reduce(math.gcd, withoutI)
    if tmp > result:
        result = tmp

print(result)

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce

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

max = 0

N = int(input())

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

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

print(max)

Submission status: Runtime Error

Solution code:
import copy
import math
from functools import reduce


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


n = int(input())
a = list(map(int, input().split()))
nl = set(range(n))
gcd_list = [0]
for i in nl:
    tmp = copy.deepcopy(a)
    tmp.pop(i)
    gcd_list.append(gcd(*tmp))
ans = max(gcd_list)
print(ans)

Submission status: Runtime Error

Solution code:
import math
N=int(input())
A=list(map(int, input().split()))
Z=0
for i in range(N):
    if i==0:
        ans=A[1]
        for j in range(2,N):
            ans=math.gcd(ans,A[j])
        print(ans)

    else :
        B=A.copy()
        B[i]=B[0]
        Z=B[0]
        for k in range(1,N):
            Z =math.gcd(Z,B[k])
            print(Z)
    
    if ans >Z:
        ans=ans
    else:
        ans=Z

print(ans)

Submission status: Runtime Error

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

def mygcd(A):
    if len(A) == 1:
        return A[0]
    else:
        return math.gcd(A[0],mygcd(A[1:]))
        
ans = []
for i in range(N):
    ans.append(mygcd(A[:i-1]+A[i:]))

print(max(ans))

Submission status: Runtime Error

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

def test(x,k,m):
    #print("i=",k)
    tmp=[0]*len(x)
    for j in range(m):
        tmp[j]=x[j]
    #print('a=',x)
    #print('tmp=',tmp)
    del tmp[k]
    #print('tmp=',tmp)
    #print("a==",x)
    XX=gcd(*tmp)
    #print("XX=",XX)
    return XX

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

yakusu=[0]*len(a)
for i in range(n):
    yakusu[i]=test(a,i,n)

ans=max(yakusu)
print(ans)

Submission status: Runtime Error

Solution code:
import math
import copy

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

if N==2:
    print(max(A))
    exit()
else:
    max=0
    for i in range(N):
        x = copy.deepcopy(A)
        del x[i]
        c = math.gcd(x[0], x[1])
        for i in range(2,N-1):
            c = math.gcd(c,x[i])
        if c >= max:
            max = c
    print(max)

Submission status: Runtime Error

Solution code:
import fraction

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


if N == 2:
    print(max(A[0], A[1]))
else:
    m = min(A)

    ans = -1
    for i in range(1, m+1):
        count = 0
        for n in range(N):
            if count > 1:
                break
            if A[n] % i != 0:
                count += 1
        if count <= 1 and i > ans:
            ans = i

    print(ans

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce

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

A.sort()
count = []

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

list_A_0 = make_divisors(A[0])

#print(list_A_0)

for j in range(len(list_A_0)):
    count.append(0)
    for i in range(1,N):
        if A[i] % list_A_0[j]:
            pass
        else:
            count[j] += 1
dict_div = {}
for k in range(len(count)):
    dict_div[list_A_0[k]] = count[k]

#print(count)
#print(dict_div)

dict_div = dict(sorted(dict_div.items(), key=lambda x: -x[1]))
#print(dict_div)

#N-2 と N-1回割れている要素のなかで一番大きいものを出力？
asm = []

for i,j in dict_div.items():
    if j == N-2 or j == N-1:
        asm.append(i)
        
def gcd(*numbers):
    return reduce(fraction.gcd, numbers)

if asm:
    print(max(asm))
else:
    print(gcd(A[1:]))

Submission status: Runtime Error

Solution code:
import math
import copy 
from functools import reduce

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

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

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

	ans=0
	for i in range(N):
		l=copy.deepcopy(A)
		l.pop(int(i))
		tmp_gcd=gcd_list(l)	
		if(tmp_gcd > ans):
			ans= tmp_gcd
	print(ans)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
A = list(map(int, input().split()))
a_list = []
b_list = []
c_list = []

A.sort()
#print(math.gcd(6, 7))
if 4 <= N:
    a, b, c = math.gcd(A[0], A[1]), math.gcd(A[1], A[2]), math.gcd(A[0], A[2])
    for i in range(3, N):
        a_list.append(math.gcd(A[i], a))
        b_list.append(math.gcd(A[i], b))
        c_list.append(math.gcd(A[i], c))
    a_list.sort()
    b_list.sort()
    c_list.sort()
    ans = max(a_list[0], b_list[0], c_list[0])

elif N == 3:
    ans = max(math.gcd(A[0], A[1]), math.gcd(A[1], A[2]), math.gcd(A[0], A[2]))

elif N == 2:
    ans = max(A[0], A[1])
else:
    ans = 1000000000
    print(N)

print(ans)

Submission status: Runtime Error

Solution code:
def gcd(p,q):
  while q!=0:
    p,q=q,p%q
  return p

n=int(input())
a=list(map(int,input().split()))
a.sort()
cnt1=0
d=a[0]

if n==2:
  print(a[-1])
elif gcd(a[0],a[1])==1:
  b=a[0]
  c=a[1]
  for i in range(n-2):
    if gcd(b,a[i+2])==1:
      b=1
      break
    else:
      b=gcd(b,a[i+2])
  for i in range(n-2):
    if gcd(c,a[i+2])==1:
      c=1
      break
    else:
      c=gcd(c,a[i+2])
  print(max(b,c))
else:
  for i in range(n-1):
    if gcd(d,a[i+1])==1 and cnt1==0:
      cnt1=1
      continue
    elif gcd(d,a[i+1])==1 and cnt1==1:
      d=1
      break
    else:
      d=gcd(d,a[i+1])
  print(max(b,c,d))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

Submission status: Runtime Error

Solution code:
import math

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

def gcd2(_a):
    buff = 0
    for n in range(N):
        buff = math.gcd(buff, _a[n])
    return buff


ans = 0
_ans = 0
for i in range(N):
    buff = A.copy()
    buff[i] = 0
    _ans = gcd2(buff)
    ans = max(_ans, ans)


print(ans)

Submission status: Runtime Error

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

def getNum(a, b):
    if a == b:
        return a
    while(True):
        a, b = max(a, b), min(a, b)
        a -= b
        if a == b:
            return a

ansList = []
for i in range(0, N-1):
    ansList.append(getNum(AList[i], AList[i+1]))

print(sorted(ansList, reverse=False)[1])

Submission status: Runtime Error

Solution code:
from collections import defaultdict

data = {}

def gcv(a, b):
    global data
    if data.get(f'{a}:{b}', None):
        return data[f'{a}:{b}']
    elif data.get(f'{b}:{a}', None):
        return data[f'{b}:{a}']

    if b == 0:
        data[f'{a}:{b}'] = a
        return a
    else:
        return gcv(b, a % b)


def solve(n, a):
    if n == 2 and a[0] == a[1]:
        return a[0]
    n_dict = defaultdict(int)
    for i in range(len(a)):
        for j in range(len(list(a)) - i + 1):
            n_dict[gcv(a[i], a[j + i - 1])] += 1
    return sorted(n_dict.items(), key=lambda x: x[0])[1][0]


def input_from_console():
    n = int(input())
    a = list(map(int, input().split()))
    return n, a


def main():
    n, a_list = input_from_console()
    print(solve(n, a_list))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

max_gcd = gcd_list(a)

for i in range(n):
    b = [a[j] if i != j else 0 for j in range(n)]
    gcd_b = gcd_list(b)
    if gcd_b > max_gcd:
        max_gcd = gcd_b

print(max_gcd)

Submission status: Runtime Error

Solution code:
#C - GCD on Blackboard
import math
from functools import reduce

def gcdList(num):
    if len(num) == 1:
        return num[0]
    else:
        return math.gcd(num.pop(), gcdList(num))
    
n = int(input())
a = list(map(int, input().split()))
ans = 0

for i in range(n):
#     if i == 0:
#         tmp = gcdList(a[1:])
#     elif  0 < i and i < n: 
#         tmp = gcdList(a[:i] + a[i+1:])
#     else:
#         tmp =  gcdList(a[:n])
    ans = max(ans, gcdList(a[:i]+a[i+1:]))
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import fractions

N = int(input()) 
a = list(int(_) for _ in input().split()) 

if N >=3:
    ma = list(itertools.combinations(a,N-1))
    print(max([fractions.gcd(*ma[_]) for _ in range(N)]))
else:
    print(max(a))

Submission status: Runtime Error

Solution code:
n = int(input())
li = list(map(int,input().split()))
ans = 0

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

def gcd_list2(li):
    a = gcd(li[0],li[1])
    for i in range(n-1):
        a = gcd(a,li[i])
    return a

for i in range(n):
    li2 = li[:i] + li[i+1:]
    a = gcd_list2(li2)
    if a > ans:
        ans = a

print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


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


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

result = 0
for i in range(n):
    withoutI = a[:i]+a[i+1:]
    tmp = gcd_list(withoutI)
    if tmp > result:
        result = tmp

print(result)

Submission status: Runtime Error

Solution code:
import math

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(math.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(math.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 math
from functools import reduce
import numpy as np
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

N = int(input())
A = list(map(int, input().split()))
ans=0
for i in range(N):
    a = A[0]
    del A[0]
    
    b = gcd_list(A)
    if ans < b:
        ans = b
    A.append(a)

print(ans)

Submission status: Runtime Error

Solution code:
import copy
import math
from functools import reduce


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


n = int(input())
a = list(map(int, input().split()))
nl = set(range(n))
gcd_list = []
for i in nl:
    tmp = copy.deepcopy(a)
    tmp.pop(i)
    gcd_list.append(gcd(*tmp))
ans = max(gcd_list)
print(ans)

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce

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

n = int(input())
a = list(map(int,input().split())) #input from array of integer like "1 2 3"

ans = []

max = 0
maxi = 0

for i in range(n):
  l = copy.deepcopy(a)
  l.pop(i)
  x = gcd_list(l)
  ans.append(x)
  if max < x:
    max = x
    maxi = i

print(max)

Submission status: Runtime Error

Solution code:
from math import gcd
from itertools import accumulate

input()
a = list(map(int, input().split()))
b = list(accumulate(a, gcd))
c = list(accumulate(reversed(a), gcd))
b = [c[-2]] + b
c = [b[-2]] + c
print(max(map(gcd, b, c[-2::-1])))

Submission status: Runtime Error

Solution code:
import numpy as np

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

Alist = np.sort(Alist)
tmp = Alist[0]
Alist = Alist % tmp
Alist = Alist[Alist != 0]

def gcd(nlist):
    tmp = nlist[0]
    while len(nlist) != 0:
        nlist = np.sort(nlist)
        tmp = nlist[0]
        nlist = nlist % tmp
        nlist = nlist[nlist != 0]
    return tmp

if len(Alist) == 0:
    print(tmp)
else:
    gcdlist = []
    for i in range(len(Alist)):
        nlist = np.append(Alist[:i], Alist[i+1:])
        gcdlist.append(gcd(nlist))
    print(max(gcdlist))

Submission status: Runtime Error

Solution code:
import numpy as np
import math

if True:
    N=int(input())
    A=np.unique(list(map(int,input().split())))
else:
    A=np.asarray(range(10**5)[10**4:])
#C=np.asarray(list(map(int,input().split())))

mina = np.min(A)

for i in range(A.size):
    A[i] = math.gcd(mina,A[i])
uA=np.unique(A)
max = 0
for a in uA:
    if A[A==a].size > 1:
        continue
    tmpgcd = uA[uA!=a][0]
    for ta in uA[uA!=a][1::]:
        tmpgcd = math.gcd(tmpgcd,ta)

    if max < tmpgcd: max = tmpgcd

print(max)

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)

    # divisors.sort()
    return divisors
  
def check(num, kouho, N, i):
  for val in kouho.keys():
    if num%val == 0:
      kouho[val] += 1
  return {k: v for k, v in kouho.items() if v > i-1}
  
  
N = int(input())
A= list(map(int, input().split()))
pri_flag = True

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

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

max_gcd = 0

for i in range(n):
    b = [a[j] if i != j else 0 for j in range(n)]
    gcd_b = gcd_list(b)
    if gcd_b > max_gcd:
        max_gcd = gcd_b

print(max_gcd)