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

N = int(input())

line = [int(a) for a in input().split()]
line = deque(line)

def check(inf):
  return reduce(gcd, inf)
m=0
for i in range(N):
  x = line.pop()
  g = check(line)
  if g>m:
    m = g
  line.appendleft(x)

print(m)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce
from collections import deque

N = int(input())

line = [int(a) for a in input().split()]
line = deque(line)

def check(inf):
  return reduce(gcd, inf)
m=0
for i in range(N):
  x = line.pop()
  g = check(line)
  if g>m:
    m = g
  line.appendleft(x)

print(m)

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

def gcd(l):
    if len(l)>=2:
        for i in range(1,len(l)):
            l[i]=fractions.gcd(l[i-1],l[i])
    return l[-1]

for i in range(n):
    work[i]=work[i-1]
    ans.append(gcd(work))
    work=a[:]
print(max(ans))

Submission status: Time Limit Exceeded

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

def solve(A, i):
    ans = A[0]
    if i == 0:
        ans = A[1]
    for j in range(len(A)):
        if j == i:
            continue
        ans = gcd(ans, A[j])
    return ans

# print(N, A)
B = []
for i in range(len(A)):
    B.append(solve(A, i))

print(max(B))

Submission status: Time Limit Exceeded

Solution code:
import fractions as mt
from functools import reduce
def gcd(nums):
    return reduce(mt.gcd, nums)
N = int(input())
A = list(map(int, input().split()))
g = []
for i in range(N):
    g.append(gcd(A[:i]+A[i+1:]))
print(max(g))

Submission status: Time Limit Exceeded

Solution code:
import functools
import copy
def gcd_strategy():
    import math
    import fractions
    return math.gcd if hasattr(math, "gcd") else fractions.gcd
gcd = gcd_strategy()


n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  l=a.copy()
  del l[i]
  ans=max(ans,functools.reduce(gcd, l))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions as fs
from functools import reduce

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

gcd_max = 1
for n in range(N):
    num = A.pop(n)
    gcd = reduce(fs.gcd, A)

    if gcd_max < gcd:
        gcd_max = gcd

    A.insert(n, num)

print(gcd_max)

Submission status: Time Limit Exceeded

Solution code:
import fractions as fs
from functools import reduce

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


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


gcd_max = 1
for n in range(N):
    num = A.pop(n)
    gcd = gcd_list(A)

    if gcd_max < gcd:
        gcd_max = gcd

    A.insert(n, num)

print(gcd_max)

Submission status: Time Limit Exceeded

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

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

def gcd(list1) :
    global dol
    lngt = len(list1)
    tuple1 = tuple(list1)
    if lngt == 1 :
        return list1[0]
    elif tuple1 in dol.keys() :
        return dol[tuple1]
    else :
        rt = ea(gcd(list1[:lngt//2]), gcd(list1[lngt//2:]))
        dol[tuple1] = rt
        return rt

dol = {}
anslist = []
for n in range(N) :
    anslist.append(gcd(Alist[:n]+Alist[n+1:]))
print(max(anslist))

Submission status: Time Limit Exceeded

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

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

def gcd(list1) :
    global dol
    lngt = len(list1)
    tuple1 = tuple(list1)
    if tuple1 in dol.keys() :
        return dol[tuple1]
    elif lngt == 1 :
        return list1[0]
    else :
        rt = ea(gcd(list1[:lngt//2]), gcd(list1[lngt//2:]))
        dol[tuple1] = rt
        return rt

dol = {}
anslist = []
for n in range(N) :
    anslist.append(gcd(Alist[:n]+Alist[n+1:]))
print(max(anslist))

Submission status: Time Limit Exceeded

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

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

def gcd(list1) :
    global dol
    lngt = len(list1)
    list2 = tuple(list1)
    if list2 in dol.keys() :
        return dol[list2]
    elif lngt == 1 :
        return list1[0]
    else :
        rt = ea(gcd(list1[:lngt//2]), gcd(list1[lngt//2:]))
        dol[list2] = rt
        return rt

dol = {}
ans = 1
for n in range(N) :
    ans = max(ans, gcd(Alist[:n]+Alist[n+1:]))
print(ans)

Submission status: Time Limit Exceeded

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

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

def gcd(list1) :
    for m in range(N-2) :
        list1 = [ea(list1[0], list1[1])] + list1[2:]
    else :
        return list1[0]


ans = 1
for n in range(N) :
    ans = max(ans, gcd(Alist[:n]+Alist[n+1:]))
print(ans)

Submission status: Time Limit Exceeded

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

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

def gcd(list1) :
    global dol
    list2 = tuple(list1)
    if list2 in dol.keys() :
        return dol[list2]
    else :
        for m in range(N-2) :
            list1 = [ea(list1[0], list1[1])] + list1[2:]
        else :
            dol[list2] = list1[0]
            return list1[0]

dol = {}
ans = 1
for n in range(N) :
    ans = max(ans, gcd(Alist[:n]+Alist[n+1:]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, fractions
from collections import deque
input = sys.stdin.readline

N = int(input())
A = deque(int(i) for i in input().split())
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
import sys, fractions
input = sys.stdin.readline

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

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

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

ans2=0
for i in range(N):
    AA=A[:i]+A[i+1:]
    ans=0
    for j in range(N-1):
        ans=fractions.gcd(ans,AA[j])
    ans2=max(ans,ans2)
    #print(AA,ans,ans2)

print(ans2)

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 =[]
for i in range(n):
    lst_new = lst[:i]+lst[i+1:]
    g = lst_new[0]
    for j in range(n-1):
        g=gcd(g,lst_new[j])
    lst_gcd.append(g)
print(max(lst_gcd))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

import numpy as np

input()
A = np.array(list(map(int, input().split())))
N = len(A)
if N <= 2:
    print(max(A))
    exit()

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

ans = 1
for ptr in range(N):
    li = np.concatenate([A[:ptr], A[ptr+1:]])
    g = li[0]
    for i in li[1:]:
        g = gcd(g,i) if g > i else gcd(i,g)
    ans = max(ans, g)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy
from functools import reduce

import sys
sys.setrecursionlimit(100000000) 

def l(i):
    if i==0:
        return 0
    else:
        return fractions.gcd(l(i-1),A[i-1])

def r(i):
    if i==N:
        return 0
    else:
        return fractions.gcd(r(i+1),A[i])

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

ans=[]
if N==2:
    ans.append(max(A))
else:
    for i in range(N):
        ans.append(fractions.gcd(l(i),r(i+1)))

print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy
from functools import reduce

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

ans=1
if N==1:
    ans=10**9
elif N==2:
    ans=max(A)
else:
    for a in A:
        A2=copy.deepcopy(A)
        A2.remove(a)
        ans=max(ans,reduce(fractions.gcd, A2))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce
from copy import deepcopy
N=int(input())
l=list(map(int,input().split()))
dp=[]
for i in range(N):
	t=deepcopy(l)
	t.pop(i)
	dp.append(reduce(gcd,t))
print(max(dp))

Submission status: Time Limit Exceeded

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

import sys
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd

def input(): return sys.stdin.readline().strip()
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

class SegTree:
    """
    以下のクエリを処理する
    1.update:  i番目の値をxに更新する
    2.get_val: 区間[l, r)の値を得る
    """
 
    def __init__(self, n, func, init):
        """
        :param n: 要素数
        :param func: 値の操作に使う関数(min, max, addなど)
        :param init: 要素の初期値
        """
        n += 1
        self.n = n
        self.func = func
        self.init = init
        # nより大きい2の冪数
        n2 = 1
        while n2 < n:
            n2 <<= 1
        self.n2 = n2
        self.tree = [self.init] * (n2 << 1)
 
    def update(self, i, x):
        """
        i番目の値をxに更新
        :param i: index(0-indexed)
        :param x: update value
        """
        i += self.n2
        self.tree[i] = x
        while i > 1:
            self.tree[i >> 1] = x = self.func(x, self.tree[i ^ 1])
            i >>= 1
 
    def get_val(self, a, b):
        """
        [a, b)の値を得る
        :param a: index(0-indexed)
        :param b: index(0-indexed)
        """
        return self._get_val(a, b, 1, 0, self.n2)
 
    def _get_val(self, a, b, k, l, r):
        """
        [a, b)の値を得る内部関数
        :param k: 現在調べている区間のtree内index
        :param l, r: kが表す区間の左右端index [l, r)
        :return: kが表す区間と[a, b)の共通区間内での最小値。共通区間を持たない場合は初期値
        """
        # 範囲外なら初期値
        if r <= a or b <= l:
            return self.init
        # [a,b)が完全に[l,r)を包含するならtree[k]の値を採用
        if a <= l and r <= b:
            return self.tree[k]
        # 一部だけ範囲内なら2つに分けて再帰的に調査
        m = (l + r) // 2
        return self.func(
            self._get_val(a, b, k << 1, l, m),
            self._get_val(a, b, (k << 1) + 1, m, r)
        )

N=INT()
A=[0]+LIST()+[0]

st=SegTree(N+2, gcd, 0)
for i in range(N+2):
    st.update(i, A[i])

ans=0
for i in range(1, N+1):
    ans=max(ans, gcd(st.get_val(0, i), st.get_val(i+1, N+2)))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(x, y):
    while y:
        amari = x % y
        x = y
        y = amari
    return x
 
def main():
    n = int(input())
    a = [int(a) for a in input().split()]
 
    maxv = 0
    for i in range(n):
        a_ = a[:i] + a[i+1:]
        gcdv = a_[0]
        for j in range(1, n-1):
            gcdv = gcd(gcdv, a_[j])
        if maxv < gcdv:
            maxv = gcdv
    print(maxv)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

L = [A[0]]
R = [A[-1]]

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

		
for i in range(1, N):
	L.append(gcd(L[-1], A[i]))
	R.insert(0, gcd(R[0], A[N - i - 1]))
	
# print(L, R)
high = 1

for i in range(N):
	if i == 0:
		ans = R[1]
	elif i == N - 1:
		ans = L[-2]
	else:
		ans = gcd(L[i - 1], R[i + 1])
	if ans > high:
		high = ans
		
print(high)

Submission status: Time Limit Exceeded

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

L = [A[0]]
R = [A[-1]]

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

		
for i in range(1, N):
	L.append(gcd(L[-1], A[i]))
	R.insert(0, gcd(R[0], A[N - i - 1]))
	
# print(L, R)
high = 1

for i in range(N):
	if i == 0:
		ans = R[1]
	elif i == N - 1:
		ans = L[-2]
	else:
		ans = gcd(L[i - 1], R[i + 1])
	if ans > high:
		high = ans
		
print(high)

Submission status: Time Limit Exceeded

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


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


def gcd_list(num_list):
    for i, num in enumerate(num_list):
        if i == 0:
            g = num
        else:
            g = Gcd(num, g)
    return g

GCD = 0
for i in range(N):
    others = A[:]
    others.pop(i)
    gcd = gcd_list(others)
    if gcd > GCD:
        GCD = gcd
print(GCD)

Submission status: Time Limit Exceeded

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


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


def gcd_list(num_list):
    for i, num in enumerate(num_list):
        if i == 0:
            g = num
        else:
            g = Gcd(num, g)
    return g

GCD = 0
for i in range(N):
    others = A[:]
    others.pop(i)
    gcd = gcd_list(others)
    if gcd > GCD:
        GCD = gcd
print(GCD)

Submission status: Time Limit Exceeded

Solution code:
import copy
from collections import deque

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

max_a = max(a)

def gcd(n, m):
    if m == 0:
        return n
    
    return gcd(m, n % m)

ans = 0

if len(a) == 1:
    print(a[0])
    exit()

for i in range(n):
    _a = copy.deepcopy(a)

    del _a[i]

    que = deque(_a)

    while len(que) > 1:
        n = que.pop()
        m = que.pop()
        l = gcd(n, m)
        
        que.append(l)

    tmp_max = que.pop()
    ans = max(ans, tmp_max)

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):
    a_except_for_i = a[:i] + a[i + 1:]
    l.append(reduce(fractions.gcd, a_except_for_i))
print(max(l))

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from itertools import combinations
from fractions import gcd
 
def get_gcd(number_list):
    return reduce(gcd, number_list)
 
N = int(input())
Numbers = list(map(int, input().split()))
 
skipped = list(combinations(Numbers, N - 1))
 
gcd_list = [get_gcd(item) for item in skipped]
    
print(int(max(gcd_list)))

Submission status: Time Limit Exceeded

Solution code:

from functools import reduce
from itertools import combinations
from fractions import gcd

def get_gcd(number_list):
    return reduce(gcd, number_list)

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

skipped = list(map(list, combinations(Numbers, N - 1)))

gcd_list = [get_gcd(item) for item in skipped]
    
print(int(max(gcd_list)))

Submission status: Time Limit Exceeded

Solution code:
#ずっとre
from fractions import gcd
from functools import reduce

def get_gcd(number_list):
    return reduce(gcd, number_list)

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

gcd_list = [get_gcd(Numbers[:i] + Numbers[i + 1:]) for i in range(N)]
    
print(int(max(gcd_list)))

Submission status: Time Limit Exceeded

Solution code:
#ずっとre
from fractions import gcd
from functools import reduce

def get_gcd(number_list):
    return reduce(gcd, number_list)

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

gcd_list = [0] * N
for i in range(N):
    tmp_list = Numbers[:i] + Numbers[i + 1:]
    gcd_list[i] = get_gcd(tmp_list)
    
print(int(max(gcd_list)))

Submission status: Time Limit Exceeded

Solution code:
#ずっとre
from fractions import gcd
from functools import reduce

def get_gcd(number_list):
    return reduce(gcd, number_list)

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

gcd_list = []
for i in range(N):
    tmp_list = Numbers[:i] + Numbers[i + 1:]
    gcd_list.append(get_gcd(tmp_list))
print(int(max(gcd_list)))

Submission status: Time Limit Exceeded

Solution code:
import functools,fractions
def lgcd(list):
  return functools.reduce(fractions.gcd, list)

n = int(input())
nums = list(map(int,input().split()))
cand = []
cand.append(lgcd(nums[1:]))
cand.append(lgcd(nums[:-1]))
for i in range(n-2):
  i += 1
  cand.append(lgcd(nums[:i]+nums[i+1:]))
print(max(cand))

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()))
output=0

for i in range(N):
        M = [A[i-1]]
        hoge = A[i]
        A[i] = A[i-1]
        for k in range(N):
                M.append(gcd(M[k],A[k]))

        if M[N] >= output:
                output = M[N]
        A[i]=hoge

print(output)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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


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

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


for i in range(N):
        hoge = A[i]
        A[i] = A[i-1]
        if gcd_list(A) >= output:
                output = gcd_list(A)
        A[i]=hoge

print(output)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from itertools import chain

N = input()
a = [int(x) for x in stdin.readline().split()]

a_divs = [{x for x in range(1, a_val + 1) if a_val % x == 0} for a_val in a]
all_divs = set(chain.from_iterable(a_divs))

for cnd in sorted(all_divs, reverse=True):
    missing_count = 0
    is_c_divs = True
    for a_each_divs in a_divs:
        if cnd not in a_each_divs:
            missing_count = missing_count + 1
        if missing_count == 2:
            is_c_divs = False
            break
    if is_c_divs:
        print(cnd)
        break

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

N = input()
a = [int(x) for x in stdin.readline().split()]

ans = 0

for i in range(len(a)):
    mn = min(a[:i] + a[i + 1:])
    for cnd in range(mn, 0, -1):
        is_c_div = True
        for a_j in a[:i] + a[i + 1:]:
            if a_j % cnd != 0:
                is_c_div = False
                break
        if is_c_div:
            ans = max(ans, cnd)
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce
n=int(input())
a=[int(i) for i in input().split()]
x=[]
for i in range(1,n+1):
    b=a.pop(-i)
    x.append(reduce(gcd,a))
    a.append(b)
print(max(x))

Submission status: Time Limit Exceeded

Solution code:

import fractions
import sys

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

if n1 == 2:
    print(max(nl1))
    sys.exit()

r1 = 0
n2 = fractions.gcd(nl1[0], nl1[1])

if n1 >= 3:
    n2 = max(n2, fractions.gcd(nl1[1], nl1[2]))
    n2 = max(n2, fractions.gcd(nl1[0], nl1[2]))

c1 = 0
for i2 in range(n1):
    if nl1[i2] % n2 != 0:
        c1 += 1
    if c1 >= 2:
        break
    if i2 == (n1 - 1):
        r1 = n2

i3 = n2

while r1 == 0:
    c1 = 0
    for i4 in range(n1):
        if nl1[i4] % i3 != 0:
            c1 += 1
        if c1 >= 2:
            break
        if i4 == (n1 - 1):
            r1 = i3
    i3 -= 1

print(str(r1))

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0

nl1.sort(reverse=True)
for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r2 = nl2[0]
    for i3 in range(n1 - 1):
        r2 = fractions.gcd(r2 ,nl2[i3 + 1])
        if r2 <= r1:
            break

    r1 = max(r1,r2)

print(str(r1))

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0

nl1.sort()
for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r2 = nl2[0]
    for i3 in range(n1 - 1):
        r2 = fractions.gcd(r2 ,nl2[i3 + 1])
        if r2 <= r1:
            break

    r1 = max(r1,r2)

print(str(r1))

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0

for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r2 = nl2[0]
    for i3 in range(n1 - 1):
        r2 = fractions.gcd(r2 ,nl2[i3 + 1])
        if r2 <= r1:
            break

    r1 = max(r1,r2)

print(str(r1))

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0
for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r2 = nl2[0]
    for i3 in range(n1 - 1):
        r2 = fractions.gcd(r2 ,nl2[i3 + 1])

    r1 = max(r1,r2)

print(str(r1))

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy
from functools import reduce

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

n1 = int(input())
nl1 = [int(i1) for i1 in input().split()]

r1 = 0
for  i2 in range(n1):
    nl2 = copy.copy(nl1)
    if i2 == 0:
        nl2[i2] = nl1[1]
    else:
        nl2[i2] = nl1[i2 - 1]
    r1 = max(r1,gcd_list(nl2))

print(str(r1))

Submission status: Time Limit Exceeded

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

def gcd(*a):
  return reduce(fractions.gcd, a)
if len(a)==2:
  print(max(*a))
else:
  print(max([gcd(*list(i)) for i in itertools.combinations(a,len(a)-1)]))

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

ans = []
for i in range(N):
    dpL = []
    L = a[:i]
    if len(L)>=1:
        dpL.append(L[0])
        for j,left in enumerate(L):
            dpL.append(fractions.gcd(dpL[j],left))
#    print(dpL)
    
    dpR = []
    R = a[i+1:]
    if len(R)>=1:
        dpR.append(R[0])
        for j,right in enumerate(R):
            dpR.append(fractions.gcd(dpR[j],right))
   # print(dpR)
   
    if dpL == []:
        ans.append(min(dpR))
    elif dpR == []:
        ans.append(min(dpL))
    else:
        ans.append(fractions.gcd(dpL[len(dpL)-1],dpR[len(dpR)-1]))

print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter
from functools import reduce
import fractions as f
import sys
input = sys.stdin.readline

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def gcd(a, b):
    if (b == 0):
        return a
    return gcd(b, a % b)


n = int(input())
a = list(map(int, input().split()))
g = [1] * n

ans = 1
for i in range(n):
    if i == 0:
        g[0] = a[1]
    else:
        g[0] = a[0]
    for j in range(1, n):
        if i == j:
            g[j] = g[j - 1]
            continue
        g[j] = gcd(g[j - 1], a[j])
    ans = max(ans, g[n - 1])

print(ans)

Submission status: Time Limit Exceeded

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

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

from functools import reduce
def multigcd(item):
    return reduce(gcd, item)

for n in range(N):
    L=LA[:n]+LA[n+1:]
    ans.append(multigcd(L))

print(max(ans))

Submission status: Time Limit Exceeded

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

def resolve():
    N = int(input())
    As = list(map(int, input().split(" ")))
    if N == 2:
        return max(As)

    gcdmax = 0
    for i in range(N):
        if i == N-1:
            g = gcds(*As[:i])
        else:
            g = gcds(*(As[:i]+As[i+1:]))
        gcdmax = max(gcdmax, g)

    return gcdmax

if '__main__' == __name__:
    print(resolve())

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nums = [int(i) for i in input().split()]
from functools import reduce
def gcd(a,b):
  while b!=0:
    a, b = b, a%b
  return a
def compute_gcd(numbers):
    return reduce(gcd, numbers)
from copy import copy
gcds = []
for i in range(len(nums)):
    n = copy(nums)
    n.pop(i)
    gcds.append(compute_gcd(n))
print(max(gcds))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nums = [int(i) for i in input().split()]
from fractions import gcd
from functools import reduce
def compute_gcd(numbers):
    return reduce(gcd, numbers)
from copy import copy
gcds = []
for i in range(len(nums)):
    n = copy(nums)
    n.pop(i)
    gcds.append(compute_gcd(n))
print(max(gcds))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nums = [int(i) for i in input().split()]
from fractions import gcd
from functools import reduce
def compute_gcd(numbers):
    return reduce(gcd, numbers)
from copy import copy
gcds = []
for i in range(len(nums)):
    n = copy(nums)
    n.pop(i)
    gcds.append(compute_gcd(n))
gcds = list(set(gcds))
print(gcds[-1])

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
A = list(map(int, input().split()))
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a %  b != 0:
        a, b = b, a % b
    return b


ans = A[0]
ansmax = 0
for skip in range(N):
    if skip == 0:
        start = 2
        ans = A[1]
    else:
        start = 1
        ans = A[0]
    for i in range(start, N):
        if skip == i:
            continue
        ans = gcd(ans, A[i])
    if ansmax < ans:
        ansmax = ans
print(ansmax)

Submission status: Time Limit Exceeded

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

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

GCDs = []

for n in range(N):
    B = A + []
    trash = B.pop(n)
    GCD = B[0]
    for b in B:
        GCD = gcd(GCD, b)
    GCDs.append(GCD)

print(max(GCDs))

Submission status: Time Limit Exceeded

Solution code:
import sys

def gcd(x, y, *val):
    val = [x, y] + list(val)
    count = len(val)

    if count == 2:
        mod = val[0] % val[1]
        if mod == 0:
            return val[1]
        elif mod == 1:
            return 1
        else:
            return gcd(val[1], mod)
    else:
        if count % 2 == 1:
            val.append(val[-1])

        return gcd(*[gcd(val[i], val[i + 1]) for i in range(0, count, 2)])
        

def main():
    sinputl = sys.stdin.readline

    num = int(sinputl().strip())
    input = [int(x) for x in sinputl().split()]

    gcd_max = 1
    input_mem = []

    if num == 2:
        print(max(input))
        return

    for i in range(num):
        mem = input.pop(num - 1 - i)
        gcd_max = max(gcd_max, gcd(*(input + input_mem)))
        input_mem.append(mem)

    print(gcd_max)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def gcd(x, y, *val):
    val = [x, y] + list(val)
    val.sort(reverse=True)
    count = len(val)

    if count == 2:
        mod = val[0] % val[1]
        if mod == 0:
            return val[1]
        elif mod == 1:
            return 1
        else:
            return gcd(val[1], mod)
    else:
        if count % 2 == 1:
            val.append(val[-1])

        return gcd(*[gcd(val[i], val[i + 1]) for i in range(0, count, 2)])
        

def main():
    sinputl = sys.stdin.readline

    num = int(sinputl().strip())
    input = [int(x) for x in sinputl().split()]

    gcd_max = 1
    input_mem = []

    if num == 2:
        print(max(input))
        return

    for i in range(num):
        mem = input.pop(num - 1 - i)
        gcd_max = max(gcd_max, gcd(*(input + input_mem)))
        input_mem.append(mem)

    print(gcd_max)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy
from functools import reduce

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

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

max_num = 0
#最大値はいらない
for i in range(N):
    B = copy.deepcopy(A)
    B.remove(B[i])
    max_num = max(max_num, reduce(gcd, B))

print(max_num)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
gcds = 0
for N in range(n):
    gcds = max(gcds,reduce(fractions.gcd, a[:N] + a[N+1:]))
print(gcds)

Submission status: Time Limit Exceeded

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

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()))
L = [0]
R = [0]
ans = 0
for i in range(N):
	L.append(gcd(L[i],A[i]))
	R.insert(0,gcd(R[0],A[N-1-i]))
L.append(0)
R.insert(0,0)
for i in range(N):
	ans = max(ans,(gcd(L[i], R[i+2])))
print(ans)

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()))
L = [0]
R = [0]
M = [0]
for i in range(N):
	L.append(gcd(L[i],A[i]))
	R.insert(0,gcd(R[0],A[N-1-i]))
L.append(0)
R.insert(0,0)
for i in range(N):
	M.append(gcd(L[i], R[i+2]))
print(max(M))

Submission status: Time Limit Exceeded

Solution code:
import fractions

N = int(input())

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

for j in range(N):

    A_co = A.copy()
    del A_co[j]

    now_gcd = A_co[0]
    
    for i in range(N-2):

        now_gcd = fractions.gcd(now_gcd , A_co[i+1])

    if ans <= now_gcd:
        ans = now_gcd

print (ans)

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

res = 0
for i in range(N):
    tmp = gcd_list(A[:i] + A[i+1:])
    res = max(res,tmp)

print(res)