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

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

for i in a:
    b = sorted(A)
    b.remove(i)
    ans.append(reduce(gcd, b))

print(max(ans))

Submission status: Runtime Error

Solution code:
import math


def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    sortedA = sorted(A)
    minNum = min(A)

    gcd_list = []
    for i in range(N):
        gcd_list.append(math.gcd(minNum, sortedA[i]))

    gcd_list = sorted(gcd_list)
    print(max(gcd_list[0], gcd_list[1]))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read() for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


import numpy as np

N = read_a_int()
A = np.array(read_ints())


def gcd(a, b):
    while (b != 0):
        tmp = a
        a = b
        b = tmp % b

    return a


import math


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

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

    return True


gcd_tmp = A[0]
for a in A[1:]:
    gcd_tmp = gcd(gcd_tmp, a)

A_gcd = A//gcd_tmp

# delidx = None
for i, a in enumerate(A_gcd):
    if is_prime(a):
        delidx = i
        break


ans = A[delidx-1]
for i, a in enumerate(A):
    if i == delidx:
        continue
    ans = gcd(ans, a)

print(ans)

Submission status: Runtime Error

Solution code:
import math
import copy

def gcd_(list):
  tmp = list[0]
  for i in range(len(list)):
    tmp = math.gcd(tmp, list[i])
  return tmp

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

b = copy.copy(a)
c = []

for i in range(n):
  del b[i]
  c.append(gcd_(b))
  b = copy.copy(a)
  
print(max(c))

Submission status: Runtime Error

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

from math import gcd
from functools import reduce

num = 0

def gcd_list(numbers):
    a = numbers[0]
    for i in range(1, len(numbers)):
        a = gcd(a, numbers[i])
    return a

for i in range(len(a)):
    num = max(num, gcd_list(a[:i] + a[i+1:]))

print(num)

Submission status: Runtime Error

Solution code:
import math
import copy

from functools import reduce

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

maxv = 0

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

for i in range(N):
    test = copy.copy(Value)
    del test[i]
    if maxv <= gcd_list(test):
        maxv = gcd_list(test)
        
print(maxv)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

max_gcd = 1

for n in range(N):
    tmp = A.copy()
    _ = tmp.pop(n)
    tmp_gcd = gcd(tmp)
    if max_gcd < tmp_gcd:
        max_gcd = tmp_gcd

print(max_gcd)

Submission status: Runtime Error

Solution code:
N  = int(input())

A_list_str = input().split()
A_list_int = list(map(int,A_list_str))

import math
from functools import reduce

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

GCD = 1
GCD_max = 1 
remove = 0

for i in range(N):
    remove = A_list_int.pop(i)
    GCD = gcd_list(A_list_int)
    A_list_int.insert(i,remove)
    if GCD > GCD_max:
        GCD_max = GCD

print(GCD_max)

Submission status: Runtime Error

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

g_list = []

if len(l) == 2:
  g_list.append(max(l[0],l[1]))
  
else:
    g = fractions.gcd(l[1],l[2])
    for j in range(3,N):
        if j != i:
            g = fractions.gcd(g,l[j])
    g_list.append(g)

    g = fractions.gcd(l[0],l[2])
    for j in range(3,N):
        if j != i:
            g = fractions.gcd(g,l[j])
    g_list.append(g)

    for i in range(N):
        g = fractions.gcd(l[0],l[1])
        for j in range(N):
            if j != i:
                g = fractions.gcd(g,l[j])
        g_list.append(g)

print(max(g_list))

Submission status: Runtime Error

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

def gcd(numbers):
    return reduce(math.gcd, numbers)
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
B = A
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
    A=B
print(max)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
#C
import numpy as np
import math
import re
from functools import reduce

n = int(input())

a = input()
a = re.split(" ",a)
a = list(map(int,a))
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

m = 0
for i in range(n):
    s = []
    for j in range(n):
        if j != i:
            s.append(a[j])
    x = gcd_list(s)
    if(x > m):
        m = x
print(m)

Submission status: Runtime Error

Solution code:
import math

n = int(input())

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

ans = 0
for i in range(n):
    flag = False
    j = 0
    if i == 0:
        tmp = a[1]
    else:
        tmp = a[0]
    while not flag and j != n:
        if j != i:
            tmp = math.gcd(tmp, a[j])
        if tmp == 1:
            flag = True
        j += 1
    if tmp > ans:
        ans = tmp

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int, input().split()))
import math
x=math.gcd(a[0], a[n-1])
y=math.gcd(a[0], a[n-2])
if n==2:
	x=max(a)
print(max(x, y))

Submission status: Runtime Error

Solution code:
from math import gcd
N = int(input())
A = list(map(int,input().split()))
# N=3
# A=[12 ,15 ,18]
l=[0]*N
r=[0]*N
l[0]=A[0]
r[0]=A[N-1]
for i in range(1,N-1):
    l[i]=gcd(l[i-1],A[i])
    r[i]=gcd(r[i-1],A[i])    
gcdlist = [l[N-2],r[N-2]]
for i in range(N-2):
    gcdlist.append(gcd(l[i],r[N-3-i]))
# print(gcdlist)
print(max(gcdlist))

Submission status: Runtime Error

Solution code:
import math

N=int(input())
A=list(map(int,input().split()))
a1=[]
a2=[]
for i in range(N-1):
    a1+=[math.gcd(A[N-1], A[i])]
    a2+=[math.gcd(A[0], A[i+1])]
a1.sort()
a2.sort()

if N>2:
    print(max(a1[1],a2[1]))
elif N==2:
    print(max(A))

Submission status: Runtime Error

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

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

def gcd_list(L):
    res = L[0]
    for l in L[1:]:
        res = gcd(res, l)
    return res

max_gcd = 1
for i in range(N):
    A_ = A.copy()
    A_.pop(i)
    tmp_gcd = gcd_list(A_)
    if tmp_gcd > max_gcd:
        max_gcd = tmp_gcd

print(max_gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
def gcd(*numbers):
    return reduce(math.gcd,numbers)
A=gcd(*a)
for i in range(n):
    c=a[i]
    del a[i]
    B=gcd(*a)
    if A<B:
        A=B
    else:
        A=A
    a.insert(i,c)
print(A)

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce

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

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

for i in range(N):
    test = copy.copy(Value)
    del test[i]
    if maxv <= gcd_list(test):
        maxv = gcd_list(test)
print(maxv)

Submission status: Runtime Error

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

A = list(set(A))
for i,a in enumerate(A):
    if len(A)==1:
        tmpA=A
        break
    tmpA = A[:i]+A[i+1:]
    while True:
        minA = min(tmpA)
        tmpA = set([a-minA for a in tmpA])
        tmpA.discard(0)
        if len(tmpA)==1:
            break

print(list(tmpA)[0])

Submission status: Runtime Error

Solution code:
import math

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

a.sort()

if n == 2:
    print(a[1])
else:
    gcd1 = math.gcd(a[0],a[1])
    gcd2 = math.gcd(a[1],a[2])
    gcd3 = math.gcd(a[0],a[2])

    ans = [gcd1, gcd2, gcd3]

    for i in range(3,n):
        if math.gcd(ans[0], i) < ans[0]:
            ans[0] = math.gcd(ans[0], i)

    for i in range(3,n):
        if math.gcd(ans[1], i) < ans[1]:
            ans[1] = math.gcd(ans[1], i)

    for i in range(3,n):
        if math.gcd(ans[2], i) < ans[2]:
            ans[2] = math.gcd(ans[2], i) 

    ans.sort()
    print(ans[-1])

Submission status: Runtime Error

Solution code:
import itertools
import fractions

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

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

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)


ans = 0
for i in range(n):
    gcd = gcd_list(A[0:i] + A[i + 1:])
    if (ans < gcd):
        ans = gcd

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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

cum_left = [A[0]]
cum_right = [A[N - 1]]
for i in range(1, N - 1):
    cum_left.append(gcd(cum_left[-1], A[i]))
    cum_right.append(gcd(cum_right[-1], A[N - 1 - i]))

ans = max(cum_left[N - 2], cum_right[N - 2])
for i in range(1, N - 1):
    ans = max(ans, gcd(cum_left[i - 1], cum_right[N - 2 - i]))
print(ans)

Submission status: Runtime Error

Solution code:
# C
import functools
def gcd(a,b):
    if a<b:a,b=b,a
    if a%b==0:return b
    return gcd(b,a%b)

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

for i in range(n):
    values = a[:i] + a[i+1:]
    gcd = functools.reduce(gcd, values)
    ans = max(ans, gcd)
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

if N == 2:
    print(max(A[0], A[1]))
else:
    a = math.gcd(A[0], A[1])
    b = math.gcd(A[0], A[2])
    c = math.gcd(A[1], A[2])
    print(max(a, max(b, c)))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import math

n = int(input())
a = input().split()
num1 = 10000000000
num2 = 10000000000

for i in range(n-1):
    w = math.gcd(int(a[i]),int(a[i+1]))
    if w < num1:
        num1 = w
    elif num1 <= w <= num2:
        num2 = w

if num2 == 10000000000:
    print(num1)
else:
    print(num2)

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce

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

N=int(input())

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

out=0

for i in range(N):
    t=copy.copy(A)
    t.pop(i)
    out=max(out,gcd(t))

print(out)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
n=3
a=[12,15,18]
def gcd(*numbers):
    return reduce(math.gcd,numbers)
A=gcd(*a)
for i in range(n):
    c=a[i]
    del a[i]
    B=gcd(*a)
    if A<B:
        A=B
    else:
        A=A
    a.insert(i,c)
print(A)

Submission status: Runtime Error

Solution code:
from math import gcd
N = int(input())
A = list(map(int,input().split()))
# N=3
# A=[12 ,15 ,18]
l=[0]*N
r=[0]*N
l[0]=A[0]
r[0]=A[N-1]
for i in range(1,N-1):
    l[i]=gcd(l[i-1],A[i])
    r[i]=gcd(r[i-1],A[i])    
gcdlist = [l[N-2],r[N-2]]
for i in range(N-2):
    gcdlist.append(gcd(l[i],r[N-3-i]))
print(gcdlist)
print(max(gcdlist))

Submission status: Runtime Error

Solution code:
import math

def solve(N, A):
    max_gcd = 0
    for i in range(N):
        lst = A[0:i]
        lst.extend(A[i + 1: N])
        gcd = lst[0]
        for j in range(1, len(lst)):
            gcd = math.gcd(gcd, lst[j])
        if gcd > max_gcd:
            max_gcd = gcd
    return max_gcd


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

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
li = []
li2 = []
for i in range(n-1):
    li.append(math.gcd(a[i],a[i+1]))
for i in range(n-2):
    li2.append(math.gcd(a[i],a[i+2]))
li = set(li)  | set(li2)
ans = max(li)
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import copy 

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

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

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
a=[int(x) for x in input().split()]
from collections import defaultdict
import math
d=defaultdict(int)
num_n=[]
num_n_1=[]
for ai in a:
    for i in range(1,int(math.sqrt(ai))+1):
        if ai%i==0:
            d[i]+=1
            d[ai//i]+=1
for key in d.keys():
    if d[key]==n:
        num_n.append(key)
    elif d[key]==n-1:
        num_n_1.append(key)
anses=[]
if num_n_1:
    anses.append(max(num_n_1))
if num_n:
    anses.append(max(num_n))
print(max(anses))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
from functools import reduce
import copy

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

max = 1

for i in range(0, N):
    tmp = np.array(Alist)
    if i != N - 1:
        tmp[i] = tmp[i + 1]
    else:
        tmp[i] = tmp[i - 1]
    gcd = reduce(math.gcd, tmp)
    if max < gcd:
        max = gcd

print(max)

Submission status: Runtime Error

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

from math import gcd
from functools import reduce

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

ans=[]
for i in range(N):
    B=A.copy()
    del B[i]
    ans.append(gcd_list(B))
    
print(max(ans))

Submission status: Runtime Error

Solution code:
import functools
import math

N = int(input())
a_list = list(map(int, input().split()))
gcd_list = []
for i in range(N):
    copied = a_list
    copied[i] = 1
    gcd = functools.reduce(math.gcd, copied)
    gcd_list.append(gcd)

print(max(gcd_list))

Submission status: Runtime Error

Solution code:
import functools
import math

N = int(input())


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

ans = 1
for i in range(N):
    tmp = A.copy()
    tmp.pop(i)
    gcd = int(functools.reduce(math.gcd, tmp))
    if gcd > ans:
        ans = gcd

print(ans)

Submission status: Runtime Error

Solution code:
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 > b:
        return euclid(b, a%b)
    else:
        return euclid(a, b%a)

biggest = 0
for i in range(n):
    for j in range(n-1):
        if j == i:
            pass
        elif j+1 == i:
            pass
        else:
            tmp = euclid(A[j],A[j+1]) 
            
    if tmp > biggest:
        biggest = tmp
print(biggest)

Submission status: Runtime Error

Solution code:
from functools import reduce
from math import gcd
n=int(input())
a=list(map(int,input().split()))
print(max(reduce(gcd, (a[i] for i in range(n) if i != j)) for j in range(n)))

Submission status: Runtime Error

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

def gcdList(num):
    return reduce(math.gcd, num)

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

for i in range(n):
    for j in range(n):
        tmp = copy.copy(a)
        tmp[j] = tmp[i]
        ans = max(ans, gcdList(tmp))
print(ans)

Submission status: Runtime Error

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
d=0
for i in range(n):
    for j in range(n):
        if(i != j):
            e=math.gcd(a[i],a[j])
            if(e > d):
                d = e
        else:
            continue
print(e)

Submission status: Runtime Error

Solution code:
import math
import copy

def gcd_(list):
  tmp = math.gcd(list[0], list[1])
  for i in range(len(list)):
    tmp = math.gcd(tmp, list[i])
  return tmp

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

b = copy.copy(a)
c = []

for i in range(n):
  del b[i]
  c.append(gcd_(b))
  b = copy.copy(a)
  
print(max(c))

Submission status: Runtime Error

Solution code:
# C
import functools import reduce
import math

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

for i in range(n):
    values = a[:i] + a[i+1:]
    gcd = reduce(math.gcd, values)
    ans = max(ans, gcd)
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

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

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

if __name__ == '__main__':
    main()

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

B = A.copy()
C = A.copy()

for n in range(N):
  del A[n]
  C[n] = gcd_list(A)
  A = B.copy()
  
ans = max(C)

print(ans)

Submission status: Runtime Error

Solution code:

import math


def gcd(nums):
    old = None
    for i in nums:
        if old is None:
            old = i
            continue

        old = math.gcd(old, i)

    return old


def resolv(nums, cnt):
    result = []
    for i in range(cnt):
        result.append(gcd(nums[0:i] + nums[i+1:cnt]))
    return result


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

print(max(resolv(A, N)))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
N = input()
A = input().split()

ret_max = 0

if N <= 2:
    print(max[A])
else:
    def gcd_list(numbers):
        return reduce(math.gcd, numbers)
    
    for i in range(len(A)):
        a = A.pop(i)
        tmp = gcd_list(a)
        if tmp > ret_max:
            ret_max = tmp
print(ret_max)

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce
import copy

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

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

Atmp = copy.deepcopy(A)

max = 0
for i in range(N):
    Atmp = copy.deepcopy(A)
    Atmp.pop(i)
    g = gcd_list(Atmp)
    if max < g:
        max = g
print(max)

Submission status: Runtime Error

Solution code:
import fraction
import numpy as np

def gcd_mul(numbers):
    s = fraction.gcd(numbers[0], numbers[1])
    for i in range(2, len(numbers)) :
        s = fraction.gcd(s, numbers[i])
    return(s)

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

ans = 0
for i in range(N) :
    B = A[np.arange(len(A))!=i]
    g = gcd_mul(B)
    if g > ans :
        ans = g
print(ans)

Submission status: Runtime Error

Solution code:
import functools
import fraction


N = int(input())
A = list(map(int, input().split()))
gcd_ans = []
for i in range(N):
    A_sub = (A[0:i]+A[i+1:N]).copy()
    gcd = functools.reduce(fraction.gcd, A_sub)
    gcd_ans.append(gcd)
print(max(gcd_ans))

Submission status: Runtime Error

Solution code:
import math

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

ans = 0
valid = []

for i in range(N):
  valid = A[:]
  valid.pop(i-1)
  valid_number = valid[0]
  for j in range(len(valid)):
    valid_number = math.gcd(valid_number,valid[j])
  ans = max(ans,valid_number)

print(ans)

Submission status: Runtime Error

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


gcd_l = [0] * n
gcd_r = [0] * n
for i in range(n):
    if i == 0:
        gcd_l[i] = A[i]
        gcd_r[-i-1] = A[-i-1]
    else:
        gcd_l[i] = gcd(gcd_l[i-1], A[i])
        gcd_r[-i-1] = gcd(gcd_r[-i], A[-i-1])

ans = [0] * n
ans[0] = gcd_r[1]
ans[n-1] = gcd_l[n-2]
for i in range(1, n-1):
    ans[i] = gcd(gcd_l[i-1], gcd_r[i+1])
print(max(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

def wa(rist, num):
  R = np.array([])
  for j in range(len(rist)):
    R.append(rist[j] // num)
  R = R[R != 0]
  if len(R) <= 1:
    return 0
  else:
    return 1
    

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

num = 0

for i in range(np.max(A)):
  me = wa(A, i)
  if me == 0:
    num = i
  else:
    pass
  
print(num)

Submission status: Runtime Error

Solution code:
import copy
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()))

g = []
for i in range(n):
    temp = copy.copy(a)
    del temp[i]
    g.append(gcd(*temp))

print(max(g))

Submission status: Runtime Error

Solution code:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

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

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

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

print(max(l))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

ans = 0
if n == 2:
    ans = max(aList)
else:
    for i in range(0,n):
        tmp = aList.pop(0)
        r = gcd(aList)
        if ans < r:
            ans = r
        aList.append(tmp)

print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
from functools import reduce

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

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

g_max = 1
for i in range(n):
    d = a_l.pop(0)
    g = gcd(a_l)
    # print(g)
    g_max = max(g, g_max)
    # print(d)
    a_l.append(d)

print(g_max)

Submission status: Runtime Error

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

import math

for i in range(N):
    for j in range(N):
        if i == j:
            pass
        else:
            if math.gcd(A[i], A[j]) > max_gcd:
                max_gcd = math.gcd(A[i], A[j])

print(max_gcd)

Submission status: Runtime Error

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = set(map(int, input().split()))
A = sorted(A)

ans = 1
for i in range(1, A[1]+1):
    if A[0] % i != 0 and A[1] % i != 0:
        continue
    else:
        if len(list(filter(lambda x: x % i != 0, A))) <= 1:
            ans = i
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

def wa(rist, num):
  R = np.array([])
  for j in range(len(rist)):
    R.append(rist[j] // num)
  R = R[R != 0]
  if len(R) <= 1:
    return 0
  else:
    return 1
    

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

num = 0

for i in range(np.max(A)):
  me = wa(A, i)
  if me = 0:
    num = i
  else:
    pass
  
print(num)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

ans = 1
for i in range(N):
    cand = gcd_list(A[:i] + A[i+1:])
    if cand > ans:
        ans = cand
print(ans)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
a = list(int(i) for i in input().split())
L = []
for i in range(N):
    a.pop(i)
    x = math.gcd(a)
    L.append(x)
print(max(L))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

N = int(input())

A = list(map(int, input().split()))
max_A = max(A)
gcd_list = []
for i in range(N):
    tmp = A[i]
    A[i] = max_A
    gcd = reduce(math.gcd, A)
    gcd_list.append(gcd)
    A[i] = tmp

print(max(gcd_list))
# 最大の値と変えてもいい

Submission status: Runtime Error

Solution code:
import math
import numpy as np

def gcd_mul(numbers):
    s = math.gcd(numbers[0], numbers[1])
    for i in range(2, len(numbers)) :
        s = math.gcd(s, numbers[i])
    return(s)

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

ans = 0
for i in range(N) :
    B = A[np.arange(len(A))!=i]
    g = gcd_mul(B)
    if g > ans :
        ans = g
print(ans)

Submission status: Runtime Error

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
l=list()
for i in range(n):
    for j in range(n):
        if(i != j):
            e=math.gcd(a[i],a[j])
            l.append(int(e))
        else:
            continue
print(max(l))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
n = int(input())
a = list(map(int, input().split()))

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

ans = 0
for i in range(n):
    c = a.pop(0)
    b = gcd(a)
    if b > ans:
        ans = b
    a.append(c)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
A_set = list(set(A))
if len(A_set)==2 and (A.count(A_set[0])==1 or A.count(A_set[1])==1):
  print(max(A))
elif len(A_set)==1:
  print(max(A))
else:
  for i in sorted(range(1,max(A)+1),reverse=True):
    tmp = [A[j]%int(i) for j in range(N)]
    tmp_set = list(set(tmp))
    if len(tmp_set)==2:
      if tmp.count(tmp_set[0])==1 or tmp.count(tmp_set[1])==1:
        ans = i
        break
  print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
Alist = list(map(int,input().split()))
a_list = []
for i in range(N):
    a_list = []
    for _ in Alist:
        a_list.append(_)
    A_copy.pop(i)
    a_list.append(np.gcd.reduce(A_copy))

print(max(a_list))

Submission status: Runtime Error

Solution code:
# C
import functools
import math

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

for i in range(n):
    values = a[:i] + a[i+1:]
    gcd = functools.reduce(math.gcd, values)
    ans = max(ans, gcd)
print(ans)

Submission status: Runtime Error

Solution code:
import math
def main():
    N = int(input())
    *A, = map(int, input().split())
    A.sort()
    gcds = []
    for i in range(1,N):
        gcds.append(math.gcd(A[0],A[i]))
    gcds.sort()
    if len(gcds) == 1:
        print(max(A))
    elif gcds[0] == gcds[1]:
        print(gcds[0])
    elif gcds[0] != gcds[1]:
        print(gcds[1])
main()

Submission status: Runtime Error

Solution code:

import math
#from functools import reduce


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


def resolv(nums, cnt):
    result = []
    for i in range(cnt):
        result.append(gcd(nums[0:i] + nums[i+1:cnt]))
    return result


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

print(max(resolv(A, N)))

Submission status: Runtime Error

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

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

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

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

print(max)

Submission status: Runtime Error

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

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

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

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

gc = [0] * (N-1)
for i in range(0,N-1):
    gc[i] = gcd(A[i],A[i+1])
#print(gc)
# このgcで最小のものが算出されるところを書き換えればよい？
# 連続してれば共通部、連続してないなら端とか？

mnd = -1
mn = 1e10
for i in range(0, N-1):
    if mn >= gc[i]:
        mnd = i
        mn = gc[i]

if mnd == N-1 and gc[-1] < gc[-2]:
    mnd = N-1

# 連続してれば後者になるのでmndはA[i]に対応することになる
# gcの長さはN-1

B = [a for a in A if a != A[mnd]]
#print(B)

lb = len(B)
if lb >= 2:
    g = B[0]
    for i in range(1, len(B)):
        g = gcd(g, B[i])
else:
    g = B[0]
print(g)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
from functools import reduce
import copy

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

max = 1

for i in range(0, N):
    tmp = np.array(copy.copy(Alist))
    if i != N - 1:
        tmp[i] = tmp[i + 1]
    else:
        tmp[i] = tmp[i - 1]
    gcd = reduce(math.gcd, tmp)
    if max < gcd:
        max = gcd

print(max)

Submission status: Runtime Error

Solution code:
import math

n = int(input())

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

ans = 0
for i in range(n):
    flag = False
    j = 0
    if(i==0):
        tmp = a[1]
    else:
        tmp = a[0]
    while(not(flag) and j!=n):
        if(j!=i):
            tmp = math.gcd(tmp, a[j])
        if(tmp==1):
            flag = True
        j += 1
    if(tmp>ans):
        ans = tmp
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 = input().split()
m = [int(a) for a in A]
ans = 0
for i in range(n):
    B = m[:]
    B.pop(i)
    cand = gcd_list(B)
    if cand > ans:
        ans = cand
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import math

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

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

Submission status: Runtime Error

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

N = int(input())
A = [int(i) for i in input().split()]
G = []
for i in range(N):
    b = A.pop(0)
    G.append(gcd_list(A))
    A.append(b)
G.sort()
print(G[-1])