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

a.sort()

if n == 2:
    print(a[1])
else:
    gcd1 = math.gcd(a[0],a[1])
    gcd2 = math.gcd(a[1],a[2])
    gcd3 = math.gcd(a[0],a[2])

    for i in range(3,n):
        if math.gcd(gcd1, a[i]) < gcd1:
            gcd1 = math.gcd(gcd1, a[i])

    for i in range(3,n):
        if math.gcd(gcd2, a[i]) < gcd2:
            gcd2 = math.gcd(gcd2, a[i])

    for i in range(3,n):
        if math.gcd(gcd3, a[i]) < gcd3:
            gcd3 = math.gcd(gcd3, a[i])

    ans = [gcd1, gcd2, gcd3]
    ans.sort()

    print(ans[-1])

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

n=int(input())
v=[int(x) for x in input().split()]
k=0
for i in range(n):
    d=v[i]
    v[i]=0
    l=gcd_list(v)
    if l>int(k):
        k=l
    v[i]=d
print(int(k))

Submission status: Runtime Error

Solution code:
import fractions
import  functools

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




N = int(input())
A = [int(x) for x in input().split()]
a2 = A.copy()
max = 0
for i,_ in enumerate(A):
    A.pop(i)
    res = A[0]
    for i in A[1:]:
        res = gcd(res,i)
    max = res if res >= max else max
    A = a2.copy()


print(max)

Submission status: Runtime Error

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

if N > 2:
    a.sort()
    diff = []
    for i in range(N-1):
        diff.append(a[i+1]-a[i])
    index = diff.index(min(diff))
    diff_ = diff[:]
    if index > 0:
        plus = diff[index-1] + diff[index]
        diff_[index-1] = plus
        diff_[index] = plus
    GCD = diff_[0]

    for i in range(N-1):
        GCD = gcd(diff_[i], GCD)

    if index < N-1:
        plus = diff[index] + diff[index+1]
        diff[index] = plus
        diff[index+1] = plus
    GCD2 = diff[0]
    for i in range(N-1):
        GCD2 = gcd(diff[i], GCD2)
    print(max(GCD, GCD2))
else:
    print(max(a))

Submission status: Runtime Error

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

glist = []
for i in range(N):
    a = copy.copy(A)
    a.pop(i)
    g = a[0]
    for j in range(N-1):
        g = math.gcd(g, a[j])
        if g == 1:
            break
    glist.append(g)

print(max(glist))

Submission status: Runtime Error

Solution code:
import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

kouho = []
n = ni()
li = na()
flag = 0
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    kouho.append(fractions.gcd(li[0], li[1]))
    kouho.append(fractions.gcd(li[1], li[2]))
    kouho.append(fractions.gcd(li[2], li[0]))
    for i in range(3,n):
        if len(kouho) == 0:
            print(i)
            break
        for num in kouho:
            if li[i] % num != 0:
                kouho.remove(num)
print(max(kouho))

Submission status: Runtime Error

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

ans = 1
if n == 2:
    print(max(a))
else:
    for i in range(n):
        b = a[:i] + a[i + 1:]
        element = math.gcd(b[0], b[1])
        if n == 3:
            ans = max(ans, element)
        else:
            for j in range(2, n - 1):
                element = math.gcd(element, b[i])
            ans = max(ans, element)
    print(ans)

Submission status: Runtime Error

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

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

def gcd(*numbers):
    return reduce(math.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

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

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

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

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

N = int(input())
A = list(map(int, input().split(' ')))
count = 0
tmp = 0
for i in range(len(A)):
    A_list = A.copy()
    A_list.pop(i)
    result = reduce(fractions.gcd, A_list)
    if result > count:
        count = result
print(count)

Submission status: Runtime Error

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
b=a
c=[0]*n
ans=a[0]
if n==2:
    print(max(a[0],a[1]))
for i in range(n):
    for j in range(n):
        if j==i:
            if j==0:
                ans=a[1]
        else:
            #print(j)
            ans=math.gcd(ans,a[j])
   # a[i]=b[i]
        c[i]=ans
    ans=a[0]
#print(c)
print(max(c))

Submission status: Runtime Error

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

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

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

a = min2
for i in range(min):
    cnt=0
    cnt2=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: Runtime Error

Solution code:
from functools import reduce


def gcd(a, b):
    if not b:
        return a
    return gcd(b, a % b)


def main():
    input()
    nums = set(map(int, input().split()))

    max_c = reduce(gcd, nums)

    if len(nums) == 2:
        return max_c

    for i in range(len(nums)):
        poped_nums = list(nums)
        poped_nums.pop(i)
        c = reduce(gcd, poped_nums)
        if c > max_c:
            max_c = c
    return max_c


print(main())

Submission status: Runtime Error

Solution code:
from fractions import gcd  # in math module python >= 3.5
from functools import reduce


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


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

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

    gcds = []
    for i in range(len(a)):
        excepted = [a[j] for j in range(len(a)) if j != i]
        b = 0
        while all([k % 2 == 0 for k in excepted]):
            b += 1
            excepted = [k // 2 for k in excepted]

        if b > 0:
            gcds.append(gcdall(excepted) * 2 * b)
        else:
            gcds.append(gcdall(excepted))
    print(max(gcds))


main()

Submission status: Runtime Error

Solution code:
import math
import functools
n=int(input())
a=list(map(int,input().split()))
A=functools.reduce(math.gcd,a)
for i in range(n):
    c=a[i]
    del a[i]
    B=functools.reduce(math.gcd,a)
    if A<B:
        A=B
    else:
        A=A
    a.insert(i,c)
print(A)

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce

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

memo = set()


def __gcd(a, b):
    if (a, b) in memo:
        return memo[a, b]
    else:
        if a < b:
            a, b = b, a
        memo.add((a, b))
        return gcd(a, b)


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


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

Submission status: Runtime Error

Solution code:
import math
import copy

from functools import reduce

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

maxv = 0

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

for i in range(N-1):
    test = copy.copy(Value)
    del test[i]
    if maxv <= gcd_list(test):
        maxv = gcd_list(test)
        
print(maxv)

Submission status: Runtime Error

Solution code:

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

Submission status: Runtime Error

Solution code:
import math
n=int(input())
a=list(map(int, input().split()))
ans=[0]*(n-1)
ans2=[0]*(n-2)

for i in range(1,n):
    ans[i-1] = math.gcd(a[0], a[i])
for i in range(2,n):
    ans2[i-2] = math.gcd(a[1], a[i])
sorted(ans)
sorted(ans2)

if n==3:
    print(max(ans[0],ans2[0]))
elif n==2:
    print(max(a))
else:
    print(max(ans[1],ans2[1]))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

from copy import copy
from math import gcd

def all_gcd(numbers):
    result = numbers[0]
    for v in numbers:
        result = gcd(result, v)
    return result

def main():
    n = int(input())
    a = list(map(int, input().split()))
    max_gcd = 0
    for i in range(n):
        b = copy(a)
        del b[i]
        bgcd = all_gcd(b)
        if max_gcd < bgcd:
            max_gcd = bgcd
    print(max_gcd)




if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

N = int(input())
A = list(map(int, input().split(' ')))
count = 0
tmp = 0
for i in range(len(A)):
    A_list = A.copy().pop(i)
    result = reduce(fractions.gcd, A_list)
    if result > count:
        count = result
print(count)

Submission status: Runtime Error

Solution code:
#import math
import fraction as math

N = int(input())
A = list(map(int, input().split()))
memo = {}
x = A[1]
for a in A[2:]:
    n = math.gcd(x, a)
    memo[(x, a)] = n
    x = n
max_gcd = x

for i in range(N):
    x = A[0]
    for j in range(N):
        if i == j:
            pass
        else:
            if (x, A[j]) in memo:
                x = memo[(x, A[j])]
            else:
                n = math.gcd(x, A[j])
                memo[(x, A[j])] = n
                x = n
    max_gcd = max(max_gcd, x)
print(max_gcd)

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-1]

for i in range(1,N-1):
    ans[i]=math.gcd(GG[i-1],GG2[i+1])
print(max(ans))

Submission status: Runtime Error

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 = set(LI())
    l = len(a)
    m = max(a)
    lm = m // (l-1)
    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):
                    t = c*(k**i)
                    if t > lm:
                        break
                    r.append(t)
        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: Runtime Error

Solution code:
import math
from functools import reduce

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(int,input().split()))
import math
if n > 2:
    a = math.gcd(s[0],s[1])
    b = math.gcd(s[1],s[2])
    c = math.gcd(s[2],s[0])

    s = max(a,b,c)
    t = min(a,b,c)
    p = s
    q = []
    if n == 3:
        print(s)
    else:
        for i in range(n-3):
            p = math.gcd(p,s[i+3])
            q.append(math.gcd(t,s[i+3]))
        q.sort()
        print(max(p,q[1]))
else:
    print(max(s))

Submission status: Runtime Error

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

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

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

n=int(input())

arr = np.array(list(map(int,input().split()))).astype(np.int)

ans=0

for i in range(n):
    ind = np.ones(n, dtype=bool)
    ind[i] = False
    #print(arr[ind])
    ans=max(ans,gcd_list(arr[ind]) )

print(ans)

Submission status: Runtime Error

Solution code:
import copy
import fractions


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    gcd_list = []
    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__":
    main()

Submission status: Runtime Error

Solution code:
import math

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

a.sort()

if n == 2:
    print(a[1])
else:
    gcd1 = math.gcd(a[0],a[1])
    gcd2 = math.gcd(a[1],a[2])
    gcd3 = math.gcd(a[0],a[2])

    for i in range(3,n):
        if math.gcd(gcd1, i) < gcd1:
            gcd1 = math.gcd(gcd1, i)

    for i in range(3,n):
        if math.gcd(gcd2, i) < gcd2:
            gcd2 = math.gcd(gcd2, i)

    for i in range(3,n):
        if math.gcd(gcd3, i) < gcd3:
            gcd3 = math.gcd(gcd3, i)

    ans = [gcd1, gcd2, gcd3]
    ans.sort()
    
    print(ans[-1])

Submission status: Runtime Error

Solution code:
import numpy as np

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

ans = 0
for i in range(N) :
    B = A[np.arange(len(A))!=i]
    g = gcd_mul(B)
    if g > ans :
        ans = g
print(ans)

Submission status: Runtime Error

Solution code:
def gcd(p,q):
  while q!=0:
    p,q=q,p%q
  return p

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

b=a[0]
if n>=3:
  c=gcd(a[0],a[2])
d=a[1]
for i in range(n-1):
  b=gcd(b,a[i+1])
if n>=4:
  for i in range(n-3):
    c=gcd(c,a[i+3])
if n>=3:
  for i in range(n-2):
    d=gcd(d,a[i+2])
print(max(b,c,d))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys,math
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def dfs(res, flag, depth):
        if depth == N:
            return res
        if flag:
            return dfs(math.gcd(res, A[depth]), True, depth + 1)
        else:
            return max( dfs(res, True, depth + 1), dfs(math.gcd(res, A[depth]), False, depth + 1))

    N = int(lines.pop(0))
    A = list(map(int, lines.pop(0).split(' ')))
    print(dfs(0, False, 0) )
lines = [x.strip() for x in sys.stdin.readlines()]
solve(lines)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

for i in range(n):
    aa = a[:]
    aa.pop(i)
    L[i] = reduce(math.gcd, aa)

print(max(L))

Submission status: Runtime Error

Solution code:
import numpy as np

def wa(rist, num):
  R = []
  for j in range(len(rist)):
    R.append(rist[j] // num)
  c = [i for i in R if i == 0]
  if len(c) <= 1:
    return 0
  else:
    return 1
    

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

num = 0

for i in range(np.max(A)):
  me = wa(A, i)
  if me == 0:
    num = i
  else:
    pass
  
print(num)

Submission status: Runtime Error

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

a = list(set(a))

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


if n <= 2:
    print(max(a))
else:
    a.sort()
    ans = max(gcd(a[0], a[-1]), gcd(a[1], a[-1]), gcd(a[0], a[-2]))
    print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

ans = []
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
for i in range(N):
  ans.append(gcd_list(A[i+1:]+A[:i]))
  
ans.sort()
print(ans[-1])

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

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

for i in range(n):
    a_tmp = a[:]
    del a_tmp[i]
    temp = gcd_list(a_tmp)
    if temp > ans:
        ans = temp

print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import functools
import math

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

max_gcd = -float('inf')

for v in itertools.permutations(list,N-1):
    max_gcd = max(functools.reduce(math.gcd,v),max_gcd)

print(max_gcd)

Submission status: Runtime Error

Solution code:
from math import gcd
n = int(input())
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll rui[222222];
ll rui2[222222];
ll gcd(ll a,ll b){
    ll r=a%b; 
    while(r!=0){a=b;b=r;r=a%b;}
    return b;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n);
  for(int i=0;i<n;i++){
    cin>>A[i];
    if(i==0)rui[i]=A[i];
    else rui[i]=gcd(rui[i-1],A[i]);
    if(i==n-1)rui2[i]=A[i];
  }
  ll ans=0;
  for(int i=n-2;i>=0;i--)
    rui2[i]=gcd(rui2[i+1],A[i]);
  for(int i=0;i<n;i++){
    if(i==0){
      // cout<<rui[i+1]<<endl;
      ans=max(ans,rui2[i+1]);
    }else if(i==n-1){
      //cout<<rui[i-1]<<endl;
      ans=max(ans,rui[i-1]);
    }else{
      //cout<<gcd(rui[i-1],rui2[i+1])<<endl;
      ans=max(ans,gcd(rui[i-1],rui2[i+1]));
    }
  }
  cout<<ans<<endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
import math

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

gcd1=math.gcd(A[0],A[-1])
gcd2=math.gcd(A[0],A[1])
ans=max(gcd1,gcd2)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
from collections import deque

N = int(input())
As = [int(i) for i in input().split()]
As = np.array(As, dtype=int)

def full_gcd(nums):
  que = deque(nums)
  while que:
    if len(que) == 1:
      return que.pop()
    
    num0 = que.popleft()
    num1 = que.popleft()
    topgcd = math.gcd(num0, num1)
    
    que.appendleft(topgcd)

maxgcd = -1
for i in range(len(As)):
  mask = np.ones(len(As), dtype=bool)
  mask[i] = False
  newAs = As[mask]
  
  maxgcd = max(maxgcd, full_gcd(newAs))
  
print(maxgcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

gcdA = [0 for i in range(N)]
for i in range(N):
    A_=A.copy()
    A_.pop(i)
    gcdA[i] = gcd(A_)

print(max(gcdA))

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce

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

N=int(input())

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

out=0

for i in range(N):
    t=copy.copy(A)
    t.pop(i)
    out=max(out,gcd(t))

print(out)

Submission status: Runtime Error

Solution code:
import copy
import math


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    gcd_list = []
    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(math.gcd(gcd, num_list.pop()), num_list)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:

import math


def kari():
    a = list(map(int, input().split()))
    b = map(int, input().split())


def start_process(num, data):
    kouyakusuu1, kouyakusuu2, kouyakusuu3 = math.gcd(data[0], data[1]), max(data[0], data[1]), min(data[0], data[1])
    # print(kouyakusuu2, kouyakusuu3)

    for i in range(2, num):
        if i == 2:
            a = math.gcd(data[i], kouyakusuu2)
            b = math.gcd(data[i], kouyakusuu3)
            kari1 = max(a, b)
            kari2 = kouyakusuu1

            kari3 = math.gcd(data[i], kouyakusuu1)
        else:
            kari1 = math.gcd(data[i], kouyakusuu2)
            kari2 = kouyakusuu1

            kari3 = math.gcd(data[i], kouyakusuu1)



        kouyakusuu1 = kari3
        kouyakusuu2 = max(kari1, kari2)



    print(max(kouyakusuu1, kouyakusuu2))

# def start_process(num, data):
#     for i in range(num)

def main():
    num = int(input())
    data = list(map(int, input().split()))
    start_process(num, data)



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys,math
from functools import reduce
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def dfs(res, flag, depth):
        if depth == N:
            return res
        if flag:
            return dfs(math.gcd(res, A[depth]), True, depth + 1)
        else:
            return max( dfs(res, True, depth + 1), dfs(math.gcd(res, A[depth]), False, depth + 1))

    N = int(lines.pop(0))
    A = list(map(int, lines.pop(0).split(' ')))
    print(dfs(0, False, 0) )
lines = [x.strip() for x in sys.stdin.readlines()]
solve(lines)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a = input()
l = map(int, raw_input().split())

def gcd(l):
	m = max(l)
	r = 0
	for i in range(1, m + 1):
		f = 0
		for j in l:
			if j % i != 0:
				f += 1
			if f > 1:
				break
		if f <= 1:
			r = i
	return r 

print gcd(l)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


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


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


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

max = 0

for i in range(n):
    j = a.pop(0)
    if max < gcd_list(a):
        max = gcd_list(a)
    a.append(j)

print(max)

Submission status: Runtime Error

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

import fraction
from functools import reduce

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

dp=[]
for i in range(n):
    aa=list(a)
    del aa[i]
    dp.append(gcd(*aa))

print(max(dp))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
s=[[0]for _ in range(n)]
#print(s)

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):
    if i==0:
        s[0]=l[1:]
    
    else:
        s[i]=l[:i]+l[i+1:]
ans=1
for i in s:
    ans=max(gcd_list(i),ans)
print(ans)

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

if N <= 2:
    print(max[A])
else:
    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:
def ans():
  N = int(input())
  A = list(map(int,input().split()))

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

  res = set()
  x = min(A)
  for i in range(N):
    res.add(gcd(A[i], x))

  b = A[0]
  for a in A[1:]:
    b = gcd(a, b)
  print(list(res)[b-1])
ans()

Submission status: Runtime Error

Solution code:
import fractions
import sys

sys.setrecursionlimit(1000000)

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

g_list = []

if len(l) == 2:
  g_list.append(max(l[0],l[1]))
  
else:
    g = fractions.gcd(l[1],l[2])
    for j in range(3,N):
        if j != i:
            g = fractions.gcd(g,l[j])
    g_list.append(g)

    g = fractions.gcd(l[0],l[2])
    for j in range(3,N):
        if j != i:
            g = fractions.gcd(g,l[j])
    g_list.append(g)

    for i in range(N):
        g = fractions.gcd(l[0],l[1])
        for j in range(N):
            if j != i:
                g = fractions.gcd(g,l[j])
        g_list.append(g)

print(max(g_list))

Submission status: Runtime Error

Solution code:
import copy
import math
from functools import reduce

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

gcd_list = []

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

for i in range(len(A)):
    tmp = copy.copy(A)
    del tmp[i]
    gcd_list.append(gcd(*tmp))

print(max(gcd_list))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


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


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap



@mt
def slv(N, A):
  
    ans = 0
    for i in range(N):
        cand = A[0] if i != 0 else A[1]
        for j, a in enumerate(A):
            if i == j:
                continue
            cand = math.gcd(cand, a)
            if cand <= ans:
                break
        ans = max(ans, cand)
        
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))

    # N  = 10**5
    # A = [10**9] * N
    # print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
a=list(map(int, input().split()))
import math
x=math.gcd(a[0], a[n-1])
y=math.gcd(a[0], a[n-2])
if n==2:
	x=max(a)
print(max(x, y))

Submission status: Runtime Error

Solution code:
# coding:utf-8
import functools
import math


def main():
    N = int(input())
    num = list(map(int, input().split()))
    # num.sort()
    # print(num)
    # print(num[0:0])
    gcd = 0
    for i in range(len(num)):
        temp_list = num[0:i]+num[i+1:]
        temp_gcd = functools.reduce(math.gcd, temp_list)
        if temp_gcd > gcd:
            gcd = temp_gcd
    print(gcd)
    # ans = 0
    # print()


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
memo = {}

def gcd(a, b):
    if (a, b) in memo.keys():
        return memo.get[(a, b)]
    if b == 0:
        return a
    return gcd(b, a % b)

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