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: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

N = int(input())
A = list(map(int,input().split()))
g_max = 0
for i in range(N):
    B = A.copy()
    B[i:i+1] = []
    g = reduce(fractions.gcd,B)
    if g_max < g:
        g_max = g
print(g_max)

Submission status: Time Limit Exceeded

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

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

if N == 2:
    print(max(A))
else:
    for i in range(N):
        B = A[:]
        B.pop(i)
        element =gcd(B[0], B[1])
        if N == 3:
            ans = max(ans, element)
        else:
            for j in range(2, N-1):
                element = gcd(element, B[j])
            ans = max(ans, element)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from functools import reduce

input = sys.stdin.readline

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

def gcds(nums):
    return reduce(gcd, nums)

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

ans = 0
for i in range(len(a)):
    if i == 0:
        l = 0
    else:
        l = gcds(a[:i])
    if i == len(a)-1:
        r = 0
    else:
        r = gcds(a[(i+1):])
    aaa = gcd(l, r)
    if ans < aaa:
        ans = aaa
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import math
from functools import reduce

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

def gcds(nums):
    return reduce(gcd, nums)

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

ans = 0
for i in range(len(a)):
    if i == 0:
        l = 0
    else:
        l = gcds(a[:i])
    
    if i == len(a) - 1:
        r = 0
    else:
        r = gcds(a[(i+1):])
    
    aaa = gcd(l, r)
    
    if ans < aaa:
        ans = aaa
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = [int(s) for s in input().split(" ")]
As.sort()
if N==2:
  print(As[-1])
  import sys
  sys.exit(0)

m = As[1]
count = 0
ans = 1
for i in range(2, m+1):
  for a in As:
    if(a % i != 0):
      count +=1
      if count == 2:
        break
  if count<2:
    ans = i
  count = 0
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import math
from functools import reduce

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

def gcds(nums):
    return reduce(gcd, nums)

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

ans = 0
for i in range(len(a)):
    aa = a[:i] + a[(i+1):]
    if ans < gcds(aa):
        ans = gcds(aa)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions 
from functools import reduce

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

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

ans = 0
for i in range(len(a)):
    aa = a[:i] + a[(i+1):]
    if ans < gcd(aa):
        ans = gcd(aa)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

ans_l = []
for i in range(len(a)):
    aa = a[:i] + a[(i+1):]
    ans_l.append(gcd(aa))
ans = max(ans_l)
print(ans)

Submission status: Time Limit Exceeded

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

import fractions
import copy
from functools import reduce

#最大公約数を求める関数
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

l = []
temp_A = A
for i in range(N):
    temp_A = copy.deepcopy(A)
    del temp_A[i]
    l.append(gcd_list(temp_A))

print(max(l))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = []
for i in range(N):
    X = A[:i] + A[i+1:]
    for v in range(max(X), 0, -1):
        if all([x % v == 0 for x in X]):
            M.append(v)
print(max(M))

Submission status: Time Limit Exceeded

Solution code:
import fractions
import functools

N = int(input())
A_array = [int(A_i_str) for A_i_str in input().split()]

min_score = max(A_array)
min_score_idx = 0

A_gcd = {}
for i, A_i in enumerate(A_array):
  for A_j in A_array[i + 1:]:
    A_min = min(A_i, A_j)
    A_max = max(A_i, A_j)
    A_gcd[(A_min, A_max)] = fractions.gcd(A_i, A_j)

for i, A_i in enumerate(A_array):
  score = sum([A_gcd[min(A_i, A_j), max(A_i, A_j)] for A_j in A_array[:i] + A_array[i+1:]])
  if min_score > score or (min_score == score and A_i < A_array[min_score_idx]):
    min_score = score
    min_score_idx = i
A_array[min_score_idx] = max(A_array)
print(functools.reduce(fractions.gcd, A_array))

Submission status: Time Limit Exceeded

Solution code:
import copy

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

#Aの最小値の次に小さな値より大きな数字にはなりえない
for n in range(N):
    B = copy.deepcopy(A)
    B[n] = max(B)
    B = sorted(B)

    for b in reversed(range(1, min(B) + 1)):
        if sum(list(map(lambda x: x % b, B))) == 0:
            max_list.append(b)
            break
print(max(max_list))

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

ans = 0
b = []
for i in range(n):
   b = a[:]
   b.pop(i)
   ans = max(ans,gcd_list(b))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def GCD(a, b):
    """ Euclidean algorithm"""
    if a < b: (a, b) = (b, a)
    m = a % b
    while m != 0:
        a = b
        b = m
        m = a % b
    return b

def GCD_of(a):
    """ Calc gcd of an array a"""
    allgcd = a[0]
    for value in a:
        allgcd = GCD(value, allgcd)
        if allgcd == 1:
            return allgcd
    return allgcd

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

if N < 2 and 1e5 < N: raise()
for v in A:
    if v < 1 and v < 1e9: raise()

result = 0
for skip in range(N):
    tmp_max = GCD_of( [ A[i] for i in range(N) if not i == skip ] )
    if result < tmp_max: result = tmp_max
print(result)

Submission status: Time Limit Exceeded

Solution code:
def GCD(a, b):
    """ Euclidean algorithm"""
    if a < b: (a, b) = (b, a)
    m = a % b
    while m != 0:
        a = b
        b = m
        m = a % b
    return b

def GCD_of(a):
    """ Calc gcd of an array a"""
    allgcd = a[0]
    for value in a:
        allgcd = GCD(allgcd, value)
    return allgcd

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

if N < 2 and 1e5 < N: raise()
for v in A:
    if v < 1 and v < 1e9: raise()

result = 0
for skip in range(N):
    tmp_max = GCD_of( [ A[i] for i in range(N) if not i == skip ] )
    if result < tmp_max: result = tmp_max
print(result)

Submission status: Time Limit Exceeded

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

N = int(input())
A = list(map(int, input().split()))
M = []
for i in range(N):
  AA = A[:i] + A[i + 1:]
  g = 0
  for j in range(len(AA)):
    g = gcd(g, AA[j])
  M.append(g)
print(max(M))

Submission status: Time Limit Exceeded

Solution code:
def GCD(a, b):
    """ Euclidean algorithm"""
    if a < b: (a, b) = (b, a)
    m = a % b
    while m != 0:
        a = b
        b = m
        m = a % b
    return b

def GCD_of(a):
    """ Calc gcd of an array a"""
    allgcd = a[0]
    for value in a:
        allgcd = GCD(allgcd, value)
    return allgcd

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

if N < 2 and 1e5 < N: raise()
for v in A:
    if v < 1 and v < 1e9: raise()

result = 0
for skip in range(N):
    tmp_max = GCD_of( [ A[i] for i in range(N) if not i == skip ] )
    if result < tmp_max: result = tmp_max
print(result)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
n = int(input())
b = [int(i) for i in input().split()]
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
ma = 0
for i in range(n):
    c = b[:]
    c.pop(i)
    m = gcd_list(c)
    ma = max(m,ma)
    #print(c)
print(ma)

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
A = list(map(int, input().split()))
C=[]
for i in range(N):
     C.append(copy.copy(A))
B = []
for i in range(N):
    del C[i][i]
    B.append(C[i])
import math
import fractions
from functools import reduce
D =[] #Aから一つを除いたものの最大公約数のリスト
for i in range(N):
    D.append(reduce(fractions.gcd,B[i]))
maxi = max(D)
print(maxi)

Submission status: Time Limit Exceeded

Solution code:
def gcd(n1,n2):
    if n1 < n2:
        bi = n2
        sm = n1
    else:
        bi = n1
        sm = n2
    a = sm
    b = bi
    c = b // a
    d = b % a
    while d > 0:
        b = a
        a = d
        c = b // a
        d = b % a
    return a
        
n = int(input())
li = [int(i) for i in input().split()]
gc = 1
for i in range(len(li)):
    tar = li[0]
    del li[0]
    c0 = li[0]
    for i in range(len(li)):
        c0 = gcd(c0,li[i])
    if c0 > gc:
        gc = c0
    li.append(tar)
print(gc)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

maxgcd = 0
for i in range(len(a)):
    temp = gcd(a[:i] + a[i + 1:])
    if temp > maxgcd:
        maxgcd = temp

print(maxgcd)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

def arrGcd(arr):
	ans = arr[0]
	for i in range(1, len(arr)):
		ans = gcd(ans, arr[i])
	return ans

n = int(input().strip())
arr = list(map(int, input().strip().split()))

maxVal = -1
for i in range(n):
	temp = arr[:i] + arr[i+1:]
	g = arrGcd(temp)
	maxVal = max(maxVal, g)
print(maxVal)

Submission status: Time Limit Exceeded

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

def gcd(a,b):
    m=max(a,b)
    n=min(a,b)
    while n!=0:
        l=m%n
        m=n
        n=l
    return m

def all_gcd(*args):
    n=len(args)
    g=args[0]
    for i in range(n):
        if args[i]%g!=0:
            g=gcd(g,args[i])
    return g

gl=0
for i in range(N):
    l=[lis[j] for j in range(N) if j!=i]
    if all_gcd(*l)>gl:
        gl=all_gcd(*l)

print(gl)

Submission status: Time Limit Exceeded

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

def gcd(a,b):
    m=max(a,b)
    n=min(a,b)
    while n!=0:
        l=m%n
        m=n
        n=l
    return m

def all_gcd(*args):
    n=len(args)
    g=args[0]
    for i in range(n):
        g=gcd(g,args[i])
    return g

gl=0
for i in range(N):
    l=[]
    for j in range(N):
        if j!=i:
            l+=[lis[j]]
    if all_gcd(*l)>gl:
        gl=all_gcd(*l)

print(gl)

Submission status: Time Limit Exceeded

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

def gcd(a,b):
    m=max(a,b)
    n=min(a,b)
    while n!=0:
        l=m%n
        m=n
        n=l
    return m

def all_gcd(*args):
    n=len(args)
    g=args[0]
    for i in range(n):
        g=gcd(g,args[i])
    return g

gl=[]
for i in range(N):
    l=[]
    for j in range(N):
        if j!=i:
            l+=[lis[j]]
    gl+=[all_gcd(*l)]

print(max(gl))

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

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

ret = gcd_list(a[1:n])
for i in range(1, n-1):
  gcd = fractions.gcd( gcd_list(a[0:i]), gcd_list(a[i+1:n]) )
  if ret < gcd :
    ret = gcd
gcd = gcd_list(a[0:n-1])
if ret < gcd :
  ret = gcd
print(ret)

Submission status: Time Limit Exceeded

Solution code:
import math
import functools
import fractions
from functools import reduce
import itertools

gcd1 = 0
gcd2 = 0
ans = 0

N = int(input())
values = ([int(x) for x in input().split()])
for i in range(len(values)):
  tem = values.pop(i)
  gcd1 = functools.reduce(fractions.gcd,values)
  values.insert(i,tem)
  if gcd1>gcd2:
    gcd2 = gcd1
    ans = gcd1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import functools
 
 
n = int(input())
a = list(map(int, input().split()))
nl = set(range(n))
gcd_list = [0]
for i in nl:
    tmp, a[i] = a[i], 0
    gcd_list.append(functools.reduce(fractions.gcd, a))
    a[i] = tmp
ans = max(gcd_list)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

N = int(input())
A = list(map(int, input().split()))
l = []
for i in range(N):
    B = A[:]
    B.pop(i)
    l.append(reduce(fractions.gcd, B))
    
print(max(l))

Submission status: Time Limit Exceeded

Solution code:

#NOT AC

import fractions
import functools

# 整数の入力
n = input()
n = int(n)

# いくつあるかわからないときのスペース区切りの整数の入力
a = input().split()
a = list(map(int,a))

gcdlist = [0] * n

i = 0
for i in range(0,n):
    check = [0] * n
    check[:] = a[:] #リストのコピーの時の作法
    del check[i]
    #print(check)
    #ここでcheckのリストの最大公約数をもとめればよい
    gcdlist[i] = functools.reduce(fractions.gcd, check)
    #print(gcdlist)

#print(gcdlist)

j = max(gcdlist)

print(j)

#a[j] = gcdlist[j]

#print(functools.reduce(math.gcd,a))

Submission status: Time Limit Exceeded

Solution code:

#NOT AC

import functools
#import math
import fractions

# 整数の入力
n = input()
n = int(n)

# いくつあるかわからないときのスペース区切りの整数の入力
a = input().split()
a = list(map(int,a))

gcdlist = [0] * n

i = 0
for i in range(0,n):
    check = [0] * n
    check[:] = a[:] #リストのコピーの時の作法
    del check[i]
    #gcdlist[i] = functools.reduce(math.gcd, check)
    gcdlist[i] = functools.reduce(fractions.gcd, check)

#print(gcdlist)

j = max(gcdlist)

print(j)

#a[j] = gcdlist[j]

#print(functools.reduce(math.gcd,a))

Submission status: Time Limit Exceeded

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

dic = {}
for i, x in enumerate(a):
    if i <2:
        for y in make_divisors(x):
            if y in dic:
                dic[y] += 1
            else:
                dic[y] = 1
    else:
        l = make_divisors(x)
        for k,v in dic.items():
            if k in l:
                dic[k]+=1

        dic = {k:v for k,v in dic.items() if v>i-1}
        
for k,v in sorted(dic.items(), reverse=True):
    print(k)
    exit()

Submission status: Time Limit Exceeded

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

dic = {}
for x in a:
    for y in make_divisors(x):
        if y in dic:
            dic[y] += 1
        else:
            dic[y] = 1

for k,v in sorted(dic.items(), reverse=True):
    if v >= n-1:
        print(k)
        exit()

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy
n = int(input())
list_a = list(map(int, input().split()))

max_value = 0

for i in range(n):
    list_temp = copy.copy(list_a)
    del list_temp[i]
    temp=list_temp[0]
    for i in range(n-1):
        temp=fractions.gcd(temp, list_temp[i])
    if max_value<temp:
        max_value = temp

print(max_value)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
import sys
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
a2 = a.copy()
res = []
for i in range(0,n):
    a2.pop(i)
    res.append(reduce(fractions.gcd,a2))
    a2 = a.copy()
print(max(res))

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy
from functools import reduce
import sys
def gcd_list(numbers):
    return reduce(fractions.gcd,numbers)
  
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
a2 = copy.copy(a)
res = []
for i in range(0,n):
    a2.pop(i)
    res.append(gcd_list(a2))
    a2 = copy.copy(a)
print(max(res))

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd,numbers)
n = int(input())
a = list(map(int,input().split()))
a2 = copy.copy(a)
res = []
for i in range(0,n):
    a2.pop(i)
    res.append(gcd_list(a2))
    a2 = copy.copy(a)
print(max(res))

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy
from functools import reduce
 
def gcd_list(numbers):
    return reduce(fractions.gcd,numbers)
  
n = int(input())
a = list(map(int,input().split()))
a2 = copy.deepcopy(a)
res = []
for i in range(0,n):
    a2.pop(i)
    res.append(gcd_list(a2))
    a2 = copy.deepcopy(a)
print(max(res))

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy

def gcd_list(numbers):
    ans = numbers[0]
    for i in range(1,n-1):
        ans = fractions.gcd(ans,numbers[i])
    return ans
  
n = int(input())
a = list(map(int,input().split()))
a2 = copy.deepcopy(a)
res = []
for i in range(0,n):
    a2.pop(i)
    res.append(gcd_list(a2))
    a2 = copy.deepcopy(a)
print(max(res))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
def k(n,x):
    if x==0:
        return n
    else:
        return k(x,n%x)
L=[0 for i in range(n)]
R=[0 for i in range(n)]
T=0
for i in a[1:]:
    T=k(i,T)
ans=[T]
for i in range(n-1):
    L[i]=k(a[i],L[i-1])

    for j in range(i+2,n):
        R[i]=k(a[j],R[i])

    ans+=[k(L[i],R[i])]
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
# ユークリッドの互除法
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def gcd_for_list(target_list, begin_idx, end_idx):
    ans = 0
    for x in target_list[begin_idx:end_idx]:
        ans = gcd(ans,x)
    return ans

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


ans = 1

for i in range(1,n+1):
    left = gcd_for_list(aa,0,i-1)
    right = gcd_for_list(aa,i,n)
    temp = gcd(left, right)
    ans = max(ans, temp)
    # print(aa[0:i-1],left, aa[i:n],right)
print(ans)

Submission status: Time Limit Exceeded

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

n=int(input())
a=[int(s) for s in input().split()]
gcd_l=[]
gcd_r=[]
gcd_ans=[]
gcd_ans.append(gcd_list(a[1::]))
for i in range(1,len(a)-1):
    gcd_l.append(gcd_list(a[:i]))
    gcd_r.append(gcd_list(a[i+1:]))
gcd_ans.append(gcd_list(a[:len(a)-1]))

for j in range(len(a)-2):
    gcd_ans.append(gcd(gcd_l[j],gcd_r[j]))

print(max(gcd_ans))

Submission status: Time Limit Exceeded

Solution code:
import fractions, itertools
from functools import reduce

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

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

ans = 0
comblist = list(itertools.combinations(tuple(A), N-1))
for l in comblist:
    tmp = gcd(l)
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
import fractions

N = int(input())
A = list(map(int, input().split()))
answer = 0
for i in range(N):
  tmp = A.copy()
  tmp.pop(i)
  gcd = functools.reduce(fractions.gcd, tmp)
  
  if answer < gcd:
    answer = gcd

print(int(answer))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
 
import fractions
from functools import reduce
 
def gcd(numbers):
    return reduce(fractions.gcd, numbers)
 

def calc_gcd(nums):
    if n==2:
        return max(nums)
    cnt = 0
    for i in range(n):
        tmp = nums.copy()
        del tmp[i]
        g = gcd(tmp)
    
        if g > cnt:
            cnt = g

    return cnt    

print(calc_gcd(l))

Submission status: Time Limit Exceeded

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

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

for i in range(N):
  if i==0:
    g=A[1]
  else :
    g=A[0]
  for j in range(N):
    if i!=j:
      g=gcd(g,A[j])
  l.append(g)
  
print(max(l))

Submission status: Time Limit Exceeded

Solution code:

# coding: utf-8

# In[1]:

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


# In[2]:

import copy
#import numpy as np


# In[3]:

def get_divisor_list(A):
    divisor_list = [1]
    if A == 1:
        return divisor_list
    else:
        for i in range(2, A//2+1):
            if A%i == 0:
                divisor_list.append(i)
        divisor_list.append(A)
        return divisor_list


# In[4]:

all_db = []
for i in range(N):
    all_db.append(set(get_divisor_list(A[i])))
#print(all_db)


# In[5]:

gcd_list = []
for i in range(N):
    all_dbc = copy.copy(all_db)
    all_dbc.pop(i)
    gcds = all_dbc[0].intersection(*all_dbc)
    gcd_list.append(max(gcds))
print(max(gcd_list))


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:

# coding: utf-8

# In[1]:

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


# In[2]:

import copy
#import numpy as np


# In[3]:

def get_divisor_list(A):
    divisor_list = [1]
    if A == 1:
        return divisor_list
    else:
        for i in range(2, A//2+1):
            if A%i == 0:
                divisor_list.append(i)
        divisor_list.append(A)
        return divisor_list


# In[4]:

all_db = []
for i in range(N):
    all_db.append(set(get_divisor_list(A[i])))
#print(all_db)


# In[5]:

gcd_list = []
for i in range(N):
    all_dbc = copy.copy(all_db)
    all_dbc.pop(i)
    gcds = all_dbc[0].intersection(*all_dbc[1:])
    gcd_list.append(max(gcds))
print(max(gcd_list))


# In[ ]:

"""
try:
    from math import gcd as ogcd
except:
    from fractions import gcd as ogcd
from functools import reduce

def gcd(*numbers):
    return reduce(ogcd, numbers)
"""


# In[4]:

"""
gcd_list = []
for i in range(N):
    Ac = copy.copy(A)
    Ac.pop(i)
    #print(Ac)
    gcd_list.append(gcd(*Ac))
"""


# In[5]:

#print(np.max(np.array(gcd_list)))


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
import fractions as frac
from functools import reduce

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

def gcd_with_replace(numbers, replace_index) :
    numbers = numbers[:]
    numbers[replace_index] = 0
    return gcd_list(numbers)

def main() :
    N = int(input())
    A_list = [int(i) for i in input().split()]
    # A_list.reverse()
    max_gcd_value = 0
    for i in range(N) :
        gcd_value = gcd_with_replace(A_list,i)
        if (max_gcd_value < gcd_value) :
            max_gcd_value = gcd_value
    
    print(max_gcd_value)



main()

Submission status: Time Limit Exceeded

Solution code:

# coding: utf-8

# In[1]:

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


# In[2]:

import copy
import numpy as np


# In[3]:

try:
    from math import gcd as ogcd
except:
    from fractions import gcd as ogcd
from functools import reduce

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


# In[4]:

gcd_list = []
for i in range(N):
    Ac = copy.copy(A)
    Ac.pop(i)
    #print(Ac)
    gcd_list.append(gcd(*Ac))


# In[5]:

print(np.max(np.array(gcd_list)))


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
import fractions
n=int(input())
a=list(map(int,input().split()))
ans=1
for i in range(n):
    ai=a[:i]+a[i+1:]
    while len(ai)>1:ai.append(fractions.gcd(ai.pop(),ai.pop()))
    ans=max(ans,ai[0])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions
from functools import reduce

def input():
	return sys.stdin.readline()

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

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

ans = 0
for i in range(N):
	if i == 0:
		A_ = A[1:]
	elif i == N-1:
		A_ = A[:-1]
	else:
		A_ = A[:i]+A[i+1:]
	ans = max(ans, gcd(A_))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions

n = int(input())
As = sorted(list(map(int, input().split(" "))))
largest = 1

for i in range(n):
  gcd = 0
  for idx, j in enumerate(As):
    if idx == i:
      continue
    gcd = j if gcd==0 else fractions.gcd(gcd, j)
    if gcd <= largest:
      break
  if gcd > largest:
    largest = gcd
    if largest == As[0] or largest == As[1]:
      break
print(largest)

Submission status: Time Limit Exceeded

Solution code:
import fractions

n = int(input())
As = sorted(list(map(int, input().split(" "))))
maxa = As[0]
largest = 1

for i in range(n):
  gcd = 0
  prev = 0
  for idx, j in enumerate(As):
    if idx == i:
      continue
    gcd = j if gcd==0 else fractions.gcd(gcd, j)
    if gcd <= largest:
      break
  if gcd > largest:
    largest = gcd
print(largest)

Submission status: Time Limit Exceeded

Solution code:
import fractions

n = int(input())
As = list(map(int, input().split(" ")))
maxa = max(As)
largest = 1

for i in range(n):
  gcd = 0
  for idx, j in enumerate(As):
    if idx == i:
      continue
    gcd = j if gcd==0 else fractions.gcd(gcd, j)
    if gcd <= largest:
      break
  if gcd > largest:
    largest = gcd
    if largest == maxa:
      break

print(largest)

Submission status: Time Limit Exceeded

Solution code:
import fractions

n = int(input())
As = list(map(int, input().split(" ")))
maxa = max(As)
largest = 1

for i in range(n):
  gcd = 0
  for idx, j in enumerate(As):
    if idx == i:
      continue
    gcd = j if gcd==0 else fractions.gcd(gcd, j)
    if gcd <= largest:
      break
  if gcd > largest:
    largest = gcd
    if largest == max:
      break

print(largest)

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

largest = 1

for i in range(n):
  gcd = 0
  for idx, j in enumerate(As):
    if idx == i:
      continue
    gcd = j if gcd==0 else fractions.gcd(gcd, j)
    if gcd <= largest:
      break
  if gcd > largest:
    largest = gcd

print(largest)

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions
from functools import reduce

def input():
	return sys.stdin.readline()

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

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

ans = 0
for i in range(N):
	if i == 0:
		A_ = A[1:]
	elif i == N-1:
		A_ = A[:-1]
	else:
		A_ = A[:i]+A[i+1:]
	ans = max(ans, gcd(A_))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from functools import reduce
from itertools import combinations

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

pattern = list(combinations(a,(len(a)-1)))
#print(pattern)
#print(pattern[0][0])

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

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

max = 0
for i in range(len(pattern)):
    #print(pattern[i])
    #print(gcd_list(pattern[i]))
    #print(gcd_list(pattern[i]))
    temp = gcd_list(pattern[i])
    if(temp > max):
        max = temp

print(max)

Submission status: Time Limit Exceeded

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

n=int(input())
al=input().split()
al_i = [int(s) for s in al]

m = 0
for x in range(n):
   if (m < al_i[x]):
      m = al_i[x]

gm = 0

for x in range(n):
   t = al_i[x]
   al_i[x] = m
   g = al_i[0]
   for y in range(n):
      g = gcd(g,al_i[y]) 
   al_i[x] = t
   if g>gm:
      gm = g
print(gm)

Submission status: Time Limit Exceeded

Solution code:
import fractions

n=int(input())
al=input().split()
al_i = [int(s) for s in al]
m = max(al_i)
gm = 0

for x in range(n):
   t = al_i[x]
   al_i[x] = m
   g = al_i[0]
   for y in range(n):
      g = fractions.gcd(g,al_i[y]) 
   al_i[x] = t
   if g>gm:
      gm = g
print(gm)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

n=int(input())
al=input().split()
al_i = [int(s) for s in al]
m = max(al_i)
gm = 0

for x in range(n):
   t = al_i[x]
   al_i[x] = m
   g = gcd(*al_i)
   al_i[x] = t
   if g>gm:
      gm = g
print(gm)

Submission status: Time Limit Exceeded

Solution code:
import fractions


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

left_gcd_list = [a[0]]
right_gcd_list = [a[n - 1]]

for i in range(1, n):
    left_gcd_list.append(fractions.gcd(a[i], left_gcd_list[i - 1]))
    right_gcd_list.insert(0, fractions.gcd(a[n - 1 - i], right_gcd_list[0]))

print(max([left_gcd_list[n - 2]] +
          [fractions.gcd(left_gcd_list[i], right_gcd_list[i + 2]) for i in range(0, n - 2)] +
          [right_gcd_list[1]]))


if __name__ == '__main__':
    pass

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

max_gcd = 1
for skip in range(N):
  first = True
  for i,an in enumerate(alist):
    if i == skip:
      continue
    elif first:
      gcd = an
      first = False
      
    gcd = fractions.gcd(gcd,an)
    if gcd < max_gcd:
      break
    
  if max_gcd < gcd:
    max_gcd = gcd
    
print(max_gcd)