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:
n = int(input())
lis = list(map(int,input().split()))

import fractions
from functools import reduce

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

nm = 0

for i in range(n):
  t = gcds(lis[:i]+lis[i+1:])
  if nm < t:
    nm = t
print(nm)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
    g=1
    while b!=0:
        g=a%b
        a=b
        b=g
    return a
    
def gcd_list(numbers):
    # print(numbers)
    g=numbers[0]
    for i in range(n-1):
        g=gcd(g,numbers[i])
    return g

n=int(input())
a=list(map(int,input().split()))
gcd_without_i=[gcd_list(a[:i]+a[i+1:]) for i in range(n)]
# print(gcd_without_i)
print(max(gcd_without_i))

Submission status: Time Limit Exceeded

Solution code:
import functools
import fractions


N = int(input())
A = list(map(int, input().split()))
gcd_ans = []
for i in range(N):
    A_sub = (A[0:i]+A[i+1:N]).copy()
    gcd = functools.reduce(fractions.gcd, A_sub)
    gcd_ans.append(gcd)
print(max(gcd_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())
a =  list(map(int, input().split()))

a.sort()
tmp_a = copy.deepcopy(a)
tmp_a.pop(0)
result = gcd_list(tmp_a)

for i in range(1, n):
    tmp_a = copy.deepcopy(a)
    tmp_a.pop(i)
    tmp = gcd_list(tmp_a)
    if(result < tmp):
        result = tmp

print(result)

Submission status: Time Limit Exceeded

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

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

resmax = 0
for j in range(n):
	if j == 0:
		res = ai[1]
		for i in range(2,n):
			res = gcd(ai[i],res)
	else:
		res = ai[0]
		for i in range(1,n):
			if i == j:
				continue
			else:
				res = gcd(ai[i],res)
	if res > resmax:
		resmax = res

#print(resi)
print(resmax)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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

Atmp = copy.deepcopy(A)

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

Submission status: 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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    all_divisors = []

    for a in A:
        all_divisors.extend(make_divisors(a))
    
    all_divisors.sort(reverse=True)

    for d in all_divisors:
        if all_divisors.count(d) >= N - 1:
            print(d)
            return

    print(1)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

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

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

print(max_gcd)

Submission status: Time Limit Exceeded

Solution code:
import copy
import math
from functools import reduce

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

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

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

for i in range(n):
    tmp = copy.copy(a)
    del tmp[i]
    tmp_rtn = gcd_list(tmp)
    if tmp_rtn > rtn:
        rtn = tmp_rtn

print(rtn)

Submission status: Time Limit Exceeded

Solution code:
import functools
import fractions

N = int(input())
A = [int(x) for x in input().split()]
print(max(functools.reduce(fractions.gcd, [A[j] for j in range(N) if j != i]) for i in range(0, N)))

Submission status: Time Limit Exceeded

Solution code:
import fractions as f
N = int(input())
As = list(map(int, input().split()))
ans = 0

for i in range(N):
    new_As = As.copy()
    new_As.pop(i)
    a = new_As[0]
    for j in range(1, N-1):
        b = new_As[j]
        a = f.gcd(a, b)
    ans = max(ans, a)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)
import copy
n = int(input())
max_ = 0
lists = list(map(int,input().split()))

for i in range(len(lists)):
    cp = copy.copy(lists)
    cp.pop(i)
    n = len(cp)
    if n==1:
        element = cp[0]
    else:
        element = gcd(cp[0], cp[1])
        for i in range(2,n):
            element=gcd(element,cp[i])
    k = element
    if k>= max_:
        max_ = k
print(max_)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

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

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

for i in range(n):
  g = gcd_list(li[:i] + li[i+1:])
  if max < g:
    max = g

print(max)

Submission status: Time Limit Exceeded

Solution code:
import math

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

M = max(A)
ans = 1

for i in reversed(range(2, M+1)):
  l = 0
  for j in range(N):
    if A[j] % i > 0:
      l += 1
  
  if l <= 1:
    ans = i
    break

print(ans)

Submission status: Time Limit Exceeded

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

import fractions
from functools import reduce

for i in range(sorted(a)[1]+1, 0, -1):
  x = 0
  for j in a:
    if j % i != 0:
      x += 1
  if x <= 1:
    print(i)
    break

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


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


def main():
    n = II()
    A = LI()
    A.sort()
    A.reverse()

    t = A[0]
    pre = [0] * n
    pre[0] = A[0]
    for i in range(1, n):
        pre[i] = gcd(pre[i - 1], A[i])
    res = pre[-1]
    for i in range(n):
        t = pre[i]
        for j in range(i + 2, n):
            t = gcd(t, A[j])
        res = max(res, t)

    return res


print(main())

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())
v = 1
a = list(map(int, input().split()))

for i in range(n):
  tmpl = a[:]
  del tmpl[i]
  tmp = gcd_list(tmpl)
  if tmp > v:
    v = tmp
print(v)

Submission status: Time Limit Exceeded

Solution code:
"""
問題文

N個の整数 A1,A2,...,ANが黒板に書かれています。
あなたはこの中から整数を 1つ選んで、1 以上 109以下の好きな整数に書き換えます。
元の整数と同じ整数に書き換えても構いません。書き換えた後のN個の整数の最大公約数の最大値を求めてください。

制約
入力は全て整数である。
2≤N≤105
1≤Ai≤109
"""

"""
3 5 7
最大公約数: 1
最大の最大公約数: 1

8 4 6
最大公約数: 2
最大の最大公約数: 4
『aとbとcの最大公約数』　＝　『aとbの最大公約数』と『c』　の最大公約数
"""
import math
from fractions import gcd  # for Ver.3.4 or lower.
from functools import reduce
def GCD(*numbers):
    return reduce(gcd, numbers)
    #return reduce(math.gcd, numbers)

def main() : 
    N = int(input())
    a_list = input().split(" ")
    a_list = [int(i) for i in a_list]
    maxValue = 0
    for i in range(N) : 
        if i == 0 : sub_a_list = a_list[1:]
        elif i == N - 1 : sub_a_list = a_list[:N-1]
        else : sub_a_list = a_list[0 : i ] + a_list[i + 1 :] 
        rst = GCD(*sub_a_list)
        if maxValue < rst : maxValue = rst
    print(maxValue)
main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import fractions


N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

res = []


for i in range(N):
    B = A[:]
    del B[i]
    gcd_num = B[0]
    for j in range(1, N-1):
        gcd_num = fractions.gcd(gcd_num, B[j])
    res.append(gcd_num)
        


print(max(res))

Submission status: Time Limit Exceeded

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

for i in range(max(A)):

    count = 0

    for j in range(N):
        if A[j] % (i+1) !=0:
            count += 1
        
    if count == 1:
        B.append(i+1)
    else:
        continue


B.sort()

if len(B) > 0:
    print(B[-1])
else :
    print(A[0])

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce
from copy import copy
def gcd_list(numbers):
    return reduce(gcd, numbers)
ans = 0
N = int(input())
A = [int(n) for n in input().split()]

for i in range(N):
    B = copy(A)
    B.pop(i)
    tmp = gcd_list(B)
    if ans < tmp:
        ans = tmp
print(ans)

Submission status: Time Limit Exceeded

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

wari_num = []
for i in range(1, max(a)+1):
    if max(a) % i == 0:
        wari_num.append(i)

one = 0
for i in wari_num[::-1]:
    for j in a:
        if j % i != 0:
            one += 1

    if one == 1:
        print(i)
        exit()
    else:
        one = 0

print(a[0])

Submission status: Time Limit Exceeded

Solution code:
import itertools
import fractions
from functools import reduce

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

N = int(input())
A = [int(i) for i in input().split()]
rt = 1
for ele in itertools.combinations(A, N-1):
    f = gcd(ele)
    if rt < f:
        rt = f
print(rt)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

max_gcd = 0
max_gcd_index = -1
for i in range(len(li)):
    tmp = li[:]
    del tmp[i]
    if max_gcd < gcd(*tmp):
        max_gcd = gcd(*tmp)
        max_gcd_index = i

print(max_gcd)

Submission status: Time Limit Exceeded

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

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

resi = []
for j in range(n):
	if j == 0:
		res = ai[1]
		for i in range(2,n):
			res = gcd(ai[i],res)
	else:
		res = ai[0]
		for i in range(1,n):
			if i == j:
				continue
			else:
				res = gcd(ai[i],res)
	resi.append(res)

#print(resi)
print(max(resi))

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

n = int(input())

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


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


gcd_l = [0]
gcd_r = []
for i in range(1,n+1):
    a_l = a[:i-1]
    a_r = a[i:]
    if a_l:
        gcd_l.append(gcd_list(a_l))
    if a_r:
        gcd_r.append(gcd_list(a_r))
gcd_r = gcd_r + [0]

ans = 0
for i in range(n):
    if gcd_l[i] == 0:
        gcd = gcd_r[i]
    if gcd_r[i] == 0:
        gcd = gcd_l[i]
    else:
        gcd = fractions.gcd(gcd_l[i],gcd_r[i])
    ans = max(gcd,ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush,heappop
import queue
import re
import math
import functools

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in range(n)]

def make2d_arr(h,w,val =INF):
    return [[val for i in range(w)]for i in range(h)]

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


N = int_raw()
As = ints_raw()


def main():
    ans = 0
    for i in range(N):
        ans = max(ans,functools.reduce(gcd, As[:i]+As[i+1:]) )
    return ans
print(main())

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

gcds = []

for i in range(n):
    as2 = as_[:]
    del as2[i]
    gcds.append(reduce(fractions.gcd, as2))

print(max(gcds))

Submission status: Time Limit Exceeded

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

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

for i in range(len(l)):
    omitlist=[l[k] for k in range(len(l))]
    omitlist.pop(i)
    n=len(omitlist)

    if n==1:
        gcds.append(omitlist[0])
    else:
        element = gcd(omitlist[0], omitlist[1])
        if n==2:
            gcds.append(element)
        else:
            for i in range(2,n):
                element=gcd(element,omitlist[i])
            gcds.append(element)

print(max(gcds))

Submission status: Time Limit Exceeded

Solution code:
import fractions


def gcd(l, t):
    a = l.pop(0)
    for v in l:
        a = fractions.gcd(a, v)
        if a <= t:
            break
    return a


N = int(input())
*A, = map(int, input().split())
A.sort()
ans = 1
for i in range(N):
    b = A[:i]+A[i+1:]
    g = gcd(b, ans)
    if g > ans:
        ans = g
print(ans)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

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


n = int(input())


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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import math
import fractions

N=int(input())
LA=[int(x) for x in input().split()]

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


r=0
for i in range(len(LA)):
    r=max(r,gcd_list(LA[:i]+LA[i+1:]))
print(r)

Submission status: Time Limit Exceeded

Solution code:
import collections


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


N = int(input())
Ns = [int(i) for i in input().split()]
cs = []
for i in Ns:
    cs += make_divisors(i)
c = collections.Counter(cs)
max = 1
for i in c.items():
    if i[1] >= N - 1 and max < i[0]:
        max = i[0]

print(max)

Submission status: Time Limit Exceeded

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

n = input()
a_list = map(int, raw_input().split())
max_g = 0
for exclude in xrange(n):
    g = a_list[0] if exclude > 0 else a_list[1]
    for i in xrange(1, n):
        if i == exclude:
            continue
        g = gcd(g, a_list[i])
        if g <= max_g:
            break
    if g > max_g:
        max_g = g
print(max_g)

Submission status: Time Limit Exceeded

Solution code:
import copy
import fractions

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

for i in range(N):
    B = copy.deepcopy(A)
    del B[i]
    temp = B[0]
    for j in range(1, N - 1):
        temp = fractions.gcd(temp, B[j])
    C[i] = temp

print(max(C))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().rstrip().split(' ')))
    max_gcd = 0
    for i in range(n):
        prev = None
        for j in range(n):
            if i == j:
                continue
            if prev is None:
                prev = a[j]
            else:
                prev = gcd(prev, a[j])
        if max_gcd < prev:
            max_gcd = prev
    print(max_gcd)


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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

min=10000000000000000000
cnt=0
for i in range(N):
    if A[i] < min:
        cnt+=1
    if cnt == N-1:
        min=A[i]

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

Submission status: Time Limit Exceeded

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

def gcd_array(A):
    n = len(A)
    s = A[0]
    i = 1
    while(i < n):
        s = gcd(s,A[i])
        i += 1
    return s

if __name__ == "__main__":
    N = int(input())
    B = list(map(int,input().split()))
    max = 0
    i = 0
    while(i < N):
        A = [i for i in B]
        A.pop(i)
        d = gcd_array(A)
        if max <= d:
            max = d
        i += 1
    print(max)

Submission status: Time Limit Exceeded

Solution code:
import copy
import functools
import fractions

n=int(input())
lstA=list(map(int,input().split()))
maximum=max(lstA)
gcdlst=[]

for i in range(n):
    cplstA=copy.copy(lstA)
    del cplstA[i]
    gcdlst.append(functools.reduce(fractions.gcd, cplstA))

print(max(gcdlst))

Submission status: Time Limit Exceeded

Solution code:
import math

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

def gcd_list(arr):

    ans = arr[0]
    for c in arr[1::]:
        ans = gcd(ans , c)
    return ans

N = int(input())

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

g = gcd_list(A)

for i in range(N):
    tmp = A.pop(0)
    if g < gcd_list(A):
        g = gcd_list(A)
    A.append(tmp)

print(g)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce
import copy
N = int(input())
A=list(map(int,input().split()))
ans=[]
def gcd_list(numbers):
  return reduce(fractions.gcd, numbers)
for i in range(N):
  tmp=copy.copy(A)
  tmp.pop(i)
  ans.append(gcd_list(tmp))
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int,input().split()))
As.sort(reverse=True)
first_d = As[0]
for d in range(first_d):
    cnt = 0
    for i in range(N):
        if As[i] % (first_d-d) == 0:
            cnt += 1
    if cnt >= N-1:
        ans = first_d-d
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# vim: set fileencoding=utf-8:
import fractions
from functools import reduce


def main():
    N = int(input())
    A = [int(ele) for ele in input().split()]
    gcds = [-1] * N

    for idx in range(N):
        tmp = A[:idx] + A[idx+1:]
        gcds[idx] = gcd(*tmp)

    print(max(gcds))


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


if __name__ == "__main__":
    main()

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)

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

temp=[]
ans=[]
for i in range(n):
    temp=a.copy()
    for j,v in enumerate(a):
        if i==j:
            temp.pop(j)
    ans.append(gcd_list(temp))

print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

A.sort(reverse=True)

#A[1] = A[0]

max_gcd = 1

for i in range(N):
    gcd_num = -1

    for j, a in enumerate(A):
        if i == j:
            continue

        if gcd_num == -1:
            gcd_num = a
            continue

        gcd_num = fractions.gcd(gcd_num, a)

    max_gcd = max(max_gcd, gcd_num)

print(max_gcd)

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 = list(map(int, input().split()))

A_list.sort()
ans = 0
for i in range(N):
  b = A_list.copy()
  b.pop(i)
  aa = gcd_list(b)
  if aa >= ans:
    ans = aa
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

if __name__ == '__main__':
  n = int(input())
  a_lst = [int(elem) for elem in input().split()]  
  res_lst = []
  for i, a in enumerate(a_lst):
    new_lst = list(a_lst)
    new_lst.pop(i)
    res = gcd_list(new_lst)
    res_lst.append(res)
  print(max(res_lst))

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd

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

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

ans = -1

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

g = gcd_list(A[:N-1])
if g > ans:
    ans = g

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import*
def dv(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 Counter(divisors)

n,*a=map(int,open(0).read().split())
ans=Counter()
for i in range(n):
    ans+=dv(a[i])
l=[]
for k,v in ans.items():
    if v==n-1 or v==n:
        l.append(k)
print(max(l))

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd

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

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

print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
import functools
import fractions
n = int(input())
values = list(map(int, input().split()))
m = 1

for i in range(n):
    a = values[:]
    a.pop(i)
    gcd = functools.reduce(fractions.gcd, a)
    if m < gcd:
        m = gcd


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
if len(A) == 1:
    ans = A[0]
elif len(A) == 2:
    ans = max(A)
else:
    for i in range(N):
        B = A[:i] + A[i+1:]
        ans = max(ans, gcd_list(B))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce


def gcdall(numlist):
    return reduce(gcd, numlist)


def main():
    _ = int(input())
    a = list(map(int, input().split()))
    if len(a) < 3:
        print(max(a))
        return

    gcds = []
    for i in range(len(a)):
        gcds.append(gcdall([a[j] for j in range(len(a)) if j != i]))
    print(max(gcds))


main()

Submission status: Time Limit Exceeded

Solution code:
import fractions
import functools

n = int(input())
a = list(map(int,input().split()))
m = 1
for i in range(n):
    ab = a[:i] + a[i+1:]
    gcd = functools.reduce(fractions.gcd, ab)
    if m<gcd:
        m = gcd
print(m)

Submission status: Time Limit Exceeded

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

import fractions
import copy
from functools import reduce

ans = 1

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

for i in range(N):
    A_sub = copy.deepcopy(A)
    del(A_sub[i])
    ans_sub = gcd_list(A_sub)
    if ans < ans_sub:
        ans = ans_sub

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())
gcdl = []
a = list(map(int, input().split()))

for i in range(n):
  tmpl = a[:]
  del tmpl[i]
  gcdl.append(gcd_list(tmpl))
print(max(gcdl))

Submission status: Time Limit Exceeded

Solution code:
import sys

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

if N == 2:
    print(max(A))
    sys.exit()

for i in range(N):
    L = A[:i]+A[i+1:]
    for j in range(N-2):
    # 割り算 余りを次の割る数に
    # A[i]がゼロになったら終了!
        while L[j]>0:
            tmp = L[j]
            L[j] = L[j+1] % L[j]
            L[j+1] = tmp
    ans = max(ans,L[N-2])

print(ans)

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):
	if i == N - 1:
		B = A[: N - 1]
	else:
		B = A[: i] + A[i + 1:]
	g = B[0]
	for j in range(1, N - 1):
		g = fractions.gcd(g, B[j])
	ans = max(ans, g)
print(ans)

Submission status: Time Limit Exceeded

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

def gcd_array(A):
    n = len(A)
    s = A[0]
    for i in range(1,n):
        s = gcd(s,A[i])
    return s

if __name__ == "__main__":
    N = int(input())
    B = list(map(int,input().split()))
    max = 0
    for i in range(N):
        A = [i for i in B]
        A.pop(i)
        d = gcd_array(A)
        if max <= d:
            max = d
    print(max)

Submission status: Time Limit Exceeded

Solution code:
import copy
import functools
import fractions

n=int(input())
lstA=list(map(int,input().split()))
maximum=max(lstA)
gcdlst=[]

for i in range(n):
    cplstA=copy.copy(lstA)
    del cplstA[i]
    gcdlst.append(functools.reduce(fractions.gcd, cplstA))

print(max(gcdlst))

Submission status: Time Limit Exceeded

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

n = input()
a_list = map(int, raw_input().split())
max_g = 0
for exclude in xrange(n + 1):
    g = a_list[0] if exclude > 0 else a_list[1]
    for i in xrange(1, n):
        if i == exclude:
            continue
        g = gcd(g, a_list[i])
    if g > max_g:
        max_g = g
print(max_g)

Submission status: Time Limit Exceeded

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

gcd_max = 1

if N == 2:
    print(max(A_array[0],A_array[1]))
    exit()
for i in range(N):
    gcd = 0
    for j, A in enumerate(A_array):
        if i == j:
            continue
        if gcd == 0:
            gcd = A
            continue
        # print(A,gcd)
        gcd = min(gcd, fractions.gcd(A, gcd))
    gcd_max = max(gcd_max, gcd)
print(gcd_max)

Submission status: Time Limit Exceeded

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))
t = []

for i in range(n):
    x = 0
    for j in range(n):
        if j != i:
            x = fractions.gcd(x, a[j])
    t.append(x)

print(max(t))

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce

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


def _gcd(*A):
    return reduce(gcd, A)


ans = 0
for i in range(N):
    B = A[:i] + A[i + 1:]
    x = _gcd(*B)
    ans = max(ans, x)
print(ans)

Submission status: Time Limit Exceeded

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

N = int(input())
A = list(map(int, input().split()))
ans = 1
for i in range(N):
    ans = max(ans, reduce(fractions.gcd, [A[j] for j in range(N) if i!=j]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import platform
ver = platform.python_version_tuple()
if int(ver[1]) < 5:
    from fractions import gcd
else:
    from math import gcd
from functools import reduce
from sys import stdin

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

    ans = 0
    for i in range(N):
        num = A[:i] + A[i+1:]
        ans = max(ans, reduce(gcd, num))
    print(ans)

input = lambda: stdin.readline()
main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
d = defaultdict(int)
for ai in a:
   for i in range(1,int(ai**0.5)+1):
    if ai%i==0:
        d[i] += 1
        if i!=ai//i:
            d[ai//i] += 1

sd=sorted(d.items(),key=lambda x:x[0],reverse=True)
for k,v in sd:
    if v==n or v==n-1:
        print(k)
        break

Submission status: Time Limit Exceeded

Solution code:
import functools
import fractions

N = int(input())
a = list(map(int,input().split()))
ans = 1
for i in range(N):
	a_new = a[0:i]+a[i+1:N]
	gcd = functools.reduce(fractions.gcd,a_new)
	ans = max(ans,gcd)

print(ans)