Problem:


Score : 300 points

Problem Statement

There are N integers, A_1, A_2, ..., A_N, written on the blackboard.

You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.

Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Output

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Sample Input 1

3
7 6 8

Sample Output 1

2

If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.

Sample Input 2

3
12 15 18

Sample Output 2

6

Sample Input 3

2
1000000000 1000000000

Sample Output 3

1000000000

We can replace an integer with itself.



Sample input:
3
7 6 8


Sample output:
2

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = []
        for i in range(2, int(math.sqrt(m)) + 1):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False

    def is_prime(self, n):
        return self.A[n]

    def division(self, n):
        d = collections.defaultdict(int)
        for c in self.T:
            while n % c == 0:
                d[c] += 1
                n //= c
            if n < 2:
                break
        if n > 1:
            d[n] += 1
        return d.items()

    def sowa(self, n):
        r = 1
        for k,v in self.division(n):
            t = 1
            for i in range(1,v+1):
                t += math.pow(k, i)
            r *= t
        return r


def main():
    n = I()
    a = sorted(LI())
    pr = Prime(10**9)
    p = collections.defaultdict(int)

    for b in a:
        r = [1]
        for k, v in pr.division(b):
            for c in r[:]:
                for i in range(1,v+1):
                    r.append(c*(k**i))
        for k in r:
            p[k] += 1
    r = 1
    for k,v in p.items():
        if v >= n-1 and r < k:
            r = k

    return r


print(main())

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce


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

ans = []
for i in range(N):
    if i != N:
        a = A[:i] + A[i+1:]
    else:
        a = A[:i]
    ans.append(reduce(fractions.gcd, a))
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions
from functools import reduce
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
n = ni()
a = nl()
maxx = gcd_list(a)
for i in range(n):
    maxx = max(maxx, gcd_list(a[:i] + a[i + 1:]))
print(maxx)

Submission status: Time Limit Exceeded

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

import fractions
from functools import reduce

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

f1 = gcd_list(a)
b = [int(_a / f1) for _a in a]

f2_list = []
for i in range(len(b)):
    tmp = b[i]
    b.pop(i)
    f2_list.append(gcd_list(b))
    b.insert(i, tmp)

print(f1 * max(f2_list))

Submission status: Time Limit Exceeded

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

l = []
for i in range(N):
    A = AA.copy()
    A.pop(i)
    minA = min(A)
    while len(A) > 1:
        minA = min(A)
        tempA = []
        tempA.append(minA)
        for a in A:
            mod = a % minA
            if mod > 0:
                tempA.append(mod)
        A = tempA
    l.append(A[0])
print(max(l))

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import fractions
n=int(input())
a=list(map(int,input().split()))
c=a[1:]
gcdc=reduce(fractions.gcd,c)
d=[gcdc]
for i in range(1,n):
    b=a[:i]+a[i+1:]
    gcd=reduce(fractions.gcd, b)
    d.append(gcd)
print(max(d))

Submission status: Time Limit Exceeded

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

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

ans = 1

for i in range(n):
	aa = a.copy()
	aa.pop(i)
	temp = gcd_list(aa)
	if(temp > ans):
		ans = temp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

def main():
	N = int(input())
	A = input().split()
	A = [int(s) for s in A]

	ans = -1
	Lis = [[-1 for _ in range(N)] for _ in range(N)]

	for i, val in enumerate(A):
		tmp = -1
		for j, vol in enumerate(A):
			if i == j:
				continue

			if tmp == -1:
				tmp = vol
				continue

			if Lis[i][j] != -1:
				tmp = Lis[i][j]
			else:
				tmp = gcd(vol, tmp)
				Lis[i][j] = tmp

		if ans == -1 or tmp > ans:
			ans = tmp

	print(ans)



def gcd(a, b):
	if a > b:
		a, b = b, a
		
	while a > 0:
		a, b = b % a, a
	return b
	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

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

n = int(stdin.readline().rstrip())
an = list(map(int, input().split()))


max = 0
for i in range(n):
  before = -1
  for j in range(n):
    if( j==i ):
      continue
    if( before == -1 ):
      before = an[j]
    else:
      before = gcd(before, an[j])
  if(max < before ):
    max = before
print(max)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import fractions


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


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

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
input = sys.stdin.readline
n = int(input())
a = input().split()
for i in range(n):
    a[i] = int(a[i])
max = 0
for i in range(n):
    temp = a[:i] + a[i+1:]
    k = gcd_list(temp)
    if k > max:
        max = k
print(max)

Submission status: Time Limit Exceeded

Solution code:
from  collections  import Counter
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())
As = [int(i) for i in input().split()]
divs = [div for a in As for div in make_divisors(a)]
# print(divs)
count = Counter(divs)
# print(count)
# print(count.most_common())
maxnum = 0
for val, num in count.most_common():
    if num in (n, n-1):
        maxnum = max(maxnum, val)
print(maxnum)

Submission status: Time Limit Exceeded

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


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

Submission status: Time Limit Exceeded

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

def gcd_l(A):
    if len(A) == 1:
        return A[0]
    x = gcd(A[0], A[1])
    if len(A) == 2:
        return x
    for i in range(2, len(A)):
        x = gcd(x, A[i])
    return x

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

ans = 1
for i in range(N):
    B = A[:i] + A[i+1:]
    ans = max(ans, gcd_l(B))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce

n = int(input())
A = [int(a) for a in input().split()]
ans = 1
for i in range(len(A)):
    B = A.copy()
    B.pop(i)
    _ = reduce(gcd, B)
    if _ > ans:
        ans = _
        
print(ans)

Submission status: Time Limit Exceeded

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


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

dic = {}
for a in A:
    divs = make_divisors(a)
    for i in divs:
        if dic.get(i) is None:
            dic[i] = 1
        else:
            dic[i] += 1

ans = 0
for k in dic:
    if dic[k] >= N - 1:
        ans = max(ans, k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import fractions
from functools import reduce


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


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


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

if n == 2:
    print max(a[0], a[1])
    exit()

M = 0
max_idx = 0
for i in range(n):
    tmp_arr = a[:i] + a[i+1:]
    M = max(gcd_list(tmp_arr), M)
print M

Submission status: Time Limit Exceeded

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

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

if N == 2:
    print(max(l))
    exit()

p = l.pop(0)
ans = []
for j in range(1,N+1):
    element = gcd(l[0], l[1])
    for i in range(2,N-1):
        element = gcd(element,l[i])
    ans.append(element)
    l.append(p)
    p = l.pop(0)
print(max(ans))

Submission status: Time Limit Exceeded

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

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)

m = 0
for i in range(N):
  if i == 0:
    tmp = A[1:]
  elif i == N-1:
    tmp = A[:N-1]
  else:
    tmp = A[:i] + A[i+1:]
  #print(tmp)
  a = gcd_list(tmp)
  if a > m:
    m = a

print(m)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
A = np.array([int(x) for x in input().split(' ')])

m = sorted(A)[1]

while True:
    if sum(A % m != 0) < 2:
        break
    m -= 1

print(m)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy
from functools import reduce

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

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

ans = 1
for i in range(n):
    tmp_list = copy.copy(a)
    tmp_list.pop(i)
    tmp = gcd_list(tmp_list)
    if ans < tmp:
        ans = tmp
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#C
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())
A = [int(j) for j in input().split()]
ans=0
for i in range(N):
    tmp=A.copy()
    tmp.pop(i)
    ans=max(ans,gcd(*tmp))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)

from functools import reduce
def gcd_list(n):
    return reduce(gcd, n)

from functools import lru_cache

@lru_cache(maxsize=10000)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

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

Submission status: Time Limit Exceeded

Solution code:
import fractions
import functools
def gcd_list(numbers):
    return functools.reduce(fractions.gcd, numbers)
n = int(input())
a = list(map(int,input().split()))
m = 1
for i in range(n):
    b = a[:i] + a[i+1:]
    x = gcd_list(b)
    if x > m:
        m = x
print(m)

Submission status: Time Limit Exceeded

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

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

ans = 0

for i in range(n):
    tmp = copy.deepcopy(a)
    del tmp[i]
    ans = max(gcd_list(tmp),ans)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import fractions
from functools import reduce

ans = 0
for i in range(n):
  x = a[:i] + a[i+1:]
  ans = max(ans, reduce(fractions.gcd, x))
  
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())
a=[int(x) for x in input().split()]

tmp=0
for i in range(n):
    l=copy.copy(a)
    _=l.pop(i)
    gcd=gcd_list(l)
    if gcd>tmp:
        tmp=gcd
print(tmp)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

ans = []
def find_gcd(x, y): 
      
    while(y): 
        x, y = y, x % y 
      
    return x 
    
for i in range(n):
    B = A[:i] + A[i+1:]
    num1 = B[0] 
    if(len(B) == 1):
        ans.append(B[0])
        break
    else:
        num2 = B[1]
    gcd = find_gcd(num1, num2) 
    for i in range(2, len(B)): 
        gcd = find_gcd(gcd, B[i])
    ans.append(gcd)
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

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

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

ans = 0
for i in range(n):
    a_reduce = a.copy()
    del(a_reduce[i])
    ans = max(ans, gcd_reduce(*a_reduce))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
n = int(input())
A = list(map(int,input().split()))
res = 0
for i in range(n):
    B = A[:i]+A[i+1:]
    GCD = B[0]
    for b in B:
        GCD = gcd(GCD,b)
    if res < GCD:
        res = GCD
print(res)

Submission status: Time Limit Exceeded

Solution code:
import fractions

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

def gcd(l):
    ans = l[0]
    for i in range(1, N-1):
        ans = fractions.gcd(ans, l[i])
    return ans

max_res = -1
for i in range(N):
    A_removed = A[0:i] + A[i+1:N]
    res = gcd(A_removed)
    if (res>max_res):
        max_res = res

print(max_res)

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:
            pass
        else:
            x = fractions.gcd(x, a[j])
    t.append(x)

print(max(t))

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc125/tasks/abc125_c

import itertools
from collections import Counter
from collections import defaultdict
import bisect

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

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

    answers = []
    for i in range(N):
        ans = 0
        for j in range(len(A)):
            if i == j:
                continue
            ans = gcd(A[j], ans)
        answers.append(ans)

    print(max(answers))


if __name__ == '__main__':
    main()

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 gcda(a):
    ret = a[0]
    for i in range(1, len(a)):
        ret = gcd(ret, a[i])
    return ret


ans = 1
for i in range(N):
    a = A[:i] + A[i+1:]
    ans = max(ans, gcda(a))

print(ans)

Submission status: Time Limit Exceeded

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

max_gcd = 0
for i in range(len(A)):
    B = A[:]
    del B[i]
    gcd = functools.reduce(fractions.gcd, B)
    if max_gcd < gcd:
        max_gcd = gcd

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

ans = 0
for i in range(N):
	temp = ls[:]
	temp.pop(i)
	a = gcd_list(temp)
	if a > ans:
		ans = a
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 = list(map(int, input().split()))

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

def main():
	N = int(input())
	A = input().split()
	A = [int(s) for s in A]

	ans = -1
	for i, val in enumerate(A):
		tmp = -1
		for j, vol in enumerate(A):
			if i == j:
				continue

			if tmp == -1:
				tmp = vol
				continue

			tmp = gcd(vol, tmp)

		if ans == -1 or tmp > ans:
			ans = tmp

	print(ans)



def gcd(a, b):
	if a > b:
		a, b = b, a
		
	while a > 0:
		a, b = b % a, a
	return b
	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce


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


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

Submission status: Time Limit Exceeded

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


def lcm(a, b):
    return a * b // gcd(a, b)


def list_lcm(number_list):
    lcm_number = 1
    for j in number_list:
        lcm_number = lcm(lcm_number, j)

    return lcm_number


def list_gcd(number_list):
    gcd_number = number_list[0]
    for i in number_list:
        gcd_number = gcd(gcd_number, i)

    return gcd_number


def ignore_list_gcd(number_list, ignore_index):
    _list = []
    for i in range(len(number_list)):
        if i != ignore_index:
            _list.append(number_list[i])

    return list_gcd(_list)


if __name__ == '__main__':
    n = int(input())
    numbers = list(map(int, input().split()))
    ans = 0
    for i in range(len(numbers)):
        ignore_gcd = ignore_list_gcd(numbers, i)
        if ans < ignore_gcd:
            ans = ignore_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())
listA=list(map(int, input().split()))

index=0
max=0
while index < len(listA):
    if index == 0:
        gc = gcd_list(listA[1:])
    elif index == len(listA)-1:
        gc = gcd_list(listA[:len(listA)-1])
    else:
        listB = listA[:index]
        listB.extend(listA[index+1:len(listA)])
        gc = gcd_list(listB)
    if gc > max:
        max = gc
    index+=1
print(max)

Submission status: Time Limit Exceeded

Solution code:
#C問題
N=int(input())
A=list(map(int,input().split()))
def gcd(GCD1,GCD2):
    x = min(GCD1,GCD2)
    y = max(GCD1,GCD2)
    if y%x == 0:
        return x
    else:
        return gcd(x,y%x)
def gcdlist(xlist):
    xlen=len(xlist)
    GCD=0
    for i in range(xlen-1):
        GCD=gcd(xlist[i],xlist[i+1])
        xlist[i+1]=GCD
    return GCD
MAX=0
kari=0
for i in range(N):
    B=A[::]
    del B[i]
    kari=gcdlist(B)
    MAX=max(MAX,kari)
if N == 2:
    MA=max(A)
    g=gcd(A[0],A[1])
    MAX=max(MA,g)
print(MAX)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

import fractions
import copy
from functools import reduce

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

max_gcd = 0
for idx in range(N):
    cleaned = copy.copy(A_list)
    del cleaned[idx]
    gcd_value = gcd(tuple(cleaned))
    if max_gcd < gcd_value:
        max_gcd = gcd_value
print(max_gcd)

Submission status: Time Limit Exceeded

Solution code:
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())
A = [int(x) for x in input().split()]
mgcd = 0
for ind,i in enumerate(A):
    mgcd = max(mgcd,gcd_list(A[:ind]+A[ind+1:]))
print(mgcd)

Submission status: Time Limit Exceeded

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

new_ans = 0

for i in range(n):
    ans = a[0]
    if i == 0:
        ans = a[1]
        
    for j in range(n):
        if j == i:
            continue
        else:
            ans = fractions.gcd(ans,a[j])
            if new_ans > ans:
                break
    else:
        new_ans = ans
print(new_ans)

Submission status: Time Limit Exceeded

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

max=0
for i in range(N):
    if A[i] > max:
        max=A[i]

a = max
for i in range(max):
    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:
import sys,collections as cl
import fractions
from functools import reduce
import copy
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


n = int(input())


a = l()
su = 0

aa = copy.copy(a)
for i in range(n):
	aa.pop(i)
	s = gcd_list(aa)
	su = max(su,s)
	aa = copy.copy(a)
print(su)

Submission status: Time Limit Exceeded

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import fractions
from functools import reduce

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

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

ans = 1
for i in range(N):
    a = copy.deepcopy(A)
    a.remove(A[i])
    ans = max(ans,gcd(a))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	ans = 0
	for i in range(N):
		this_gcd = A[i-1] if i > 0 else A[i+1]
		for j in range(N):
			if i == j:
				continue
			this_gcd = gcd(this_gcd, A[j])
		ans = max(ans, this_gcd)
	print(ans)


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

if __name__ == '__main__':
    main()

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
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


if n == 2:
    print(max(a))
else:
    cand = []
    for j in range(n):
        if j == 0:
            temp = a[1]
            for i in range(2,len(a)):
                temp = gcd(temp, a[i])
        else:
            temp = a[0]
            for i in range(1,len(a)):
                if i != j:
                    temp = gcd(temp, a[i])
        cand.append(temp)
    print(max(cand))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys,collections as cl
import fractions
from functools import reduce
import copy
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


n = int(input())


a = l()
su = 0

aa = copy.deepcopy(a)
for i in range(n):
	aa.pop(i)
	s = gcd_list(aa)
	su = max(su,s)
	aa = copy.deepcopy(a)
print(su)

Submission status: Time Limit Exceeded

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

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

ans = 0

for i in range(n):
    tmp = a[:i]
    tmp2 = a[i+1:]
    tmp.extend(tmp2)
    ans = max(gcd_list(tmp),ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd_(a,b):
    if a<b:    a,b=b,a
    if b==0:    return a
    return gcd_(b,a%b)
  
def gcd(l):
    ans=l[0]
    for i in l:
        ans=gcd_(ans,i)
    return ans
  
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 bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    n = get_int()
    a = get_li()
    ans = 1
    for i in range(len(a)):
        ans = max(ans, reduce(gcd, a[:i] + a[i+1:]))
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy
from fractions import gcd
from functools import reduce
N = int(input())
A = [int(i) for i in input().split()]

def gcd_(*numbers):
    return reduce(gcd, numbers)
    
ans = []
for i in range(N):
    B = deepcopy(A)
    B.pop(i)
    ans.append(gcd_(*B))
print(max(ans))