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: Runtime Error

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



GG=[0]*N
GG[0]=A[0]
for i in range(1,N):
    GG[i]=math.gcd(GG[i-1],A[i])

GG2=[0]*N
GG2[-1]=A[-1]

for i in range(2,N+1):
    GG2[-i]=math.gcd(GG2[-(i-1)],A[-i])

ans=[0]*N

ans[0]=GG2[1]
ans[-1]=GG[N-2]
#print(GG)
#print(GG2)
#print(ans)


temp=ans[0]
for i in range(1,N-1):
    ans[i]=math.gcd(GG[i-1],GG2[i+1])
    if ans[i]>temp:
        temp=ans[i]
if ans[-1]>temp:
    temp=ans[-1]


print(temp)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

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

for i in range(int(n/2) +1):
    aa = a[i]
    a[i] = a[i+1]
    t.append(gcd(*a))
    a[i] = aa
    
print(max(t))

Submission status: Runtime Error

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

def gcd (a: int,b: int) -> int:
    if a < b: a,b = b,a
    return a if b == 0 else gcd(b,a%b)
def lcm (a: int,b: int) -> int:
    return a // gcd(a,b) * b

def dfs(i,v,flg):
    if i == N-1:
        if flg:
            return gcd(A[N-1],v)
        else:
            return v
    if flg:
        return dfs(i+1,gcd(A[i],v),True)
    else:
        return max(dfs(i+1,gcd(v,A[i]),False),dfs(i+1,v,True))

if N == 2:
    print(max(A))
    exit(0)
else:
    print(max(dfs(1,A[0],False),dfs(2,A[1],True)))

Submission status: Runtime Error

Solution code:
num = input()
tar = input().split()
cnt = 0
aaa = 0
tmp = []

nyan = int(tar[0])

for i in range(int(num)):
  if nyan < int(tar[i]):
    nyan = int(tar[i])
    aaa = i

for i in range(1,int(nyan)):
  for j in range(int(num)):
    if int(tar[j]) < j:
      break
    if int(tar[j])%i == 0:
      cnt +=1
  if cnt >= int(num)-1:
    tmp.append(i)
  cnt = 0

print(tmp[len(tmp)-1])

Submission status: Runtime Error

Solution code:
import math
import copy

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

result = 0

def gcd_list(nums):
    x = math.gcd(nums[0],nums[1])
    for i in range(2,len(nums)):
        x = math.gcd(nums[i],x)
    return x

for i in range(N):
    a = copy.deepcopy(A)
    del a[i]
    result = max(gcd_list(a),result)

print(result)

Submission status: Runtime Error

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from math import gcd
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


def GCD(lis): return reduce(gcd, lis)


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

n = INT()

a = LIST()

q = GCD(a)

for i in range(n):
    lis = a.copy()
    lis.pop(i)
    if GCD(lis) > q:
        q = GCD(lis)

print(q)

Submission status: Runtime Error

Solution code:
import copy
import math
from functools import reduce

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

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

MAXNUM = max(A)
MGCD = 0
COPYA = copy.deepcopy(A)

for i in range(N):
    if i > 0:
        A[i-1] = COPYA[i-1]
    for n in range(1,MAXNUM):
        A[i] = n
        tmp = gcd_list(A)
        if tmp > MGCD:
            MGCD = tmp

print(MGCD)

Submission status: Runtime Error

Solution code:
import collections

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

    # divisors.sort()
    return divisors
  
def check(num, kouho, N, i):
  for val in kouho.keys():
    if num%val == 0:
      kouho[val] += 1
    return {k: v for k, v in kouho.items() if v > i-2}
  
  
N = int(input())
A= list(map(int, input().split()))

divs = []
for i in range(3):
  divs.extend(cal_divs(A[i]))
kouho = {}
c = collections.Counter(divs)
for div, n in c.most_common():
	kouho[div] = n
    
kouho = {k: v for k, v in kouho.items() if v > 1}

for i,num in enumerate(A[3:]):
  kouho = check(num, kouho, N, i+3)
  print(kouho)
  
print(max(kouho))

Submission status: Runtime Error

Solution code:

n = int(input())

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


from functools import lru_cache
import sys
if n == 2:
    print(max(a))
    sys.exit()


@lru_cache(maxsize=100000)
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def gcd_list(li):
    g = gcd(li[0], li[1])
    for i in range(2, len(li)):
        g = gcd(g, a[i])
    return g


def gcd_list_2(li):
    g = gcd(li[0], li[1])
    if g == 1:
        return max(gcd_list([li[0]] + li[2:]), gcd_list(li[1:]))
    for i in range(2, n):
        if gcd(g, a[i]) == 1:
            return gcd_list([g] + li[i + 1:])
        else:
            g = gcd(g, a[i])
    return g


def max_gcd(a):
    g = gcd_list(a)
    a = [a[i]//g for i in range(n)]
    m = gcd_list_2(a)
    print(g * m)


max_gcd(a)

Submission status: Runtime Error

Solution code:
import math
import copy 

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

if __name__ == '__main__':
	N=int(input())
	A=list(map(int,input().split()))

	ans=0
	for i in range(N):
		l=copy.deepcopy(A)
		l.pop(int(i))
		if(N > 2):
			tmp_gcd=math.gcd(l[0],l[1])
			for j in range(len(l)):
				tmp_gcd=math.gcd(tmp_gcd,l[j])
			if(tmp_gcd >= ans):
				ans=tmp_gcd
		else:
			ans=math.gcd(A[0],A[1])
	print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcd(numlist):
    return reduce(math.gcd, numlist)

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

ans = 0

maxA = max(Alist)
for i in range(N):
    Ai = Alist[i]
    Alist[i] = maxA
    Agcd = gcd(Alist)
    if ans < Agcd:
        ans = Agcd
    Alist[i] = Ai

print(ans)

Submission status: Runtime Error

Solution code:
#C
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
N=int(input())
A = [int(j) for j in input().split()]
A=list(set(A))
A.sort()
ans=0

for a in A:
    if len(A)!=1:
        tmp=A.copy()
        tmp.remove(a)  
        ans=max(ans,gcd(*tmp))
    else:
        ans=A[0]
print(ans)

Submission status: Runtime Error

Solution code:
import copy
import fractions
import sys


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    gcd_list = []
    if n == 1:
        print(10**10 - 1)
    else:
        for i in range(len(a_list)):
            cp_list = copy.copy(a_list)
            del cp_list[i]
            gcd_tmp = cp_list.pop()
            gcd_list.append(multiple_gcd(gcd_tmp, cp_list))
        print(max(gcd_list))


def multiple_gcd(gcd, num_list):
    if len(num_list) == 0:
        return gcd
    return multiple_gcd(fractions.gcd(gcd, num_list.pop()), num_list)


if __name__ == "__main__":
    sys.setrecursionlimit(10000)
    main()

Submission status: Runtime Error

Solution code:
#C - GCD on Blackboard
import math
from functools import reduce

def gcdList(num):
    return reduce(math.gcd, num)

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

for i in range(n):
    if i == 0:
        tmp = gcdList(a[1:])
    elif  0 < i and i < n: 
        tmp = gcdList(a[:i] + a[i+1:])
    else:
        tmp =  gcdList(a[:n])
    ans = max(ans, tmp)
print(ans)

Submission status: Runtime Error

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

def gcd(a,b):
	while b:
		a, b = b, a % b
	return a
if n == 1:
	print(l[0])
elif n == 2:
	print(gcd(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 = 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: Runtime Error

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

import math
from functools import reduce

def gcd(num_list):
    return reduce(math.gcd, num_list)

kys = []

for i in range(N):
    B = A.copy()
    B.pop(i)
    kys.append(gcd(B))

print(max(kys))

Submission status: Runtime Error

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()]
cand = 0
mingcd = gcd_list(A)
if(N<2):
    print(max(A))
else:
    for i in range(N-1):
        if(mingcd==fractions.gcd(A[i],A[i+1])):
            if(i<N-1):
                if(mingcd==fractions.gcd(A[i],A[i+2])):
                    cand = i
                else:
                    cand = i+1
                break
            else:
                if(mingcd==fractions.gcd(A[i],A[i-2])):
                    cand = i
                else:
                    cand = i+1
                break
    print(gcd_list(A[:cand]+A[cand+1:]))

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
//#define MOD 1000000007
#define MOD 998244353
#define INF 100000000000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

int gcd(int a,int b){
    if(a<=0||b<=0){
        return 0;
    }
    if(a<b)swap(a,b);
    int r=a%b;
    while(r){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}


signed main(){
    int N;
    int A[114514];
    cin >> N;
    REP(i,N){cin >> A[i];}
    if(N==2){
        cout << max(A[0],A[1]) << endl;
        return 0;
    }
    sort(A,A+N);
    int B[114514];
    B[0]=A[0];
    REP(i,N-1){
        B[i+1]=A[i+1]-A[i];
    }
    sort(B,B+N);
    B[0]+=B[1];
    B[1]=B[0];
    int Ans=B[0];
    REP(i,N){
        Ans=gcd(Ans,B[i]);
    }
    cout << Ans << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
import fractions

N=int(input())
a_list = [int(i) for i in input()]
result = 0
for i in range(N):
	b_list = a_list[:]
	del b_list[i]
	gcd = fractions.gcd(math.gcd, b_list)
	if gcd > result:
		result = gcd
print(result)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import copy
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
N = int(input())
A=list(map(int,input().split()))
max_ = 1
for j,i in enumerate(A):
    replace = i
    B = copy.deepcopy(A)
    B.pop(j)
    for t in range(1,min(B)):
        temp=[]
        temp.append(t)
        temp.extend(B)
        y = gcd_list(temp)
        if y> max_:
            max_=y
print(max_)

Submission status: Runtime Error

Solution code:
import math
import sys
from functools import reduce

def gcd2(array):
    return reduce(math.gcd, array)


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

i = sys.maxsize
l = 0
for k in range(n):
    if i > math.gcd(a[k], m):
        i = math.gcd(a[k], m)
        l = k
    elif i == math.gcd(a[k], m):
        del a[k]
        print(gcd2(a))
        sys.exit(0)
del a[l]
print(gcd2(a))

Submission status: Runtime Error

Solution code:
# from math import gcd
import math
N = int(input())
A = list(map(int,input().split()))
# N=3
# A=[12 ,15 ,18]
l=[0]*N
r=[0]*N
l[0]=A[0]
r[0]=A[N-1]
for i in range(1,N-1):
    l[i]=math.gcd(l[i-1],A[i])
    r[i]=math.gcd(r[i-1],A[N-1-i])    
gcdlist = [1,l[N-2],r[N-2]]
for i in range(N-2):
    gcdlist.append(math.gcd(l[i],r[N-3-i]))
# print(gcdlist)
print(max(gcdlist))

Submission status: Runtime Error

Solution code:
import functools
import math
import copy

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

A.sort()
ans = 1

for i in range(N):
    B = copy.copy(A)
    B.pop(i)
    gcd = functools.reduce(math.gcd, B)
    ans = max(ans, gcd)

print(ans)

Submission status: Runtime Error

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

N = int(input())
A = list(map(int, input().split()))
A.sort()
s = []
for i in range(len(A)-1):
	for j in range(i+1,len(A)):
		s.append(gcd(A[i], A[j]))

if(len(set(s)) != 1):
	ss = min(s)
	for i in s:
		s.remove(ss)
	print(s[0])
else:
	print(s[0])

Submission status: Runtime Error

Solution code:
import math

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

gcd_1 = [math.gcd(A[0],A[i]) for i in range(1,n)]

gcd_1.sort()

gcd_2 = A[1]

for i in range(2,n):
      gcd_2 = math.gcd(gcd_2,A[i])

if n == 2:
    print(A[0])
else:
    print(max(gcd_1[1],gcd_2))

Submission status: Runtime Error

Solution code:
from copy import deepcopy

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

def gcd_mul(numbers):
    s = gcd(numbers[0], numbers[1])
    for i in range(2, len(numbers)) :
        s = gcd(s, numbers[i])
    return(s)

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

ans = 0
A2 = deepcopy(A)
for i in range(N) :
    del A[i]
    g = gcd_mul(A)
    if g > ans :
        ans = g
    A = deepcopy(A2)
print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

    # divisors.sort()
    return divisors
  
def check(num, kouho, N, i):
  for val in kouho.keys():
    if num%val != 0:
      kouho[val] -= 1
    return {k: v for k, v in kouho.items() if v > i-2}
  
  
N = int(input())
A= list(map(int, input().split()))

divs = []
for i in range(3):
  divs.extend(cal_divs(A[i]))
kouho = {}
c = collections.Counter(divs)
for div, n in c.most_common():
	kouho[div] = n
    
kouho = {k: v for k, v in kouho.items() if v > 1}

for i,num in enumerate(A[3:]):
  kouho = check(num, kouho, N, i+3)

print(max(kouho))

Submission status: Runtime Error

Solution code:
import math
import copy

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

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

if N==2:
    print(max(A))
    exit()
else:
    max=0
    for i in range(N):
        x = copy.deepcopy(A)
        del x[i]
        c = gcd(x[0], x[1])
        for i in range(2,N-1):
            c=gcd(element,x[i])
        if c >= max:
            max = c
print(max)

Submission status: Runtime Error

Solution code:
from math import gcd, sqrt
from sys import exit
N=int(input())
A=list(map(int,input().split()))

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

g=gcd(A[0],A[-1])

p=[]
for i in range(1,int(sqrt(g)+1)):
    if g%i==0:
        if i*i==g: p.append(i)
        else: p+=[i,g//i]
        
def ok(n):
    f=False
    for a in A[1:-1]:
        if a%n:
            if f: return False
            f=True
    return True
    
def GCD(L):
    if len(L)==1: return L[0]
    ans=gcd(L[0],L[1])
    if len(L)>2:
        for l in L[2:]:
            ans=gcd(ans,l)
    return ans

p.sort(reverse=True)
for num in p:
    if ok(num):
        ans=num
        break
p1=GCD(A[1:-1])
print(max([ans,gcd(p1,A[0]),gcd(p1,A[-1])]))

Submission status: Runtime Error

Solution code:
from statistics import mode
N = int(input())
A=list(map(int,input().split()))
tmp=[]
ans=[]
if N<100:
  for i in range(N):
    tmp=copy.copy(A)
    tmp.pop(i)
    ans.append(gcd_list(tmp))
  print(max(ans))
else:
  A1=copy.copy(A[0:N/2])
  A2=copy.copy(A[N/2:])
  ans.append(gcd_list(A1))
  ans.append(gcd_list(A2))
  print(max(ans))

Submission status: Runtime Error

Solution code:
from sys import stdin
import numpy as np
import math

n = stdin.readline().rstrip()
n = int(n)

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

max = 0
for i in range(len(a)):
    for j in range(i, len(a)):
        if i == j:
            continue

        g = math.gcd(a[i], a[j])
        if max < g:
            max = g

print(max)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
for x in input().split():
    a.append(int(x))

ans = []

import math
from functools import reduce

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

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

for i in range(n):
    c = a.copy()
    c.remove(a[i])
    ans.append(gcd_list(c))

print(max(ans))

Submission status: Runtime Error

Solution code:
n=int(input())
a=sorted([int(i) for i in input().split()])
gcd1=[0]*n
gcd2=[0]*n
for i in range(n):
    if i!=0:
        gcd1[i]=gcd(a[0],a[i])
    if i!=1:
        gcd2[i]=gcd(a[1],a[i])
print(max(max(gcd1),max(gcd2)))

Submission status: Runtime Error

Solution code:
import math,copy
from functools import reduce
N=int(input())
A=list(map(int,input().split()))
g=[]
def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
B=copy.copy(A)
for i in range(N):
    del B[i]
    g.append(gcd_list(B))
    B=copy.copy(A)
print(max(g))

Submission status: Runtime Error

Solution code:

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

n = int(input())
a = list(map(int,input().split()))
#a = list(set(a))
a.sort()
"""
a = a[0:3]
"""
#print(a)
p1 = gcd(a[0],a[1])
p2 = gcd(a[1],a[2])
p3 = gcd(a[0],a[2])

p = [p1,p2,p3]
"""
for i in p:
    if min(p) == i:
"""
"""
f1 = 0
f2 = 0
f3 = 0
res0 = []
res1 = []
res2 = []
res = []
for i in range(n):
    if a[i]%a[0]!= 0:
        f1 += 1
        res0.append(a[i])
        res.append(a[i])
    if a[i]%a[1]!= 0 and i>0:
        f2 += 1
        res1.append(a[i])
        res.append(a[i])
    if a[i]%a[2]!= 0 and i>1:
        f3 += 1
        res3.append(a[i])
        res.append(a[i])
    
    if sum(f1,f2,f3) > 1:
        print(1)
        break

    if sum(f1,f2,f3):
        res = res[i]
        break
        """
f = 0
tmp = a[0]
res1,res2,res3 = p1,p2,p3
for i in range(n):
    if gcd(tmp,a[i])==1:
        f += 1
    else:
        tmp = gcd(tmp,a[i])

    if i>=3:
        res1 = gcd(res1,a[i])
        res2 = gcd(res2,a[i])
        res3 = gcd(res3,a[i])

    if f > 1:
        print(tmp)
        break
else:
    print(max(tmp,res1,res2,res3))

Submission status: Runtime Error

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

mm = 0
for i in range(N):
  for j in range(i+1,N):
    g = gcd(A[i],A[j])
    if mm < g:
      mm = g
      
    #print(i,j,g)
    
print(mm)

Submission status: Runtime Error

Solution code:
import math
import numpy as np
from functools import reduce

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


N = int(input())
A_list = list(map(int,input().split()))
temp_max= 0
for i in range(N):
        temp_list = A_list.copy()
        temp_list.pop(i)
        gcd_temp = gcd(*temp_list)
        if type(gcd_temp)== int:
                gcd_temp = [gcd_temp] 
        if max(gcd_temp)>temp_max:
                temp_max = max(gcd_temp)

print(temp_max)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
N = int(input())
A = input().split()
A = [int(i) for i in A]
ret_max = 0

def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
        return reduce(math.gcd, numbers)
    
for i in range(len(A)):
    a = A.pop(i)
    tmp = gcd_list(a)
    if tmp > ret_max:
        ret_max = tmp
print(ret_max)

Submission status: Runtime Error

Solution code:
import functools
import math

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

max = 0
for i in range(len(li)):
    n_li = li[0:i] + li[i+1:]
    gcd = functools.reduce(math.gcd, n_li)
    if max < gcd:
        max = gcd
print(max)

Submission status: Runtime Error

Solution code:
import copy,math

def gcd_lis(l):
    res = 0
    for i in range(len(l)-1):
        if i == 0:
            res = math.gcd(l[i],l[i+1])
        else:
            res = math.gcd(res,l[i+1])
    return res

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

reslis = []
reslis.append(gcd_lis(lis))
for i in range(n):
    tmp = copy.deepcopy(lis)
    del tmp[i]
    reslis.append(gcd_lis(tmp))
print(max(reslis))

Submission status: Runtime Error

Solution code:
import math

words = lambda t : list(map(t, input().split()))

n = int(input())
a = words(int)

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

else:
    cgcdm1 = max(math.gcd(a[0],a[1]),math.gcd(a[1],a[2]),math.gcd(a[2],a[0]))
    allgcd = math.gcd(a[0],math.gcd(a[1],a[2]))

    for i in range(3,n):
        cgcdm1 = max(math.gcd(cgcdm1,a[i]),allgcd)
        allgcd = math.gcd(allgcd, a[i])

    print(cgcdm1)

Submission status: Runtime Error

Solution code:
import math
import fractions
from functools import reduce

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

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

ans=[]

b=a[:-1]
ans.append(gcd_list(b))


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

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

Submission status: Runtime Error

Solution code:
import functools
import math

n = int(input())
a = list(int(n) for n in input().split())

#gcd = functools.reduce(math.gcd, a)
# print(gcd)

max = 0

for i in range(n):
    j = a.pop(0)
#    print(a)
    if max < functools.reduce(math.gcd, a):
        max = functools.reduce(math.gcd, a)
    a.append(j)

print(max)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
a=int(input())
li=list(map(int,input().split()))
#li_same=li
num=0
num_li=[]
for i in range(a):
    #li=li_same
    b=li.pop(i)
    num=gcd_list(li)
    num_li.append(num)
    li.insert(i,b)
   
print(max(num_li))

Submission status: Runtime Error

Solution code:
import math
import copy 

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

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

ans=0
for i in range(N):
	l=copy.deepcopy(A)
	l.pop(int(i))
	if(N > 2):
		tmp_gcd=math.gcd(l[0],l[1])
		for j in range(len(l)):
			tmp_gcd=math.gcd(tmp_gcd,l[j])
		if(tmp_gcd >= ans):
			ans=tmp_gcd
	else:
		ans=math.gcd(A[0],A[1])
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
from functools import reduce

input = sys.stdin.readline


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


def gcd2(index, a_list):
    nums = a_list[:]
    del nums[index]
    return gcd(nums)


def main():
    n = int(input())
    a_list = [int(i) for i in input().split()]
    print(max([gcd2(i, a_list) for i in range(n)]))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math

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

if n == 2:
    a.append(math.gcd(a[0],a[1]))

g0 = [math.gcd(a[0],a[1]),math.gcd(a[0],a[2]),math.gcd(a[1],a[2])]
s_g0 = sorted(g0,reverse=True)

maxg1 = s_g0[0]
maxg2 = s_g0[1]

if n >= 4:
    for i in range(n - 3):
        maxg1 = math.gcd(maxg1,a[i + 3])
        maxg2 = math.gcd(maxg2,a[i + 3])

if maxg1 >= maxg2:
    print(maxg1)
else:
    print(maxg2)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
for i in range(1,min(a)+1):
    c = 0
    for j in range(0,N):
        if a[j]%i != 0:
            c += 1
    if c == 1:
        o = i
print(o)

Submission status: Runtime Error

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

def get_gcd(x,n):
    if n==1:
        print(x[0])
    else:
        element = gcd(x[0], x[1])
        if n==2:
            return element
        else:
            for i in range(2,n):
                element = gcd(element,x[i])
            return element

n = int(input())
a = [int(i) for i in input().split()]
interim_max = 0
for i in range(n):
    max_gcd = get_gcd(a[:i]+a[i+1:], n-1)
    if interim_max < max_gcd:
        interim_max = max_gcd
print(interim_max)

Submission status: Runtime Error

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


def blackbord(n,a):
    if n==2 and a[0]==a[1]:
        return a[0]
    else:
        return max(list(hcf(i,j) for i in a for j in list(filter(lambda b:b!=i,a))))
 
n = int(input())
a=list(map(int, input().split()))
print(blackbord(n,a))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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


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

ans = 0
for i in range(n):
    init = a_list[:]
    init.pop(i)
    gcd = gcd_list(init)
    if ans < gcd:
        ans = gcd

print(ans)

Submission status: Runtime Error

Solution code:
import fraction
import functools
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]
    gcd = functools.reduce(fraction.gcd, a)
    gll.append(gcd)
    a.insert(i,s)
print(max(gll))

Submission status: Runtime Error

Solution code:
import math

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

M = max(A)
ans = 1

G = math.gcd(A[0], A[1])
for i in range(2, N):
  G = math.gcd(G, A[i])

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

print(ans)

Submission status: Runtime Error

Solution code:
import functools
import math


def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    # gcd = functools.reduce(math.gcd, A)
    max_gcd = 1
    for i in range(N):
        A_ = A.copy()
        A_.remove(A[i])
        max_gcd = max(max_gcd, functools.reduce(math.gcd, A_))
    print(max_gcd)
    

if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

n = int(input())

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

a = [4,8,12,9,16]


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


gcd_l = [a[0]]
gcd_r = [a[-1]]
for i in range(1,n):
    gcd_l.append(fractions.gcd(gcd_l[i-1],a[i]))
    gcd_r.append(fractions.gcd(gcd_r[i-1],a[-i-1]))

gcd_r.reverse()

ans = max(gcd_l[1],gcd_r[-2])
for i in range(1,n-1):
    gcd = fractions.gcd(gcd_l[i-1],gcd_r[i+1])
    ans = max(ans,gcd)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
Alist = list(map(int, input().split()))
def gcd(a,b):
    while b!=0:
        a,b = b, a%b
    return a
def gcds(numbers):
    if len(numbers) == 2:
        return gcd(*numbers)
    else:
        n1 = gcd(numbers[0], numbers[1])
        return gcds(*[n1]+numbers[2:])
if len(Alist)>2:
    gcdlist = [gcds(Alist[:i]+Alist[i+1:]) for i in range(N)]
    print(max(gcdlist))
else:
    print(gcds(Alist))

Submission status: Runtime Error

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

import fractions
from functools import reduce
from copy import copy

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

gcds=[]
for i in range(N):
    A_=copy(A)
    A_=pop(i)
    gcds.append(gcd(*A_))

print(max(gcds))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

def get_gcd(*alist):
    return reduce(math.gcd, alist)

max_gcd = 0
for i in range(N):
    A_=[]
    for j in range(N):
        if j != i:
            A_.append(A[j])
    gcd = get_gcd(*A_)
    if max_gcd < gcd:
        max_gcd = gcd
print(max_gcd)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
Al = list(map(int, input().split()))
a = 0
b = 0

if N = 2:
  a = max(Al)
else:
  for i in range(0, N-1):
    c = math.gcd(Al[i], Al[i+1])
    if b > c:
      b = math.gcd(Al[i], Al[i+1])
  a = b
  print(a)

Submission status: Runtime Error

Solution code:
import fractions
import copy
from functools import reduce
from statistics import mode
N = int(input())
A=list(map(int,input().split()))
tmp=[]
ans=[]
if N<100:
  for i in range(N):
    tmp=copy.copy(A)
    tmp.pop(i)
    ans.append(gcd_list(tmp))
  print(max(ans))
else:
  A1=copy.copy(A[0:N/2])
  A2=copy.copy(A[N/2:])
  for i in range(N/2):
    tmp=copy.copy(A)
    tmp.pop(i)
    ans.append(gcd_list(tmp))
  print(max(ans))

Submission status: Runtime Error

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

A = list(set(A))

result = []
for i,a in enumerate(A):
    if len(A)==1:
        tmpA=A
        break
        
    tmpA = A[:i]+A[i+1:]
    while True:
        minA = min(tmpA)
        tmpA = set([a % minA for a in tmpA])
        tmpA.discard(0)
        tmpA.add(minA)
        if len(tmpA)==1:
            break
    result.append(list(tmpA)[0])

print(max(result))

Submission status: Runtime Error

Solution code:
import math

num = input()
tar = input().split()
cnt = 0
aaa = 0
tmp = []

nyan = int(tar[0])

for i in range(int(num)):
  if nyan < int(tar[i]):
    nyan = int(tar[i])
    aaa = i

for i in range(1,int(nyan)):
  for j in range(int(num)):
    if int(tar[j])%i == 0:
      cnt +=1
  if cnt >= int(num)-1:
    tmp.append(i)
  cnt = 0

print(tmp[len(tmp)-1])

Submission status: Runtime Error

Solution code:
import math

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

ans_list = []
for i in range(N):
    if N != 2:
        ans_list.append(math.gcd(*(v_list[:i] + v_list[i+1:])))
    else:
        ans_list = v_list

print(max(ans_list))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

n = int(input())
a_s = set(map(int, input().split()))
a = list(a_s)
b = list()
c = list()
for i in range(n):
    b = a[::]
    del b[i]
    c.append(gcd_list(b))
print(max(c))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import functools


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


n = int(input())
a = list(map(int, input().split(" ")))
res = []
for i in range(n):
    tmp = a[:]
    del tmp[i]
    res.append(gcd_list(tmp))

print(max(res))

Submission status: Runtime Error

Solution code:
def make_divisors(arg):
    divisors = set()
    for i in range(1, int(arg**0.5)+1):
        if arg % i == 0:
            divisors.add(i)
            if i != arg // i:
                divisors.add(arg//i)

    return divisors


n = int(input())
a = list(map(int, input().split()))
a.sort()
a0y = make_divisors(a[0])
a1y = make_divisors(a[1])
common = a0y & a1y
one = a0y ^ a1y
last = 0
for e in a[2:]:
    if e == last:
        continue
    tmp = make_divisors(e)
    common = tmp & common
    one = (one & tmp)
    last = e

print(max(*common, *one))