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
from collections import Counter as ct
from functools import reduce

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

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

def yakusulist(n):
    ans=[]
    for i in range(1,int(math.sqrt(n+1))+1):
        if n%i==0:
            ans.append(i)
            ans.append(n//i)
    return(set(ans))
    
def warennnokaomaera(n):
    if n==1:return(True)
    for k,i in enumerate(A):
        if k<3:continue
        if i%n:return(False)
    return(True)

N=int(input())
data=[int(i) for i in input().split()]
datagcd=gcd_list(data)
A=[i//datagcd for i in data]
if N>2:
    alpha=sorted(ct(A).keys())
    min3=[alpha[0],alpha[1],alpha[2]]
    p,q,r=[yakusulist(n) for n in min3]
    pq=p&q
    qr=q&r
    rp=r&p
    overtwo=pq|qr|rp
    overtwo=sorted(list(overtwo),reverse=True)
    for i in overtwo:
        if warennnokaomaera(i):
            print(datagcd*i)
            break
else:print(max(data))

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
from functools import reduce
from fractions import gcd
tmp=[]
for i in range(N):
    A.remove(i)
    tmp.append(reduce(gcd,A))
print(max(tmp))

Submission status: Runtime Error

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

def solve(lines):
    def dfs(res, flag, depth):
        if depth == N:
            return res
        if flag:
            return dfs(fraction.gcd(res, A[depth]), True, depth + 1)
        else:
            return max( dfs(res, True, depth + 1), dfs(fraction.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())
A = [int(i) for i in input().split()]

if N == 2:
    if A[0] > A[1]:
        print(A[0])
    else:
        print(A[1])
else:
    gcd_max = 0
    for i in range(N):
        if i != 0:
            gcd = A[0]
        else:
            gcd = A[1]
        for j in range(N):
            if j != i:
                gcd = math.gcd(gcd, A[j])
        if gcd_max < gcd:
            gcd_max = gcd
    print(gcd_max)

Submission status: Runtime Error

Solution code:
3
7 6 8

Submission status: Runtime Error

Solution code:
import math
import sys
import collections
from functools import reduce

def gcd_list(numbers):
    return reduce(math.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()
    return divisors
    
 
N = int(sys.stdin.readline())
A = sys.stdin.readline().strip().split()
A = list(map(int, A))
#print(A)


if(N==2):
    print(max(A))
else:
    A_d = []
    for i in range(N):
        #d = make_divisors(A[i])
        A_d.append(make_divisors(A[i]))
    #print(A_d)
    A_d = [flatten for inner in A_d for flatten in inner]
#    print(A_d)
    
    c = collections.Counter(A_d)
#    print(c)
#    print(c.most_common(4))
    
#    print(c.most_common()[1][0])
    f=1
    i=0
    ans=0
    while(f==1):
#        print(i," common=",c.most_common()[i][1])
        if(c.most_common()[i][1]==N-1):
           ans = c.most_common()[i][0]
        elif(c.most_common()[i][1] < N-1):
           f=0
        i+=1
    print(ans)

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(x, y):
    while y:
        x, y = y, x % y
    return x


def gcd_list(li):
    g = gcd(li[0], li[1])
    for i in range(2, len(li)):
        g = gcd(g, li[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, li[i]) == 1:
            return gcd_list([g] + li[i + 1:])
        else:
            g = gcd(g, li[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
from functools import reduce


def main():

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

    maxd = 1
    for n in range(N):
        l = A[:n] + A[n+1:]
        maxd = max(maxd, gcd(*l))

    print(maxd)    


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


main()

Submission status: Runtime Error

Solution code:
import math
#最大公約数gcd
N = int(input())
A = list(map(int, input().split()))



ans = 1

for index in range(N-1):
    
    
    if ans < math.gcd(A[index], A[index +1]):
        ans = math.gcd(A[index], A[index +1])
    
print(ans)

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce
n=int(input())
num=list(map(int,input().split()))

def hcfnaive(a,b): 
  if(b==0): 
    return a 
  else: 
    return hcfnaive(b,a%b) 
      
def gcd(numbers):
  if len(numbers)==2:
    return hcfnaive(numbers[0],numbers[1])
  elif len(numbers)==1:
    return numbers[0]
  else:
    numbers[0]=hcfnaive(numbers[0],numbers[1])
    numbers.pop(1)
  return gcd(numbers)

ans=0
for i in range(n):
  num2=copy.copy(num)
  num2.pop(i)
  ab=gcd(num2)
  if ab>ans:
    ans=ab
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

left_gcd = [0]
right_gcd = [0]

for i in range(n):
    left_gcd.append(math.gcd(left_gcd[-1], a[i]))
    right_gcd.insert(0, math.gcd(right_gcd[0], a[(n - 1) - i]))

max_gcd = 0

for i in range(n):
    gcd = math.gcd(left_gcd[i], right_gcd[i + 1])
    if gcd > max_gcd:
        max_gcd = gcd

print(max_gcd)

Submission status: Runtime Error

Solution code:
from sys import stdin
import fractions
 
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
 
res = []
 
for i in range(N):
    B = A[:]
    del B[i]
    B.sort()

    gcd_num = fractions.gcd(B[0], B[1])

    res.append(gcd_num)

 
print(max(res))

Submission status: Runtime Error

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

def maxgcd(A,N):
    B=[]
    max = 1
    for i in range(N):
        if len(A) == 2:
            if A[0] > A[1]:
                temp = gcd(A[0],A[1])
            else:
                temp = gcd(A[1],A[0])
        else:
            B = copy.copy(A)
            B.pop(i)
            temp = maxgcd(B,N-1)
        if max < temp:
            max = temp
    return max
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

print(maxgcd(A,N))

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-3}
  
  
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
def main():
    N = int(input())
    A = [int(n) for n in input().split()]
    fore = [0]*N
    back=[0]*N
    fore[0] = A[0]
    back[-1] = A[-1]
    for i in range(1, N):
        fore[i] = math.gcd(fore[i-1], A[i])
    for i in reversed(list(range(0, N-1))):
        back[i] = math.gcd(back[i+1], A[i])
    maximum = 0
    for i in range(N):
        f = fore[i-1] if i != 0 else 0
        b = back[i+1] if i != N-1 else 0
        m = math.gcd(f, b)
        maximum = max(m, maximum)
    print(maximum)
main()

Submission status: Runtime Error

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

def gcd_list(numbers):
    return reduce(fractions.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 numpy as np
import math

_ = input()
a = np.array([int(x) for x in input().split(" ")])

if len(a) == 2:
    print(math.gcd(*a))
    exit()

list = [math.gcd(a[2], a[1]), math.gcd(a[0], a[2]), math.gcd(a[0], a[1])]
gcd = np.max(list)
bad_num = a[np.argmax(list)]

for i in range(3, len(a)):
    if a[i] % gcd == 0:
        continue
    else:
        newgcd = math.gcd(a[i], gcd)
        oldgcd = math.gcd(bad_num, gcd)

        if newgcd > oldgcd:
            gcd = newgcd
        else:
            gcd = oldgcd
            bad_num = a[i]

        if gcd == 1:
            print(1)
            exit()

print(gcd)

Submission status: Runtime Error

Solution code:
import copy

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

result = 0

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

def gcd_list(nums):
    x = gcd(nums[0],nums[1])
    for i in range(2,len(nums)):
        x = 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 math

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

for i in range(n-1):
    for j in range(n-1):
        g = a[0]
        if j != i:
            g = math.gcd(g, a[j+1])
            glist.append(g)
for i in range(n-2):
    g = a[1]
    g = math.gcd(g, a[i+2])
    glist.append(g)
for i in range(n-1):
    g = a[0]
    g = math.gcd(g, a[i+1])
    glist.append(g)
print(max(glist))

Submission status: Runtime Error

Solution code:
import math
n = int(input())
listA = list(map(int, input().split()))
listA.sort()
if len(listA) < 3:
    print(max(listA))
else:
    minGcd1 = math.gcd(listA[0], listA[1])
    minGcd2 = math.gcd(listA[1], listA[2])
    minGcd3 = math.gcd(listA[0], listA[2])
    ming1 = minGcd1
    maxg1 = 1
    while ming1 > 1:
        count=0
        flag=0
        index1=0
        while index1 < len(listA):
            if listA[index1]%ming1==0:
                pass
            else:
                count+=1
            if count >1:
                flag=1
                break
            index1+=1
        if flag:
            ming1-=1
        else:
            maxg1 = ming1
            break
    ming2 = minGcd2
    maxg2 = 1
    while ming2 > 1:
        count = 0
        flag = 0
        index1 = 0
        while index1 < len(listA):
            if listA[index1] % ming2==0:
                pass
            else:
                count += 1
            if count > 1:
                flag = 1
                break
            index1 += 1
        if flag:
            ming2 -= 1
        else:
            maxg2 = ming2
            break
    ming3 = minGcd3
    maxg3= 1
    while ming3 > 1:
        count = 0
        flag = 0
        index1 = 0
        while index1 < len(listA):
            if listA[index1] % ming3==0:
                pass
            else:
                count += 1
            if count > 1:
                flag = 1
                break
            index1 += 1
        if flag:
            ming3 -= 1
        else:
            maxg3 = ming3

            break
    print(max(maxg1, maxg2, maxg3))

Submission status: Runtime Error

Solution code:
import numpy as np
import fraction
import sys

n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
m=[]
m.append(fraction.gcd(a[0],a[1]))
if(n==2):
    print(m[0])
    sys.exit()
t=-1
for i in range(2,a[-1]+1):
    t=np.argmax(np.mod(np.array(a),i))
    if(t!=0 and t!=-1):
        a.pop(t)
        break

s=fraction.gcd(a[0],a[1])
for i in range(2,len(a[1:])):
    s=fraction.gcd(s,a[i])
print(s)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)
n = int(input())
A = input().split()
m = [int(a) for a in A]
ans = 0
for i in range(n):
    B = m[:]
    B.pop(i)
    gcm = gcd(B[0], B[1])
    cand = gcm
    for j in range(len(B)-2):
        cand = gcd(B[j+2], gcm)
    if cand > ans:
        ans = cand
print(ans)

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);
    /*REP(i,N){
        cout << B[i] << " ";
    }*/
    int s=0;
    REP(i,N){
        if(B[i]!=0){
            s=i;
            break;
        }
    }
    B[s]+=B[s+1];
    B[s+1]=B[s];
    int Ans=B[N-1];
    REP(i,N){
        if(B[i]!=0){
            Ans=gcd(Ans,B[i]);
        }
    }
    cout << Ans << endl;
    return 0;
}

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
i = 0
for i in range(N):
    p = A.pop(i)
    c = gcd_list(A)
    if c > max:
        max = c
    A.insert(i, p)

print(max)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math
from functools import reduce
import copy

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

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

numNum = int(input())
setOfNumOrg = input().split()
setOfNum = [int(i) for i in setOfNumOrg]

ans = 0
#二つの場合
if numNum == 2:
    ans = max(setOfNum)
else:
#一つづつ順に欠損させていきそのなかの最大に合わせればいい
    for i in range(numNum):
        copyData = copy.copy(setOfNum)
        del copyData[i]
        if gcd(*copyData) > ans:
            ans = gcd(*copyData)
print(ans)

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

if n == 2:
  gcdnum = max(numbers[0], numbers[1])
else:
  gcdnum = max(gcd(numbers[0], numbers[1]), gcd(numbers[0], numbers[2]), gcd(numbers[1], numbers[2]))
  for i in range(3, n):
    if gcd(gcdnum, number[i]) == 1:
      break
    else:
      gcdnum = gcd(gcdnum, number[i])
    
print(gcdnum)

Submission status: Runtime Error

Solution code:
from math import gcd
from itertools import accumulate

input()
a = list(map(int, input().split()))
b = list(accumulate(a, gcd))
c = list(accumulate(reversed(a), gcd))
print(max(b[-2], c[-2], *map(gcd, b[:-2], c[-3::-1])))

Submission status: Runtime Error

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

nums = A[:]
import math

gcd_queue = [
    (nums[0], True),
    (nums[1], True),
    (math.gcd(nums[0], nums[1]), False),
]
for n in nums[2:]:
    tmp_queue = []
    for q in gcd_queue:
        if q[1] == True:
            tmp_queue.append((math.gcd(q[0], n), True))
        else:
            tmp_queue.append((math.gcd(q[0], n), False))
            tmp_queue.append((q[0], True))
    gcd_queue = tmp_queue[:]
#print(gcd_queue)

ans = 0
for q in gcd_queue:
    ans = max(ans, q[0])
print(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()
    ac = collections.Counter(LI())
    a = []
    aa = []
    for k,v in ac.items():
        if v > 1:
            aa.append(k)
        else:
            a.append(k)

    tr = -1
    if len(aa) > 0:
        tr = aa[0]
        for k in aa[1:]:
            tr = fractions.gcd(k,tr)

    l = len(a)
    if l < 1:
        return tr
    if l < 3:
        r = 0
        return 1 / 0
        for i in a:
            kr = fractions.gcd(i,tr)
            if r < kr:
                r = kr
        return r

    m = max(a)
    lm = m
    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)
                    r.append(t)
        for k in r:
            p[k] += 1



    if tr == -1:
        r = 1
        for k,v in p.items():
            if v >= l-1 and r < k:
                r = k
        return r

    r = 1
    for k,v in p.items():
        kk = fractions.gcd(tr,k)
        if v >= l-1 and r < kk:
            r = kk

    return r


print(main())

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
import copy

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
  
n = int(input())
A = list(int(i) for i in (input().split()))

red_list = list(set(A))

ans = 0
tmp = 0
reduce_num = 0
for i in range(len(red_list)):
  if( i != 0): red_list.append(reduce_num)
  reduce_num = red_list.pop(0)
  tmp = gcd_list(red_list)
  if(ans < tmp):
    ans = tmp

print(ans)

Submission status: Runtime Error

Solution code:
import sys
def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    left = arr[:mid]
    right = arr[mid:]
    left = merge_sort(left)
    right = merge_sort(right)

    return merge(left, right)
def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged

n = int(input())
li = list(map(int,input().split()))
merge_sort(li)
ans = int(li[n - 1] - li[0])
if (li[0] == li[n - 1]):
    print(li[0])
    sys.exit()
if(((li[n - 1] % ans) == 0) and ((li[0] % ans) == 0)):
    print(ans)
    sys.exit()

if((li[1] % (li[n - 1] - li[1])) == 0):
    print(int(li[n - 1] - li[1]))
    sys.exit()
else:
    print((li[n - 2] -li[0]))

Submission status: Runtime Error

Solution code:
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
mem = {}
for i,_ in enumerate(A):
    A.pop(i)
    res = A[0]
    for i in A[1:]:
        str12 = "{}.{}".format(i,res)
        if str12 in mem.keys():
            res = mem[str12]
        else:
            res = gcd(res,i)
            mem[str12] = res
    max = res if res >= max else max
    A = list(a2)


print(max)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
import sys

n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
m=[]
m.append(math.gcd(a[0],a[1]))
if(n==2):
    print(m[0])
    sys.exit()
t=-1
for i in range(2,a[-1]+1):
    t=np.argmax(np.mod(np.array(a),i))
    if(t!=0 and t!=-1):
        a.pop(t)
        break

s=math.gcd(a[0],a[1])
for i in range(2,len(a[1:])):
    s=math.gcd(s,a[i])
print(s)

Submission status: Runtime Error

Solution code:
from sys import stdin
import fractions
from collections import deque
 
 
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
#A = deque(A)
 
res = []
 
for i in range(N):
    B = A[:]
    del B[i]
    B.sort()

    res.append(fractions.gcd(B[0], B[1]))

 
print(max(res))

Submission status: Runtime Error

Solution code:
import math, copy, sys
def gcd(list):
    if len(list) == 2:
        return math.gcd(list[0], list[1])
    else:
        return(gcd(list[0],list[1:]))
N = int(input())
A = sorted([int(x) for x in input().split()])
if N == 2:
    print(max(A[0], A[1]))
    sys.exit()
tmp = 0
for i in range(N):
    list = copy.copy(A)
    del list[i]
    if tmp < gcd(list):
        tmp = gcd(list)
print(tmp)

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 = [int(x) for x in input().split()]
list = []
max = 1

for x in range(N):

    for y in range(N):
        if x != y:
            list.append(A[y])

    gcd = gcd_list(list)
    if gcd > max:
        max = gcd

print(max)

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()))
math.gcd(2,4)

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]) < i:
      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
from functools import reduce
num=input()
list=list(map(int,input().split()))
pop_num=0
answer=[]
for x in range(len(list)):
    pop_num=list.pop(x)
    #print(list)
    answer.append(reduce(math.gcd,list))
    #print(answer)
    list=[pop_num]+list
answer.sort()
#print(answer)
print(answer[-1])

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce

N = int(input())
nums = [int(i) for i in input().split()]
nums2 = copy.copy(nums)
ans = []

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


for i in range(N):
   nums.pop(i)
   ans.append(gcds(nums))
   nums = copy.copy(nums2)

print(max(ans))

Submission status: Runtime Error

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

cm = np.prod(A)
max_gcd = 0
for i in range(len(A)):
    Am = A.copy()
    Am[i] = cm
    gcd = np.gcd.reduce(Am)
    if gcd > max_gcd:
        max_gcd = gcd
print(max_gcd)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(sys.getrecursionlimit())
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:
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


N = int(input())
AA = [int(i) for i in input().split()]
result = 1
for i in range(N):
    tmp1 = gcd_list(AA[:i]) 
    tmp2 = gcd_list(AA[:i+1])
    tmp3 = fractions.gcd(tmp1,tmp2)
    result = max(tmp3,result)
print(result)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

result = 0

n = int(input())
A = list(map(int, input().split()))
for i in range(n):
    result = max(result, reduce(math.gcd, A[:i]+A[i+1:]))

print(result)

Submission status: Runtime Error

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

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

maxt = 0
for i in range(n):
	b = a[0:i]
	b += (a[i+1:n])
	tmp = b[0]

	for bi in b[1::]:
		tmp = math.gcd(tmp,bi)
		
	if maxt < tmp:
		maxt = tmp
 
print (maxt)

Submission status: Runtime Error

Solution code:
import fractions

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

g_memo = {}

def my_gcd(i_list):
    global g_memo

    k = str(sorted(i_list))

    if k in g_memo.keys():
        return g_memo[k]

    if len(i_list) == 2:
        g_memo[k] = fractions.gcd(i_list[0], i_list[1])
        return g_memo[k]

    g_memo[k] = fractions.gcd(i_list[0], my_gcd(i_list[1:]))
    return g_memo[k]

if len(A) == 2:
    print(max(A))
else:
    max_gcd = 0
    for i in range(N):
        i_list = A[:i] + A[i+1:]
        gcd = my_gcd(i_list)
        if max_gcd < gcd:
            max_gcd = gcd

    print(max_gcd)

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 == 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 = 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:
import math

N = int( input() )
A = list( map( int ,input().split()) )
A.sort()
print(A)
ans = 1000000000
ansbuf = 0
index = 0
if len(A) >= 3:
    for lop in range(1,len(A)):
        buf = math.gcd(A[lop-1],A[lop])
        if ans > buf :
            index = lop
            ans = buf
    A[index] = A[0]
    ans = 1000000000
    for lop in range(1,len(A)):
        buf = math.gcd(A[lop-1],A[lop])
        if ans > buf :
            ans = buf
            
else:
    print(max(A))
print(ans)

Submission status: Runtime Error

Solution code:
import math
N =int(input())
a = input().split()
b=0
num=[]
test=[]
res=[]
for i in range(N):
  num.append(int(a[i]))
#a,bの最大公約数を求める
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
for j in range(N):
  test=num[:]
  if len(test) > 2:
    del test[j]
  else:
    res=[max(test)]
    break
  for i in range(N-1):
	  b = gcd(test[0],test[1])
	  b = gcd(b,test[i])
  res.append(b)

print(max(res))
for i in range(N):
#while k %= i:

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 = [int(x) for x in input().split()]
list = []
max = 1

for x in range(N):

    for y in range(N):
        if x != y:
            list.append(A[y])

    gcd = gcd_list(list)
    if gcd > max:
        max = gcd

print(max)

Submission status: Runtime Error

Solution code:
import math
import sys

def gcd2(array):
    gcd = math.gcd(array[0], array[1])
    for i in range(2, len(array)-1):
        gcd = math.gcd(gcd, array[i])
    return gcd


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:
#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:
        print(A[0])
        exit()
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))