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

dic = {}
def gcd(x, y):
  if (x, y) in dic:
    return dic[(x, y)]
  if y == 0:
    dic[(x, y)] = x
  else:
    dic[(x, y)] = gcd(y, x % y)
  return dic[(x, y)]

def gcd_list(numbers):
  return reduce(gcd, numbers)
 
n = int(input())
li = list(set(map(int, input().split())))

ans = []
for i in range(n):
  du = li.copy()
  del du[i]
  ans.append(gcd_list(du))

print(max(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 = mat.gcd(c,x[i])
        if c >= max:
            max = c
    print(max)

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

if n==2:print(max(a))
else:
    ans=0
    for i in range(n):
        b=np.array([x for x in a if not x==a[i]])
        c=gcd_list(b)
        if ans<c: ans=c
    print(ans)

Submission status: Runtime Error

Solution code:
def saidai(a,b):
    global ans
    amari = a % b
    if amari != 0:
        return saidai(b,amari)
    else:
        return b
def saidai_f(a):
    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()))
 
for i in range(n):
    for ii in range(n):
        if i!=ii:
            hoge.append(a[ii])
    ans.append(saidai_f(hoge))
    hoge=[]
print(max(ans))

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce
N=int(input())
A=list(map(int,input().split()))
g=[]
def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
B=A[:]
for i in range(N):
    del B[i]
    g.append(gcd_list(B))
    B=A[:]
print(max(g))

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
    for i in range(10001):
        if dp[i] == True:
            if count == 1: return i
            count += 1

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

Submission status: Runtime Error

Solution code:
num = input()
tar = input().split()
cnt = 0
aaa = 0
tmp = []

nyan = int(tar[0])

for i in range(int(num)):
  if nyan < int(tar[i]):
    nyan = int(tar[i])
    aaa = i

for i in range(1,int(nyan)):
  for j in range(int(num)):
    if int(tar[j])/2 < i:
      break
    if int(tar[j])%i == 0:
      cnt +=1
  cnt +=1
  if cnt >= int(num)-1:
    tmp.append(i)
  cnt = 0

print(tmp[len(tmp)-1])

Submission status: Runtime Error

Solution code:
import math
N = int(input())
a = list(map(int,input().split()))
err = 8
ma1 = [1]
for i in range(1,N):
    f = math.gcd(a[0],a[i])
    for j in range(1,N):
        if a[j]%f != 0:
            err = err + 1
        if err == 10:
            break
    if err < 10:
        ma1.append(f)
arr = 8
ma2 = [1]

tmp = a[N-1]
a[N-1]=a[0]
a[0]=tmp


for i in range(1,N):
    f = math.gcd(a[0],a[i])
    for j in range(1,N):
        if a[j]%f != 0:
            arr = arr + 1
        if arr == 10:
            break
    if arr < 10:
        ma2.append(f)



if max(ma2) > max(ma1):
    print(max(ma2))
else:
    print(max(ma1))

Submission status: Runtime Error

Solution code:
n = int(input())
A = [int(i) for i in 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




min_a = min(A)

divisors = make_divisors(min_a)

divisors = sorted(divisors, reverse = True)




previous_d=0
ans = 1
for d in divisors:
    #print(d)
    A_2 = [a/d for a in A]
    #print(A_2)
    num_float = 0
    for a in A_2:
        if a.is_integer() == False:
            num_float += 1
    #print(num_float)
    if num_float <= 1:
        ans = d
        break
    
        
print(ans)

Submission status: Runtime Error

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

if len(l) == 2:
    memo = max(l)
else:
    memo = 1
    for i in range(N):
        g = fractions.gcd(*(l[:i]+l[i+1:]))
        if g > memo:
            memo = g

print(memo)

Submission status: Runtime Error

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

def gcd(t1,t2):
    while t2:
        t1,t2=t2,t1%t2
    return t1

if n==2:
    print(max(a))
    exit()

ans=[gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])]
ans=list(set(ans))
tmp1=max(ans)
tmp2=tmp1
for i in range(2,n):
    tmp1=gcd(tmp1,a[i])
    if tmp1!=tmp2:
        ans+=[tmp1]
        tmp2=tmp1
ans.sort()
print(ans[1])

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]
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 = 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 sys
N = input()

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


if len(A) < 3:
    print(max(A))
    sys.exit()



min_0 = A[0]
min_1 = A[1]
min_2 = A[2]


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



max_primes = primes(A[-1])

def soinsu(n):
    ret = [0 for _ in range(len(max_primes))]
    for p_index in range(len(max_primes)):
        p = max_primes[p_index]
        while n % p == 0:
            n /= p
            ret[p_index] += 1
    return ret

def kouyaku(x, y):
    kouyaku = 1
    for p_index in range(len(max_primes)):
        p = max_primes[p_index]
        i = min(x[p_index], y[p_index])
        kouyaku *= pow(p, i)
    return kouyaku

def check(n):
    fail_count = 0
    for a in A:
        if a % n != 0:
            fail_count +=1
            if fail_count == 2:
                return False
    return True



soinsu_0 = soinsu(min_0)
soinsu_1 = soinsu(min_1)
soinsu_2 = soinsu(min_2) 


kouyaku_01 = kouyaku(soinsu_0, soinsu_1)
kouyaku_12 = kouyaku(soinsu_1, soinsu_2)
kouyaku_02 = kouyaku(soinsu_0, soinsu_2)


ans = 1
if check(kouyaku_01):
    ans = max(ans, kouyaku_01)

if check(kouyaku_12):
    ans = max(ans, kouyaku_12)


if check(kouyaku_02):
    ans = max(ans, kouyaku_02)


print(ans)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a = [int(i) for i in input().split()]
m = []
if len(a) == 2:
    print(max(a))

else:
    for i in range(n-2):
        m.append(math.gcd(a[i],a[i+1]))
    m.append(math.gcd(a[0],a[n-1]))
    m = list(set(m))
    m.sort()
    print(m[1])

Submission status: Runtime Error

Solution code:
import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

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

n = ni()
li = na()
li2 = []
kouho = []
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    a = fractions.gcd(li[0], li[1])
    b = fractions.gcd(li[1], li[2])
    c = fractions.gcd(li[2], li[0])
    li2.append(a)
    li2.append(b)
    li2.append(c)
    li2.extend(make_divisors(a))
    li2.extend(make_divisors(b))
    li2.extend(make_divisors(c))
    kouho = set(li2)
    for i in range(3,n):
        if len(kouho) == 0:
            break
        for num in kouho:
            if li[i] % num != 0:
                kouho.remove(num)
    if len(kouho) == 0:
        print(1)
    else:
        print(max(kouho))

Submission status: Runtime Error

Solution code:
import math

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


if N == 2:
    if A[0] > A[1]:
        print(A[0])
    else:
        print(A[1])
else:
    gcd_max = 0
    for i in range(N):
        if i != 0:
            gcd = A[0]
        else:
            gcd = A[1]
        for j in range(N):
            if j != i:
                gcd = math.gcd(gcd, A[j])
        if gcd_max < gcd:
            gcd_max = gcd
    print(gcd_max)

Submission status: Runtime Error

Solution code:
#C
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
N=int(input())
A = [int(j) for j in input().split()]
A=list(set(A))
A.sort()
ans=0
 
for i in range(N):
    if len(A)>2:
        tmp=A.copy()
        tmp.pop(i)
        ans=max(ans,gcd(*tmp))
    elif len(A)==1:
        ans=A[0]
        print(ans)
        exit()
        
    else:
        ans=gcd(A[0],A[1])
        print(ans)
        exit()
print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

    # 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:]):
  kouho = check(num, kouho, N, i+3)
  if len(kouho) == 1:
    print(1)
    pri_flag = False
    break

if pri_flag:
  print(max(kouho))

Submission status: Runtime Error

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

def maxgcd(A,N):
    B=[]
    max = 1
    for i in range(N):
        if len(A) == 2:
            if A[0] > A[1]:
                temp = gcd(A[0],A[1])
            else:
                temp = gcd(A[1],A[0])
            if max < temp:
                max = temp
            break
        else:
            B = copy.copy(A)
            B.pop(i)
            temp = maxgcd(B,N-1)
        if max < temp:
            max = temp
    return max
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

print(maxgcd(A,N))

Submission status: Runtime Error

Solution code:
import itertools
N = int(input())
A = [int(_) for _ in input().split()]
gcd = lambda x, y: gcd(y, x % y) if x % y else y
G = list(itertools.accumulate(A, func=gcd))
g = G[-1]
if G[0] == g:
    ans = list(itertools.accumulate(A[1:], func=gcd))[-1]
else:
    for i in range(1, N - 1):
        if G[i] == g:
            ans = max(
                gcd(G[i - 1],
                    list(itertools.accumulate(A[i + 1:], func=gcd))[-1]),
                G[-2])
            break
print(ans)

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):
    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 = set(numbers[1:])
        if set_index in gcd_map : return gcd_map[set_index]
        value = GCD(numbers[1:])
        gcd_map[set_index] = value
        return value

def gcd_sub(a , b) : 
    if (a , b) in gcd_map : return gcd_map[(a,b)]
    else : 
        rst = gcd(a , b)
        gcd_map[(a,b)] = rst
        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) , GCD(after_list))
        if maxValue < rst : maxValue = rst
    print(maxValue)
main()

Submission status: Runtime Error

Solution code:
import math
#from functools import reduce
import functools

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

if max(v) % 2 ==0:
	b = True
else:
	b = False
		
v.sort()

for index,_ in enumerate(v):
	if _  % 2 ==0:
		if not b:
			v[index] = v[-1]
			break
			
	else:
		if b:
			v[index] = v[-1]
			break
			
#print(v)

#固定
print(functools.reduce(math.gcd,v))

Submission status: Runtime Error

Solution code:
import functools
import math

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

for i in range(n):
    tmp=a[i]
    a.pop(i)
    ans.append(functools.reduce(math.gcd,a))
    a.insert(i,tmp)
print(max(ans))

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)
if N == 2:
    print(max(a_list))
else:
    ans.sort()
    print(ans[2])

Submission status: Runtime Error

Solution code:
import math
# math.gcd(a,b) # 最大公約数

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

# def gcd(index,a,b):
#     if (index >= N):
        
#     m = math.gcd(a,b)
#     return gcd(index+1, m, A[index+1])
def gcd1():
    buff = 0
    for n in range(N):
        buff = math.gcd(buff, A[n])
    return buff

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

# _J = 10**10
# for i in range(N):
#     for j in range(_J):
#         A[i] = j + 1
#         ans = gcd1()


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:
import math
n=int(input())
a=list(map(int,input().split()))
b=a
c=[0]*n
ans=a[0]
for i in range(n):
    for j in range(n):
        if j==i:
            if j==0:
                ans=a[1]
            else:
                pass
        else:
            #print(j)
            ans=math.gcd(ans,a[j])
   # a[i]=b[i]
        c[i]=ans
    ans=a[0]
#print(c)
print(max(c))

Submission status: Runtime Error

Solution code:
import math
# def gcd(x, y):
#     while y:
#         amari = x % y
#         x = y
#         y = amari
#     return x

def gcd_list(numbers, maxv):
    gcdv = numbers[0]
    if len(numbers) == 1:
        return gcdv
    for n in range(1, len(numbers)):
        gcdv = math.gcd(gcdv, numbers[n])
        if maxv > gcdv:
            return maxv
        else:
            maxv = gcdv
    return maxv

def main():
    n = int(input())
    a = [int(a) for a in input().split()]

    maxv = 0
    for nn in range(n):
        maxv = gcd_list(a[:nn]+a[nn+1:], maxv)
    print(maxv)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

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]])
        #print(tmp1, tmp2)
        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())
an = list(map(int, input().split(' ')))
an = list(set(an))
if len(an) == 1:
  print(an[0])
  exit()
  
from fractions import gcd
from functools import reduce
import copy

max_g = 1
g0 = reduce(gcd, an)
for i in range(n):
  bn = copy.copy(an)
  bn.pop(i)
  g = reduce(gcd, bn)
  max_g = max(g, max_g)
print(max_g)

Submission status: Runtime Error

Solution code:
import sys
import copy
import fraction
from functools import reduce


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

    if(N == 2):
        print(max(B))
        return

    result = 1
    for i in range(N):
        chB = copy.copy(B)
        chB.pop(i)
        current_gcd = gcd_list(chB)
        if(result < current_gcd):
            result = current_gcd
    print(result)


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


if(__name__ == '__main__'):
    main()

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce

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

max_cd = -1
for i in range(N):
    tmp_list = A[0:i]
    tmp_list.extend(A[i+1:N])
    max_cd = max(gcd_list(tmp_list),max_cd)

print(max_cd)

Submission status: Runtime Error

Solution code:

object Main {
  def main(args:Array[String]) = {
    var sc = new java.util.Scanner(System.in)
    var n = sc.nextInt
    var a = Array.fill(n)(sc.nextInt())
    var max = 0
    var gcdRecord = 0
    for(i <- 0 until n; j <- 0 until n-1){
        if(j != i && j != i-1){
            max = if(gcd(a(j), a(j+1)) > max) gcd(a(j), a(j+1)) else max;
        }else if(j == i-1 && j < n-2){
            max = if(gcd(a(j), a(j+2)) > max) gcd(a(j), a(j+2)) else max;
        }
    }
    if (n == 2){
        max = if(a(0) > a(1)) a(0) else a(1)
    }else if(n == 1){
        max = a(0)
    }
    println(max)
  }

  def gcd(x: Int, y: Int): Int = {
    if(y > x) gcd(y, x)
    else if(y == 0) x
    else gcd(y, (x % y))
  }
}

Submission status: Runtime Error

Solution code:
import math

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

def gcd_list2(li):
    a = math.gcd(li[0],li[1])
    for i in range(n-1):
        a = math.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:
def saidai(a,b):
    global ans
    amari = a % b
    if amari != 0:
        return saidai(b,amari)
    else:
        return b
def saidai_f(a):
    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()))

for i in range(n):
    for ii in range(n):
        if i!=ii:
            hoge.append(a[ii])
    ans.append(saidai_f(hoge))
    hoge=[]
print(max(ans))

Submission status: Runtime Error

Solution code:
import fractions
n=int(input())
a=list(map(int, input().split()))
ans=[0]*(n-1)
ans2=[0]*(n-1)

for i in range(1,n):
    ans[i-1] = fractions.gcd(a[0], a[i])
for i in range(0,n):
    if i==1:
        continue
    else:
        ans2[i-2] = fractions.gcd(a[1], a[i])
s_ans=sorted(ans)
s_ans2=sorted(ans2)

if n==2:
    print(max(a))
else:
    print(max(s_ans[1],s_ans2[1]))

Submission status: Runtime Error

Solution code:
N=int(input())
C=list(map(int, input().split()))
if len(set(C))==1:
    print(C[0])
    exit(0)

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 gcd(a,b):
    while b:
        a,b=b,a%b
    return a

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

a={}
for i in range(N):
    for j in make_divisors(C[i]):
        a[j]=a.get(j,0)+1
b=[]
for i in a:
    if a[i]==N-1:
        b.append(i)
ans=b[0]
for i in range(1,len(b)):
    ans=lcm(ans,b[i])

print(ans)

Submission status: Runtime Error

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

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

else:
    b=min(A)
    c=max(A)
    for a in A:
        list_koyaku1.append(gcd(a,b))

    for a in list_koyaku1:
        list_koyaku11.append(gcd(a,c))
    ans=max(list_koyaku11)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a = [int(i) for i in input().split()]
m = []
if len(a) == 2:
    print(max(a))

else:
    for i in range(n-1):
        m.append(math.gcd(a[i],a[i+1]))
    m.append(math.gcd(a[0],a[n-1]))
    m = list(set(m))
    m.sort()
    print(m[1])

Submission status: Runtime Error

Solution code:
import fraction

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

if n == 2:
    a.append(fraction.gcd(a[0],a[1]))

g0 = [fraction.gcd(a[0],a[1]),fraction.gcd(a[0],a[2]),fraction.gcd(a[1],a[2])]
s_g0 = sorted(g0,reverse=True)

maxg1 = s_g0[0]
maxg2 = s_g0[1]

if n >= 4:
    for i in range(n - 3):
        maxg1 = fraction.gcd(maxg1,a[i + 3])
        maxg2 = fraction.gcd(maxg2,a[i + 3])

if maxg1 >= maxg2:
    print(maxg1)
else:
    print(maxg2)

Submission status: Runtime Error

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

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

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

if n < 100:
  for i in range(n):
    b = copy.copy(a)
    b.pop(i)
    t = gcd(b)
    if ans < t:
      ans = t
else:
  for _ in 100:
    t = gcd(random.sample(a, 3))
    if ans < t:
      ans = t

print(ans)

Submission status: Runtime Error

Solution code:
import functools
import math

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
  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(math.gcd, A[0:i]+A[i+1:])
    if tmp > x:
      x = tmp
  
  print(x)
  
main()

Submission status: Runtime Error

Solution code:
import math
n=int(input())
array=list(map(int,input().split()))
max=0

for i in range(0,n):
	for j in range(i+1,n):
		num=math.gcd(array[i],array[j])
		# print(num)
		if max<num:
			max=num

print(max)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)

import math
from functools import reduce

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

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

for n in range(len(A)):
    temp_A = list(A)
    del temp_A[n]
    gcd_num = gcd_list(temp_A)
    if gcd_num > gcd_max:
        gcd_max = gcd_num

print(gcd_max)

Submission status: Runtime Error

Solution code:
import functools
import math

n=int(input())
v=list(map(int,input().split()))
tmp = 3
for i in v:
    if i % 2 == 0:
        tmp = i
for i in v:
    if i % 2 != 0:
        v[v.index(i)] = tmp

gcd = functools.reduce(math.gcd, v)

print(gcd)

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)


tmp = 0
gcd_max = 0
for n in range(N):
    tmp = A[n]
    A.remove(A[n])
    gcd = gcd_list(A)
    if gcd >= gcd_max:
        gcd_max = gcd

    A.insert(n, tmp)

print(gcd_max)

Submission status: Runtime Error

Solution code:
def make_divisors(arg):
    divisors = set()
    for i in range(1, int(arg**0.5)+1):
        if arg % i == 0:
            divisors.add(i)
            divisors.add(arg//i)

    return divisors


n = int(input())
a = list(map(int, input().split()))
a.sort()
a0y = make_divisors(a[0])
a1y = make_divisors(a[1])
common = a0y & a1y
one = a0y ^ a1y
last = 0
lastdev = set()
tmp = set()
for e in a[2:]:
    if e == last:
        tmp = lastdev
    else:
        tmp = make_divisors(e)
    common = tmp & common
    one = (one & tmp) | (common - tmp)
    last = e

print(max(common.union(one)))

Submission status: Runtime Error

Solution code:
import fractions
import sys
import copy

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

def gcd2(array):
    gcd = fractions.gcd(array[0], array[1])
    for i in range(2, len(array)-1):
        gcd = fractions.gcd(gcd, array[i])
    return gcd

max = 0
for i in range(n):
    b = copy.copy(a)
    del b[i]
    g = gcd2(b)
    if max < g:
        max = g
print(max)

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:
        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
from sys import stdin

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

def GCD(numbers):
    if len(numbers)==1:
        return numbers[0]
    else:
        e = k(numbers[0],numbers[1])
        if len(numbers)==2:
            return e
        else:
            for j in range(2, len(numbers)):
                e=k(e,numbers[i])
            return e

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
max = 0
for i in range(N):
    if i==0:
        g=GCD(A[1:])
    elif i==N-1:
        g=GCD(A[:N-1])
    else:
        g=GCD(A[:i]+A[i+1:])
    if g>max:
        max=g
print(max)

Submission status: Runtime Error

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

min=10000000000000000000
for i in range(N):
    if A[i] < min:
        min=A[i]
min2=10000000000000000000
for i in range(N):
     if A[i] < min2 and A[i] != min:
         min2=A[i]
if min2==10000000000000000000:
    min2 = min
cnt=0
for i in range(N):
    if A[i] % min2 == 0:
        cnt+=1
if cnt == len(A) or cnt == len(A)-1:
    print(a)
    quit()

a = min
for i in range(min):
    cnt=0
    for i in range(N):
        if A[i] % a == 0:
            cnt+=1
        if cnt == len(A) or cnt == len(A)-1:
            print(a)
            quit()
    a -= 1

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
def gcd(a, b):
    P = max(a, b)
    Q = min(a, b)
    R = P%Q
    P = Q
    Q = R
    while R != 0:
        R = P%Q
        P = Q
        Q = R
    return P

candidate = [(gcd(A[0], A[1]), True), (A[0], False), (A[1], False)]
for i in range(2, N):
    nxt_cand = []
    for v, b in candidate:
        if(v == 1):
            continue
        if(b == True and gcd(v, A[i]) < v):
            nxt_cand.append((v, False))
        else:
            nxt_cand.append((gcd(v, A[i]), b))
    candidate = nxt_cand[::]

print(max(candidate)[0])

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

def gcd_list2(li):
    a = math.gcd(li[0],li[1])
    for i in range(n-1):
        a = math.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)