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:
#-*- using:utf-8 -*-

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

def gcd(a,b):
#    print("gcd %d %d" %(a,b))
    n = 0
    if a == b:
        return a
    elif a > b:
        n = euclidean(a,b)

    elif a < b:
        n = euclidean(b,a)

    else:
        pass

    return n 

def blackboard(n,a):
    candidate = 0
    maxnum = 0
    b = list(map(int,a))


    k = n - 1
    for j in range(n):
        c = [b[p] for p in range(n)]
        del c[j]
#        print("b %s" %b)
#        print("c %s" %c)
        ml = 0
        mr = 0
        for i in range(k):
#            print("i=>%d" %i)

            ml = gcd(ml,c[i])
            mr = gcd(mr,c[k-i-1])
#            print("ml %d" %ml)
#            print("mr %d" %mr)
            if i == k-i-1:
                break
#        print("ml %d mr %d" %(ml,mr))
        candidate = gcd(ml,mr)
#        print("!!!!!!!!!!!!!!!!candidate %d max %d" %(candidate,maxnum))
        if candidate > maxnum:
            maxnum = candidate
            
#        print("maxnum %d" %maxnum)
        


    return maxnum


if __name__ == '__main__':
    n = raw_input()
    a = raw_input().split()
    global m 
    m = int(n)
    print("%d" %(blackboard(m,a)))

Submission status: Time Limit Exceeded

Solution code:
import fractions
import itertools
import collections

n = int(input().split()[0])
a_list = list(map(int, input().split()))

def koyakusu(x):
    i = 1
    koyaku_list = []
    while i * i <= x:
        if x % i == 0:
            koyaku_list.append(i)
            koyaku_list.append(x//i)
        i += 1

    koyaku_list = list(set(koyaku_list))
    return koyaku_list

# 最大公約数の最大値
gcd_list = []
all_koyaku_list_list = []
for a in a_list:
    koyaku_list = koyakusu(a)
    # print('{}: {}'.format(a, koyaku_list))
    all_koyaku_list_list.append(koyaku_list)

all_koyaku_list = list(itertools.chain.from_iterable(all_koyaku_list_list))
c = collections.Counter(all_koyaku_list)

kouho_list = [k for k, v in c.items() if v in [n, n-1]]
# print(kouho_list)
ans = max(kouho_list)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a%b)
n = int(input())
l = list(map(int,input().split()))
import collections
c=collections.Counter(l)
mc=c.most_common()
s_d=set(i[0] for i in mc if i[1]>=2)
ans=1
s=set(l)
for i in range(n):
    s_new=copy.deepcopy(s)
    if l[i] not in s_d:
        s_new.remove(l[i])
    g = l[(i+1)%2]
    for j in s_new:
        g=gcd(g,j)
    if g>ans:ans=g
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions as f
import itertools as it
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
for i in range(N):
    C=A.copy()
    del C[i]
    if len(C)==1:
        print(max(A))
        exit()
    else:
        b=list(it.accumulate(C,f.gcd))
        B[i]=b[-1]     
print(max(B))

Submission status: Time Limit Exceeded

Solution code:
import operator
class SegmentTree:
    def __init__(self, size, default, op = operator.add):
        self.size = 1
        while self.size < size:
            self.size *= 2
        self.dat = [default]*(self.size*2-1)
        self.op = op

    def update(self, i, x):
        i += self.size - 1
        self.dat[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.dat[i] = self.op(self.dat[i*2+1], self.dat[i*2+2])

    def add(self, i, x):
        i += self.size - 1
        self.dat[i] = self.op(self.dat[i], x)
        while i > 0:
            i = (i - 1) // 2
            self.dat[i] = self.op(self.dat[i], x)

    def get(self, a, b, k = None, l = None, r = None):
        if k is None:
            k = 0
            l = 0
            r = self.size

        if r <= a or b <= l:
            return None

        if a <= l and r <= b:
            return self.dat[k]

        res_l = self.get(a, b, k*2+1, l, (l+r)//2)
        res_r = self.get(a, b, k*2+2, (l+r)//2, r)
        if res_l is None:
            return res_r
        if res_r is None:
            return res_l
        return self.op(res_l, res_r)


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

n = int(input())
a = list(map(int, input().split()))
seg = SegmentTree(n,0,gcd)
for i in range(n):
    seg.update(i,a[i])
ans = 1
for i in range(n):
    ans = max(ans, gcd(seg.get(0,i),seg.get(i+1,n)))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from copy import *
from sys import *
import math
import queue
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)

#dp[i][j]: iまでからj枚えらんで和がkになるのは何通り
def main():
	n = int(input())
	a = list(map(int,input().split()))
	m = []
	for i in range(n):
		tmp = a[0] if i!=0 else a[1]
		for j in range(n):
			if(i==j): continue
			tmp = gcd(tmp,a[j])
		m.append(tmp)
	print(max(m))
			


def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

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

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Time Limit Exceeded

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


def gcd_over2(list_gcd):
    if len(list_gcd) == 1:
        return list_gcd[0]
    if list_gcd == []:
        return 1
    c = gcd(list_gcd[0], list_gcd[1])
    if len(list_gcd) <= 2:
        return c
    for i in range(1, len(list_gcd)-1):
        c = gcd(c, list_gcd[i + 1])
    return c


a1 = input()

a = input().split()
a = sorted([int(i) for i in a])
c = gcd_over2(a)
a = [i / c for i in a]

g = 0

for u in range(len(a)):
    list_new1 = [a[i] for i in range(len(a)) if i != u]
    g3 = gcd_over2(list_new1)
    if g3 > g:
        g = g3


print(int(c * g))

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a%b)
n = int(input())
lst = list(map(int,input().split()))
lst_gcd =[]
ans=1
for i in range(n):
    lst_new = lst[:i]+lst[i+1:]
    g = lst_new[0]
    for j in lst_new:
        g=gcd(g,j)
    if g>ans:ans=g
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict


def divisor(n):  # nの約数を全て求める
    i = 1
    div_set = set()
    while i * i <= n:
        if n % i == 0:
            div_set.add(i)
            div_set.add(n//i)
        i += 1
    return div_set


def divisor2(n):  # 既存のリストからnの約数だけを返す
    div_set = set()

    for i in kouho:
        if i > n:
            return div_set
        if n % i == 0:
            div_set.add(i)
    return div_set


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

divcount = defaultdict(int)
for n in A_list[:2]:
    for i in divisor(n):
        divcount[i] += 1

kouho = list(divcount.keys())
kouho.sort()
# print(kouho)

for n in A_list[2:]:
    for i in divisor2(n):
        divcount[i] += 1

# print(divcount)
max_divisor = 0
for key, value in divcount.items():
    if value >= N - 1 and key > max_divisor:
        max_divisor = key

print(max_divisor)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict


def divisor(n):  # nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    div_set = set(table)
    return div_set


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

divcount = defaultdict(int)
for n in A_list:
    for i in divisor(n):
        divcount[i] += 1

# print(divcount)

max_divisor = 0
for key, value in divcount.items():
    if value >= N - 1 and key > max_divisor:
        max_divisor = key

print(max_divisor)

Submission status: Time Limit Exceeded

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

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

lis = []
ans = 0

for i in range(N):
	lis = []
	for j in range(N):
		if i != j:
			lis.append(A[j])
	tmp = lis[0]
	for i in range(len(lis)-1):
		tmp = gcd(tmp,lis[i+1])
	ans = max(ans, tmp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
i = max(a)
while True:
    count = 0
    for j in range(n):
        if a[j] % i == 0:
            count += 1
    if count >= n - 1:
        print(i)
        break
    i -= 1

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

def GCD(lis):
    ans = lis[0]
    for i in range(1, len(lis)):
        ans = fractions.gcd(ans, lis[i])
    return ans

ans = 0
for i in range(n):
    b = a.copy()
    del b[i]
    ans_ = GCD(b)
    if ans_ > ans:
        ans = ans_

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

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

l = [a[0]]
r = [a[-1]]
for i in range(n-1):
  l.append(gcd(l[-1], a[i+1]))
  r.insert(0, gcd(r[0], a[-2-i]))

maxi = max(l[-2], r[1])
for i in range(1, n-1):
  maxi = max(maxi, gcd(l[i-1], r[i+1]))
print(maxi)

Submission status: Time Limit Exceeded

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########

N = i_inpl()
A = l_inpl()

# a, bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

# リストnumbers最大公約数
def gcdlist(numbers):
    a = numbers[0]
    for i in range(len(numbers)):
        a = gcd(a, numbers[i])
    return a

l = []
for i in range(N):
    tmp = A[i]
    A[i] = 0
    l.append(gcdlist(A))
    A[i] = tmp

print(max(l))

Submission status: Time Limit Exceeded

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

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

ans = 0

for i in range(N):
    newA = list(A)
    del newA[i]
    temp = 0
    for j in range(N-1):
        temp = gcd(temp, newA[j])
    ans = max(temp, ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#最大公約数
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

#最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)

#最大公約数（複数）
def gcds(l):
    if len(l) == 1:
        return l[0]
    elif len(l) == 2:
        return gcd(l[0], l[1])
    else:
        n = len(l) // 2
        L = l[:n]
        R = l[n:]
        return gcd(gcds(L), gcds(R))

#最小公倍数(複数)
def lcms(l):
	if len(l) == 1:
		return l[0]
	elif len(l) == 2:
		return lcm(l[0], l[1])
	else:
		n = len(l) // 2
		L = l[:n]
		R = l[n:]
		return lcm(lcms(L), lcms(R))

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

mm = []
import copy

for i in range(n):
	temp = copy.deepcopy(a)
	temp.pop(i)
	mm.append(gcds(temp))
print(max(mm))

Submission status: Time Limit Exceeded

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

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

c = list(itertools.combinations(a,n-1))
ans = 1
for i in c:
  ans = max(ans,gcd_list(i))
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(max(a),0,-1):
  cnt = 0
  for j in a:
    if j % i != 0:
      cnt+=1
  if cnt < 2:
    print(i)
    break

Submission status: Time Limit Exceeded

Solution code:
import fractions as f

N = int(input())

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

rightGCD = []
leftGCD = []

rightGCD.append(0)
tmp = 0
for x in A[:-1:]:
    tmp = f.gcd(tmp,x)
    rightGCD.append(tmp)

leftGCD.insert(0,0)
tmp = 0
for x in A[:0:-1]:
    tmp = f.gcd(tmp,x)
    leftGCD.insert(0,tmp)

#print(leftGCD)
#print(rightGCD)

ans = 0

for i in range(N):
    if i==0:
        ans = max(ans,leftGCD[i])
        continue
    if i==N-1:
        ans = max(ans,rightGCD[i])
        continue

    ans = max(ans,f.gcd(rightGCD[i],leftGCD[i]))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
import fractions

n = int(input())

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

for i in range(n):
    temp = a_li.copy()
    temp.pop(i)
    gcd = functools.reduce(fractions.gcd, temp)
    if ans < gcd:
        ans = gcd
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
import fractions
import numpy as np
n = int(input())

a_li = list(map(int, input().split()))
ans = 0
a_li = np.array(a_li)
for i in range(n):
    temp = a_li.copy()
    temp = np.delete(temp, i)
    gcd = functools.reduce(fractions.gcd, temp)
    if ans < gcd:
        ans = gcd
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
import fractions
import numpy as np
n = int(input())

a_li = list(map(int, input().split()))
ans = 0
a_li = np.array(a_li)
for i in range(n):
    temp = a_li.copy()
    temp = np.delete(temp, i)
    gcd = gcd = functools.reduce(fractions.gcd, temp)
    if ans < gcd:
        ans = gcd
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
import fractions

n = int(input())

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

for i in range(n):
    temp = a_li.copy()
    temp.pop(i)
    gcd = gcd = functools.reduce(fractions.gcd, temp)
    if ans < gcd:
        ans = gcd
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
ans = reduce(fractions.gcd, a)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import itertools as it

N = int(input())
a = list(map(int, input().split()))
ccb = it.combinations(a, int(N-1))

tmp = []
for element in ccb:
	tmp.append((element))

ans = 0

for i in tmp:
    hoge = list(i)
    pairgcd = hoge[0]
    for k in range(len(hoge)):
        pairgcd = fractions.gcd(pairgcd, hoge[k])
    if pairgcd > ans:
        ans = pairgcd

print(ans)

Submission status: Time Limit Exceeded

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

a.sort()

prime = []
for i in range(N):
    count = 0
    for j in range(len(prime)):
        if a[i] % prime[j] == 0 :
            count = 1
    if count == 0 :
        prime.append(a[i])


 
gcd = []
for i in range(len(prime)):
    list_not_i = a.copy()
    list_not_i.remove(prime[i])
    gcd.append(functools.reduce(fractions.gcd, list_not_i))
 
print(max(gcd))

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


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


def gcd_m(*args):
    if len(args) == 0:
        return 0
    if len(args) == 1:
        return args[0]
    if len(args) >= 2:
        ret = gcd(args[0], args[1])

    for value in args[2:]:
        ret = gcd(ret, value)
    return ret


def solve(inputs):
    [N] = string_to_int(inputs[0])
    A = [0] + (string_to_int(inputs[1])) + [0]
    # A = string_to_int(inputs[1])

    if N == 2:
        return max(A)

    left_gcd_memo = [0]

    max_num = 0
    for i in range(1, len(A)):
        right = A[i+1:]

        left_gcd = gcd_m(left_gcd_memo[-1], A[i-1])
        left_gcd_memo.append(left_gcd)
        right_gcd = gcd_m(*right)

        g = gcd(left_gcd, right_gcd)
        if g > max_num:
            max_num = g

    return max_num


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


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


def gcd_m(a, b, *args):
    ret = gcd(a, b)
    for value in args:
        ret = gcd(ret, value)
    return ret


def solve(inputs):
    [N] = string_to_int(inputs[0])
    A = deque(string_to_int(inputs[1]))

    if N == 2:
        return max(A)

    max_num = 0
    for _ in range(0, len(A)):
        tmp = A.popleft()
        result = gcd_m(*A)
        if result > max_num:
            max_num = result
        A.append(tmp)
    return max_num


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

ans = 0

for i in range(n): # 無効にする
  cd = -1
  for j in range(n):
    if i==j:
      continue
    if cd < 0:
      cd = a[j]
    else :
      cd = fractions.gcd(cd,a[j])      
  if ans < cd:
    ans = cd
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
import math
import fractions
N = int(input())
a = list(map(int, input().split()))
 
gcd = []
for i in range(N):
    list_not_i = a.copy()
    list_not_i.remove(a[i])
    gcd.append(functools.reduce(fractions.gcd, list_not_i))
 
print(max(gcd))

Submission status: Time Limit Exceeded

Solution code:
import fractions  # python3.5以降ではmath


def seekGcd(A, n):
    ans = A[0]
    for i in range(1, n):
        ans = fractions.gcd(ans, A[i])  # python3.5以降ではmath.gcd
    ans_list.append(ans)


n = int(input())
A = list(tuple(map(int, input().split())))
n = len(A)
ans_list = []

for i in range(n):
    p = A.pop(0)
    seekGcd(A, n-1)
    A.append(p)

print(max(ans_list))

Submission status: Time Limit Exceeded

Solution code:
import fractions  # python3.5以降ではmath


def seekGcd(A, n):
    ans = A[0]
    for i in range(1, n):
        ans = fractions.gcd(ans, A[i])  # python3.5以降ではmath.gcd
    ans_list.append(ans)


n = int(input())
A = list(map(int, input().split()))
ans_list = []

for i in range(n):
    p = A.pop(0)
    seekGcd(A, n-1)
    A.append(p)

print(max(ans_list))

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(1000000)

import fractions
from functools import reduce

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

def mygcd(a,b):
    if a==0:
        return b
    elif b==0:
        return a
    else:
        return fractions.gcd(a,b)


def L(n):
    if n==-1:
        return 0
    else:
        return mygcd(L(n-1),A[n])

def R(n):
    if n==N:
        return 0
    else:
        return mygcd(R(n+1),A[n])

ans=1
for i in range(N):
    c=mygcd(L(i-1),R(i+1))
    ans=max(ans,c)

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

ans=1
for i in range(N):
    b=A[:i]+A[i+1:]
    c=reduce(fractions.gcd, b)
    ans=max(ans,c)

print(ans)

Submission status: Time Limit Exceeded

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

    res = {}
    for a in A:
        for divisor in divisors(a):
            if divisor not in res:
                res[divisor] = 1
            else:
                res[divisor] += 1

    print(max([key for key, value in res.items() if value == N or value == N - 1]))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)


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


def xgcd(a):
    size = len(a)
    if size == 1:
        return a[0]
    if size == 2:
        return gcd(a[0], a[1])

    la = a[:size // 2]
    ra = a[size // 2:]

    return gcd(xgcd(la), xgcd(ra))


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


ans = 0
for i in range(n):
    tmp = a[i]
    a[i] = a[i - 1]
    ans = max(ans, xgcd(a))
    a[i] = tmp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
   
M = 1  
for i in range(0,N):
  L1 = X[:i]
  R1 = X[i+1:]
  if not L1:
    M = max(M, gcd_list(R1))
  elif not R1:
    M = max(M, gcd_list(L1))
  else:
    L = gcd_list(L1)
    R = gcd_list(R1)
    M = max(M, fractions.gcd(L,R))

print(M)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
N = int(input())
X = list(map(int, input().split()))
 
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
  
gcd = 1
 
for i in range(N):
  Y = X.pop(i)
  gcd_1 = gcd_list(X)
  gcd = max(int(gcd), int(gcd_1))
  if gcd in X:
    break
  X.insert(i,Y)
print(gcd)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
N = int(input())
X = list(map(int, input().split()))

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

for i in range(N):
  Y = X.pop(i)
  gcd_1 = gcd_list(X)
  gcd = max(int(gcd), int(gcd_1))
  X.insert(i,Y)
print(gcd)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
N = int(input())
a = list(map(int, input().split()))
a_max = max(a)
ans = 0

for i in range(len(a)):
    save = a[i]
    a[i] = a_max
    gcd = reduce(fractions.gcd, a)
    if gcd > ans:
        ans = gcd
    a[i] = save
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import functools
import fractions

def resolve():
	mx=0
	n=int(input())
	a=list(map(int,input().split()))
	for i in range(n):
		l=a[::]
		l.pop(i)
		mx=max(functools.reduce(fractions.gcd,l),mx)
	print(mx)
resolve()

Submission status: Time Limit Exceeded

Solution code:
import functools
def gcd(a,b):
	m=max(a,b)
	n=min(a,b)
	return n if m%n==0 else gcd(n,m%n)

def resolve():
	mx=0
	n=int(input())
	a=list(map(int,input().split()))
	for i in range(n):
		l=a[::]
		l.pop(i)
		mx=max(functools.reduce(gcd,l),mx)
	print(mx)
resolve()

Submission status: Time Limit Exceeded

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


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


lcmTable = [0 for w in range(N)]
for k in range(0, N):
    T = A.pop(0)
    lcmT = A[0]
    for i in range(1, N - 1):
        lcmT = lcm(lcmT, A[i])
    lcmTable[k] = lcmT
    A.append(T)
print(max(lcmTable))

Submission status: Time Limit Exceeded

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

import fractions
from functools import reduce

def gcd(numbers):
    return reduce(fractions.gcd, numbers)
ans = 0
for idx, num in enumerate(A):
  result = gcd(A[:idx:]+A[idx+1::])
  if result > ans:
    ans = result
print(ans)

Submission status: Time Limit Exceeded

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

import math
import fractions
from functools import reduce

def gcd(numbers):
    return reduce(fractions.gcd, numbers)
ans = 0
for idx, num in enumerate(A):
  result = gcd(A[:idx:]+A[idx+1::])
  if result > ans:
    ans = result
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import fractions
from functools import reduce

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

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

N = int(input())
arr = list(map(int, input().split()))
GCD = 0
max_GCD = 0

for i in range(N):
    GCD = gcd(*(arr[0:i] + arr[i + 1::]))
    if max_GCD < GCD:
        max_GCD = GCD
print(max_GCD)

Submission status: Time Limit Exceeded

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

def search_cd(a):
  common_div = 0
  for a_i in a:
    common_div = gcd(a_i, common_div)
  return common_div

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

m = max([search_cd(a[:i] + a[i+1:]) for i in range(n)])
  
print(m)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce


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


N = int(input())
a = list(map(int, input().split()))
ans = [0]*N
for i in range(0, N):
    tmp = a.pop(0)
    ans[i] = gcd_list(a)
    a.append(tmp)

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

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
N = int(input())
A=[int(i) for i in input().split()]
B=[]
def list_gcd(a):
    l = len(a)
    if l ==1:
        return(a[0])
    elif l ==2:
        return(fractions.gcd(a[0],a[1]))
    else:
        k = l//2 
        return(fractions.gcd(list_gcd(a[:k]),list_gcd(a[k:])))
b = []
for i in range(N):
    if i>0 and i<N-1:
        a = A[:i]+A[i+1:]
    elif i == 0:
        a = A[1:]
    else:
        a = A[:N-1]
    b.append(list_gcd(a))
print(max(b))

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
import copy
N = int(input())
A=[int(i) for i in input().split()]
B=[]
def list_gcd(a):
    return reduce(fractions.gcd , a)
b = []
for i in range(N):
    if i>0 and i<N-1:
        a = A[:i]+A[i+1:]
    elif i == 0:
        a = A[1:]
    else:
        a = A[:N-1]
    b.append(list_gcd(a))
print(max(b))

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
import copy
N = int(input())
A=[int(i) for i in input().split()]
B=[]
def list_gcd(a):
    return reduce(fractions.gcd , a)
b = []
for i in range(N):
    a = copy.copy(A)
    a.remove(A[i])
    b.append(list_gcd(a))
print(max(b))

Submission status: Time Limit Exceeded

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

def gcd2(array):
    t = array[0]
    for i in array:
        t = gcd(t,i)
    return t
    

n=int(input())
a=list(map(int,input().split()))
m = 0
for i in range(n):
    m = max(m,gcd2(a[:i]+a[i+1:]))
print(m)

Submission status: Time Limit Exceeded

Solution code:
#C
import fractions
List = []
n = int(input())
A = list(map(int, input().split()))

for j in range(n):
    a = A[:j] + A[j+1:]
    ans = a[0]
    for i in range(1, n-1):
        ans = fractions.gcd(ans, a[i])
    List.append(ans)
    
print(max(List))

Submission status: Time Limit Exceeded

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

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

d = {}
m = []

if len(A) == 2:
    print(max(A))
    exit()

for i in range(N):
    _A = []
    _A.extend(A[0:i])
    _A.extend(A[i+1:N])

    for j in range(1, len(_A)):
        if j == 1:
            tmp = gcd(_A[j], _A[j-1])
        else:
            tmp = gcd(_A[j], tmp)
    m.append(tmp)
print(max(m))

Submission status: Time Limit Exceeded

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

    return divisors


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

d = {}
for a in A:
    for x in make_divisors(a):
        d[x] = d.get(x, 0) + 1

print(sorted([(k,v) for k,v in d.items() if v >= N-1], key=lambda x: -x[0])[0][0])

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

import copy

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

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

ans = 1

for i in range(n):
  m = copy.copy(l)
  m.pop(i)
  gcd = gcd_list(m)
  if gcd > ans:
    ans = gcd

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

import copy

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

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

ans = 1

for i in range(n):
  m = copy.copy(l)
  m.pop(i)
  if gcd_list(m) > ans:
    ans = gcd_list(m)

print(ans)