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())
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)
    return divisors

candidate1 = []
candidate = {}
for i in range(N):
    if i > 1:
        delete_key = []
        for c in candidate.keys():
            if A[i] % c == 0:
                candidate[c]['atari'] += 1
            else:
                candidate[c]['hazure'] += 1        
    elif i == 0:
        candidate1 = make_divisors(A[i])
    elif i == 1:
        candidate2 = make_divisors(A[i])
        prev = -1
        for c in sorted(candidate1 + candidate2):
            if c != prev and prev != -1 and candidate[prev]['atari'] < 2:
                candidate[prev]['hazure'] += 1
            if c not in candidate:
                candidate[c] = {
                    'atari': 1,
                    'hazure': 0
                }
            else:
                candidate[c]['atari'] += 1
            prev = c
        if candidate[prev]['atari'] < 2:
            candidate[prev]['hazure'] += 1            
max = 0
for c in candidate:
    if candidate[c]['hazure'] < 2 and max < c:
        max = c
print(max)

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]

	base = -1
	for i, val in enumerate(A):
		if i == 0:
			base == val
			continue
		base = gcd(val, base)

	ans = base
	for i, val in enumerate(A):
		tmp = -1
		if ans >= val:
			break
		for j, vol in enumerate(A):
			if i == j:
				continue
 
			if tmp == -1:
				tmp = vol
				continue
 
			tmp = gcd(vol, tmp)
			if tmp <= ans:
				break
 
		if 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 functools
import fractions
import copy
 
N = int(input())
A_list = list(map(int, input().split()))
values = []
values_list = []
 
for i in range(N):
    values = copy.copy(A_list)
    del values[i]
    gcd = functools.reduce(fractions.gcd, values)
    values_list.append(gcd)
 
print(max(values_list))

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
from functools import reduce
n=input()
n=int(n)
a=input().split()
a=[int(i) for i in a]
ncount=2
count=0
gll=list()
for i in range(n):
    s=a[i]
    del a[i]
    gc = reduce(gcd, a)
    gll.append(gc)
    a.insert(i,s)
print(max(gll))

Submission status: Time Limit Exceeded

Solution code:

#from fractions import gcd

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

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

def gcd_list(a):
    a2 = a[0]
    for i in range(1,len(a)):
        a2 = my_gcd(a2, a[i])
    return a2

ans = gcd_list(a)
a_stock = a.copy()
for i in range(n):
    a = a_stock.copy()
    a.pop(i)
    ans2 = gcd_list(a)
    if ans < ans2:
        ans = ans2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import functools
N=int(input())
A=[int(i) for i in input().split()] 
max_gcd=functools.reduce(fractions.gcd, A)
for i in range(N):
	tmp=A.copy()
	tmp.pop(i)
	gcd=functools.reduce(fractions.gcd, tmp)
	if max_gcd<gcd:
		max_gcd=gcd
print(max_gcd)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

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

def gcd(a, b):
    if a>b: a,b = b,a
    if (a,b) in gcd_memo.keys():
        return gcd_memo[(a,b)]
    while b:
        a, b = b, a % b
    gcd_memo[(a,b)] = 0
    return a

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

j=0
while j<len(a):
    erase_list = []
    r_len = len(a)
    for k in range(r_len):
        if k==j: continue
        if a[k] % a[j] == 0:
            erase_list.append(k)
    if len(erase_list) > 1:
        for k in erase_list[::-1]:
            del(a[k])
            a.append(a[j])
    j+=1

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

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

gcd_left = []
gcd_left.append(A[0])
gcd_right = []
gcd_right.append(A[N-1])
for i in range(N-1):
    gcd_left.append(fractions.gcd(gcd_left[i],A[i+1]))
    gcd_right.insert(0,fractions.gcd(gcd_right[0],A[N-2-i]))
min_left = min(gcd_left)
min_right = min(gcd_right) 

min_gcd = 1
tmp_left = 0
tmp_right = 0
if min_gcd < gcd_right[1]:
    min_gcd = gcd_right[1]
if min_gcd < gcd_left[N-2]:
    min_gcd = gcd_left[N-2]
for i in range(0,N-2):
    tmp_left = gcd_left[i]
    tmp_right = gcd_right[i+2]
    tmp = fractions.gcd(tmp_left,tmp_right)
    if tmp > min_gcd:
        min_gcd = tmp
        if tmp_left == min_left or tmp_right == min_right:
            break;
print(min_gcd)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from functools import reduce
#import math as m
import fractions as m
import numpy as np

# via [Pythonで最大公約数と最小公倍数を算出・取得 \| note\.nkmk\.me](https://note.nkmk.me/python-gcd-lcm/)
def gcd_list(numbers):
    return reduce(m.gcd, numbers)

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

#N = 3
#A = np.array([7,6,8])

# via [Numpy で特定のインデックス以外の要素を取り出す \- Qiita](https://qiita.com/shuhei_f/items/4ef8c728a52d0290ad71)
max_gcd =0
max_i = 0

for i in range(N):
    index = np.ones(N, dtype=bool)
    index[i] = False
    tmp_gcd = gcd_list(A[index]) 

    if tmp_gcd > max_gcd :
        max_gcd = tmp_gcd
        max_i = i

print(max_gcd)

Submission status: Time Limit Exceeded

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


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

A.sort()
ans = 1

for i in range(N):
    B = A[:]
    B.pop(i)
    tmp=B[0];
    for j in B:
        if(ans>j):
            break
        tmp=gcd(tmp,j)

    ans = max(ans, tmp)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import math
import fractions
input=[]
for i in range(2):
    input.append(stdin.readline().rstrip().split())

N=int(input[0][0])
A=[]
for i in input[1]:
    A.append(int(i))

#print(N,A)

"""
x=0
for i in range(N):
    if i <= 1:
        x=math.gcd(A[0],A[1])
    else:
        x=math.gcd(x,A[i])
print(x)
"""
x=0
output=0
for i in range(N):
    copy_A=A.copy()
    copy_A.pop(i)
    if N==2:
        if A[0]<A[1]:
            output=A[1]
        else:
            output=A[0]
        break

    else:
        for i in range(N-1):
            if i <= 1:
                x=fractions.gcd(copy_A[0],copy_A[1])
            else:
                x=fractions.gcd(x,copy_A[i])
                if (x==1) or (x<=output):
                    break

        if output<x:
            output=x

print(output)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int,input().split()))
gcd_list = []
min_element = min(A)
max_element = max(A)

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

for i in range(n):
    y = A[i]
    for j in range(min_element, max_element + 1):
        A[i] = j
        x = A[0]
        for k in range(1, n):
            x = gcd(x, A[k])
        gcd_list.append(x)
    A[i] = y
print(max(gcd_list))

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

n=int(input())
array = list(map(int, input().split())) 
# array=list(set(array))
array.sort(reverse=True)


max=-100

for i in range(n):
    if(max>array[i]):
        break
    pop=array.pop(i)
    tmp_gcd=gcd(*array)
    # print(copy_array)
    if(max<tmp_gcd):
        max=tmp_gcd
    array.insert(i,pop)
    
print(max)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(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)
    return divisors

candidate1 = []
candidate = {}
for i in range(N):
    if i > 1:
        delete_key = []
        for c in candidate.keys():
            if A[i] % c == 0:
                candidate[c]['atari'] += 1
            else:
                candidate[c]['hazure'] += 1        
    elif i == 0:
        candidate1 = make_divisors(A[i])
    elif i == 1:
        candidate2 = make_divisors(A[i])
        prev = -1
        for c in sorted(candidate1 + candidate2):
            if c != prev and prev != -1 and candidate[prev]['atari'] < 2:
                candidate[prev]['hazure'] += 1
            if c not in candidate:
                candidate[c] = {
                    'atari': 1,
                    'hazure': 0
                }
            else:
                candidate[c]['atari'] += 1
            prev = c
        if candidate[prev]['atari'] < 2:
            candidate[prev]['hazure'] += 1            
max = 0
for c in candidate:
    if candidate[c]['hazure'] < 2 and max < c:
        max = c
print(max)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
As = [int(i) for i in input().split()]
import functools
import fractions
ans = 0
for i in range(n):
    tmpa = As[:i] + As[i + 1:]
    gcd = functools.reduce(fractions.gcd, tmpa)
    # print(gcd)
    ans =max(ans, gcd)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import copy
from functools import reduce, lru_cache

@lru_cache(maxsize=100000)
def gcd(a, b):
    return reduce(fractions.gcd, [a, b])

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 = tmp_list[0]
    for i in range(len(tmp_list)):
        if tmp_list[i] < ans:
            break
    for i in range(len(tmp_list)):
        tmp = gcd(tmp, tmp_list[i])
        if tmp < ans:
            break
    if ans < tmp:
        ans = tmp
print(ans)

Submission status: Time Limit Exceeded

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



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

i=2
b=[1]#a=0
c=[1]
d=[]
while True:
    a = 0
    for j in range(N):
        if A[j] % i != 0:
            a += 1
        if a > 1:
            d.append(i) #black list
            break

    #print(i,A,a)

    if a == 0:
        b.append(i) #white list
        for j in range(len(A)):
            A[j] = int(A[j] / i)
        i = 2
    if a == 1:
        c.append(i) #gray list
    if a > 0:
        i += 1
    
    k=0
    while True:
        if k >= len(d):
            break
        if i % d[k] == 0:
            i += 1
            k = -1
        k += 1


    if i > min(A):
        break

bs = 1
for i in range(len(b)):
    bs *= b[i]
print(bs * max(c))

Submission status: Time Limit Exceeded

Solution code:
import sys
from functools import reduce
import sys
input = sys.stdin.readline
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(numbers):
    return reduce(gcd, numbers)

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

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

max_ans = 0
for i in range(len(A)):
    tmp = A[:i] + A[1+i:]
    ans = gcd_list(tmp)
    if max_ans < ans:
        max_ans = ans
print(max_ans)

Submission status: Time Limit Exceeded

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

mi_A=min(A)

count=0
bad=0
for j in range(N-1,-1,-1):
  if A[j]%mi_A==0:
    count=count+1
  elif bad==1:
    break
  else:
    bad=bad+1
if count>=N-1:
  ans=mi_A
  
else:
  for i in range(mi_A//2+1,0,-1):
    if mi_A%i==0:
      count=0
      bad=0
      for j in range(N-1,-1,-1):
        if A[j]%i==0:
          count=count+1
        elif bad==1:
          break
        else:
          bad=bad+1
      if count>=N-1:
        ans=i
        break


A.remove(min(A))
if len(A)==N-1:
  mi_A=min(A)
  count=0
  bad=0
  for j in range(0,N-1):
    if A[j]%mi_A==0:
      count=count+1
    else:
      break
  if count>=N-1:
    ans=mi_A
    
  else:
    for i in range(mi_A//2+1,0,-1):
      if mi_A%i==0:
   
        count=0
        bad=0
        for j in range(0,N-1):
        
          if A[j]%i==0:
            count=count+1
         
          else:
        
            break
        if (count>=N-1) and (i>ans):
          ans=i
          break
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
seki = 1

for x in range(2,int(1000000000**0.5)+1):
    count = 0

    for y in range(N):
        if A[y] % x != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = x

for i in range(N):
    count = 0
    if A[i] < 1000000000**0.5+1:
        break
    for j in range(N):
        if A[i] % A[j] != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = A[i]

print(seki)

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
from functools import reduce

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


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


c = itertools.combinations(A, N-1)

a_max = gcd(*A)
for i in c:
    a_max = max(a_max, gcd(*list(i)))

print(a_max)

Submission status: Time Limit Exceeded

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


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

A.sort()
ans = 1

for i in range(N):
    B = A[:]
    B.pop(i)
    tmp=B[0];
    for j in B:
        tmp=gcd(tmp,j)

    ans = max(ans, tmp)

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(max(A), 1, -1):
  cnt = [a % i == 0 for a in A].count(True)
  if cnt == N or cnt == N-1:
    print(i)
    sys.exit()
print(1)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import functools

N=int(input())
A=list(map(int,input().split()))
A=sorted(A,reverse=True)
gcdA=functools.reduce(fractions.gcd,A)
ans=gcdA
B=A
for i in range(N):
    num=B[i]
    del B[i]
    gcdB=functools.reduce(fractions.gcd,B) 
    gcd=max(gcdA,gcdB)
    if gcd>ans:
        ans=gcd
        B.insert(i,num)
    else:
        B.insert(i,num)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3

import numpy as np

N = int(input())
nums = np.array(list(map(int, input().split())))

sorted_num = np.sort((nums))

res = 1
for i in range(sorted_num[1], 0, -1):
    nums_div_i = np.remainder(nums, i)

    nums_div_i = nums_div_i > 0
    d = np.sum(np.ones(N) * nums_div_i)
    if d == 1 or d == 0:
        res = i
        break

print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int,input().split()))
gcd_list = []
max_element = max(A)

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

for i in range(n):
    y = A[i]
    for j in range(1, max_element + 1):
        A[i] = j
        x = A[0]
        for k in range(1, n):
            x = gcd(x, A[k])
        gcd_list.append(x)
    A[i] = y
print(max(gcd_list))

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8
from functools import reduce
import copy

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

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

n = int(input())
numlist = [ int(d) for d in input().split(" ")]
buflist = list()
maxdivlist = list()

maxdivlist.append(gcd_list(numlist))

for i in range(n):
	buflist = copy.copy(numlist)
	buflist.pop(i)
	maxdivlist.append(gcd_list(buflist))
print(max(maxdivlist))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
li=list(map(int,input().split()))
import fractions
from functools import reduce
def gcd_list(numbers):
  return reduce(fractions.gcd,numbers)
k=0
for i in range (0,n):
  t=li.copy()
  t.pop(i)
  m=gcd_list(t)
  if m>=k:
    k=m
print(k)

Submission status: Time Limit Exceeded

Solution code:
import functools
import copy

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

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

if N == 2:
    n = max(A)
else:
    for i in range(N):
        l = copy.copy(A)
        l.pop(i)
        res = functools.reduce(lambda x, y: gcd(x, y), l)
        if res > n:
            n = res
print(n)

Submission status: Time Limit Exceeded

Solution code:
import functools
n = int(input())
a_list = list(map(int,input().split()))

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

res = []
tmp = []
for _ in range(n):
    e = a_list.pop(0)
    if e in tmp or e in res:
        continue
    res.append(functools.reduce(gcd, a_list))
    a_list.append(e)
    tmp.append(e)

print(max(res))

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

dp = [a[1], a[0], gcd(a[0], a[1])]
for i in range(2, n):
    for j in range(i+1):
        if j != i:
            dp[j] = gcd(a[i], dp[j])
    dp += [gcd(a[i], dp[i])]


print(max(dp))

Submission status: Time Limit Exceeded

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

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

def gcd_list(X, N):
  g = X[0]
  for i in range(N):
    g = gcd(g, X[i])
  return g

num = 1
for i in range(N):
  B = A[:i]
  B.extend(A[i+1:])
  num = max(num, gcd_list(B, N-1))
  
print(num)

Submission status: Time Limit Exceeded

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

for i in range(max(a), 0, -1):
  cnt = 0
  for j in range(n):
    if a[j] % i == 0:
      cnt += 1
  if cnt >= n - 1:
    print(i)
    break

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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

#リスト l の最大公約数
def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a
  
ans = 1
for i in range(N):
    ans = max(ans, gcdlist(A[0:i]+A[i+1:N]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def gcd(a,b):
    a,b=sorted([a,b])
    while b%a!=0:
        a,b=b%a,a
    return a
n=int(input())
a=list(map(int, input().split()))
if(n==2):
    print(max(a))
    quit()
ans=0
for i in range(n):
    tmp=a[i-1]
    for j in range(n):
        if(j==i):
            continue
        tmp=gcd(tmp,a[j])
    ans=max(ans,tmp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
Als = [int(x) for x in input().split()]

import fractions
from functools import reduce



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



a = []
for i in range(N):
    Als2 = Als[:]
    Als2.pop(i)
    a.append(gcd_list(Als2)) 

print(max(a))

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 = (input()).split()
A = [int(a) for a in A]
max=0

for i in range(N):
    B = A.copy()
    del B[i]
#     print(B)
    if max < gcd(*B):
        max = gcd(*B)
            
print(max)

Submission status: Time Limit Exceeded

Solution code:
import math
import fractions
from copy import copy
n = int(input())
listA = list(map(int, input().split()))
listB = copy(listA)
listC = []
ans = 0
for i in range(n):
    del listB[i]
    ans = listB[0]
    for j in range(1, n-1):
      ans = fractions.gcd(ans, listB[j])
    listC.append(ans)
    listB = copy(listA)
print(max(listC))

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
a = [int(_) for _ in input().split()]
a.sort()

def GCD(x, y):
    while y > 0:      
        x, y = y, x % y
    return x

if n == 2:
    print(a[1])
else:
    ans = 0
    for i in range(n):
        if i == 0:
            prev = GCD(a[1], a[2])
        elif i == 1:
            prev = GCD(a[0], a[2])
        else:
            prev = GCD(a[0], a[1])
        for j in range(n):
            if j != i:
                prev = GCD(prev, a[j])
        if prev > ans:
            ans = prev
    print(ans)

Submission status: Time Limit Exceeded

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

B = {}
C = []
for i in range(N):
    if i in B and B[str(i)] >= 2:
        continue
    if i not in B:
        B[str(i)] = 1
    else:
        B[i] += 1
    C.append(A[i])

if len(B.keys()) == 2:
    max(C[0], C[1])

N = len(C)
A = C

if N == 2:
    print(max(A[0], A[1]))
else:
    m = min(A)
    ans = 1
    for i in range(m, 1, -1):
        count = 0
        for n in range(N):
            if count > 1:
                break
            if A[n] % i != 0:
                count += 1
        if count <= 1:
            ans = i
            break

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

if n <= 2 :
  print(str(max(a)))
  sys.exit()
res = 1
for i in range(min(a), 1, -1):
  count = 0
  for value in a:
    if value%i != 0 :
      count += 1
    if count >= 2 :
      break
  if count <= 1 :
    res = i
    break
print(str(res))

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]

	base = -1
	for i, val in enumerate(A):
		if i == 0:
			base == val
			continue
		base = gcd(val, base)

	ans = base
	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 tmp <= ans:
				break
 
		if 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
import copy
from functools import reduce

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

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

# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))

ka = 0
k = 0

for i in range(n):
    t = a[0]
    a.pop(0)
    ka = gcd_list(a)
    a.append(t)
    if ka > k:
        k = ka

print(k)

Submission status: Time Limit Exceeded

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


from functools import reduce

n = int(input())
a_s = list(map(int, input().split()))
mx = 0
for i in range(n):
    b = a_s[:i] + a_s[i + 1:]
    g = reduce(gcd, b)
    if g > mx:
        mx = g
print(mx)

Submission status: Time Limit Exceeded

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

def gcd(a, b):

    c = min(a, b)
    d = max(a, b)
    r = 0    
    while True:
        r = d % c
        if r == 0:
            break
        d = c
        c = r

    return c

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]


    n = int(lines[0])
    a = [int(e) for e in lines[1].split(" ")]

    return (n, a)


def solve(n, a):

    if len(a) == 2:
        return max(a[0], a[1])


    result = 1

    for i in range(n):
        b = a[:i] + a[i+1:] 
        r = gcd(b[0], b[1])
        for j in range(1, n-1):
            r = gcd(b[j], r)
        if r > result:
            result = r

    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))

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)
 
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


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(reverse=True)
    return divisors

n = int(input())
a = list(map(int, input().split()))
a_div = [make_divisors(a[i]) for i in range(n)]

flag=False

for i in range(10000000000):
    out = 0
    tmp = a_div[0][i]
    for j in range(n):
        if tmp not in a_div[j]:
            out += 1
    if out <= 1:
        break

a_tmp = a[:]
del a_tmp[0]
temp = gcd_list(a_tmp)

print(max(temp,tmp))

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy
import fractions
from functools import reduce
 
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
  
# 整数の入力
a = int(input())
# 数値のリスト化
xList = [int(i) for i in input().split()]
keisanList = deepcopy(xList)
saidai = max(xList)
saidaiKoyakuSu = 0
koyakuSu = 0
listIndex = 0
 
for i in range(a):
    keisanList = deepcopy(xList)
    keisanList[i] = saidai
    koyakuSu = gcd_list(keisanList)
    if(saidaiKoyakuSu < koyakuSu):
        saidaiKoyakuSu = koyakuSu
    if(koyakuSu >= keisanList[i]):
        break
print(saidaiKoyakuSu)

Submission status: Time Limit Exceeded

Solution code:
import fractions
from functools import reduce

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

n=int(input())
array = list(map(int, input().split())) 
# array=list(set(array))
array.sort(reverse=True)


max=-100

for i in range(n):
    copy_array=array.copy()
    if(max>array[i]):
        break
    copy_array.pop(i)
    tmp_gcd=gcd(*copy_array)
    # print(copy_array)
    if(max<tmp_gcd):
        max=tmp_gcd
    
print(max)

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
l = sorted(list(map(int, input().split())))
b = []

def gcd(a,b):
	while b:
		a, b = b, a % b
	return a
if n == 2:
	print(max(l[0],l[1]))
elif n == 3:
	print(max(gcd(l[0],l[1]),gcd(l[0],l[2]),gcd(l[2],l[1])))
else:
	for i in range(n):
		tmp = copy.copy(l)
		tmp.pop(i)
		x = gcd(tmp[0],tmp[1])
		for j in list(range(2, n-1)):
			x = gcd(x,tmp[j])
		b.append(x)
	print(max(b))

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce

d = {}


def gcd(a, b):
    if (a, b) in d:
        return d[(a, b)]
    else:
        while b != 0:
            a, b = b, a % b
        d[(a, b)] = a
    return a


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


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

max_ = 0
for i in range(1, len(A) + 1):
    num = gcd_list(A[:i-1] + A[i:])
    if max_ < num:
        max_ = num

print(max_)

Submission status: Time Limit Exceeded

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

B = {}
C = []
for i in range(N):
    if i in B and B[str(i)] >= 2:
        continue
    if i not in B:
        B[str(i)] = 1
    else:
        B[i] += 1
    C.append(A[i])

if B.keys() == 2:
    max(C[0], C[1])

N = len(C)
A = C

if N == 2:
    print(max(A[0], A[1]))
else:
    m = min(A)
    ans = 1
    for i in range(m, 1, -1):
        count = 0
        for n in range(N):
            if count > 1:
                break
            if A[n] % i != 0:
                count += 1
        if count <= 1:
            ans = i
            break

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import collections 
import fractions
import math
import copy

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    A = list(int(_) for _ in input().split())
    ans = 0
    
    for i in range(N):
        A_tmp = copy.copy(A)
        A_tmp.pop(i)
        div_num = A_tmp[0]
        for j in range(1,N-1):
            div_num = fractions.gcd(div_num,A_tmp[j])
        ans = max(div_num,ans)

    print(ans)
    
if __name__ == '__main__':
    main()