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 fractions

N=int(input())
A=list(map(int, input().split()))
Z=0
ans=0
for i in range(N):
    if i==0:
        B=A.copy()
        B[0]=B[1]
        ans=fractions.gcd(B)


    else :
        B=A.copy()
        B[i]=B[0]
        Z=B[0]
        Z =fractions.gcd(B)


    if ans >Z:
        ans=ans
    else:
        ans=Z

print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
import copy
import math

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


gcds = []

for i in range(N):
    for x in set(integers):
        tmp_integers = copy.copy(integers)
        tmp_integers[i] = x
        gcds.append(reduce(math.gcd, tmp_integers))
print(max(gcds))

Submission status: Runtime Error

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


import math
from functools import reduce

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

res = 0
for i in range(n):
    a = x.copy()
    b = a.pop(i)
    c = gcd_list(a)

    d = x.copy()
    d[i] = c
    if  res < gcd_list(d):
        res = gcd_list(d)
print(res)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
#C
import numpy as np
import math
import re
import functools
def gcd_list(numbers):
    return functools.reduce(math.gcd, numbers)

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

m = 0
for i in range(n):
    s = []
    for j in range(n):
        if j != i:
            s.append(a[j])
    x = gcd_list(s)
    if(x > m):
        m = x
print(m)

Submission status: Runtime Error

Solution code:
# GCD
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x

# struct
class struct:
  def __init__(self,a,b,c):
    self.a=a
    self.b=b
    self.c=c

n=int(input())
if n==2:
  a,b=map(int,input().split())
  print(max(a,b))
  exit()
elif n==3:
  a,b,c=map(int,input().split())
  print(max(gcd(a,b),gcd(a,c),gcd(b,c)))
  exit()
else:
  l=list(map(int,input().split()))
  a=l[0]
  b=l[1]
  c=l[2]
  d=l[3]
  l2=[]
  l2.append(struct(a,b,gcd(a,b)))
  l2.append(struct(a,c,gcd(a,c)))
  l2.append(struct(a,d,gcd(a,d)))
  l2.append(struct(b,c,gcd(b,c)))
  l2.append(struct(b,d,gcd(b,d)))
  l2.append(struct(c,d,gcd(c,d)))
  l2=sorted(l2,key=lambda x:(x.c,x.a,x.b))
  aa=l2[0].a
  l3=[l2[0].c,l2[1].c,l2[2].c,l2[3].c,l2[4].c,l2[5].c]
  l3=list(set(l3))
  bb=l3[1]
  for x in l:
    xx=gcd(bb,x)
    yy=gcd(bb,aa)
    if xx<yy:
      aa=x
      bb=yy
  print(bb)

Submission status: Runtime Error

Solution code:
import itertools
from math import gcd

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

comb_list = itertools.permutations(a_list, n-1)
max_yaku = 0
if len(a_list) is 2:
    max_yaku = gcd(a_list[0], a_list[1])
else:
    for i in comb_list:
        a = i[0]
        for j in range(1, len(i)):
            yaku = gcd(a, i[j])
            a = i[j]
        if max_yaku < yaku:
            max_yaku = yaku

print(max_yaku)

Submission status: Runtime Error

Solution code:
import fractions
import itertools

def gcd_list(list_,n):
  if n == len(list_)-2:
    return fractions.gcd(list_[n],list_[n+1])
  gcd_max = fractions.gcd(list_[n],gcd_list(list_,n+1))
  return gcd_max

N = int(input())
A_ = list(map(int,input().split()))
A_list = itertools.combinations(A_,N-1)
gcd_max = 0
if N > 2:
  for i in A_list:
    tmp = gcd_list(i,0)
    if gcd_max < tmp:
      gcd_max = tmp
else:
  gcd_max = max(A_)
print(gcd_max)

Submission status: Runtime Error

Solution code:
import math

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

GCD = []
for i in range(N):
    temp = 0
    for j in range(N):
        if i != j:
            temp = math.gcd(temp, A[j])
    GCD.append(temp)

print(max(GCD))

Submission status: Runtime Error

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

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

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

res = 0
for i in range(n):
    res = max(gcd(pre[i], post[n - 1 - i]), res)

print(res)

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce

n = int(input())
A = list(map(int, input().split()))
maxGcd = 0

for i in range(n):
    g = reduce(lambda a, b: gcd(a, b), A[:i]+A[i+1:])
    maxGcd = max(maxGcd, g)

print(maxGcd)

Submission status: Runtime Error

Solution code:
import sys
import os
import math
import fractions
from functools import reduce
from fractions import gcd

def test(x,k,m):
    #print("i=",k)
    tmp=[0]*len(x)
    for j in range(m):
        tmp[j]=x[j]
    #print('a=',x)
    #print('tmp=',tmp)
    del tmp[k]
    #print('tmp=',tmp)
    #print("a==",x)
    XX=gcd(*tmp)
    ans=0
    for aa in range(len(tmp)):
        ans = fractions.gcd(ans, tmp[aa])
    #print("XX=",XX)
    return ans

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

yakusu=[0]*len(a)
for i in range(n):
    yakusu[i]=test(a,i,n)

ans=max(yakusu)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

def list_primes(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

prime_list = list_primes(max(As))
max_prime = 0
max_prime_n = 0
for n,i in enumerate(prime_list):
    max_prime_now = max(list(map( lambda x: i if x % i == 0 else 0, As)))
    if max_prime_now > max_prime:
        max_prime = max_prime_now
        max_prime_n = n
As_np = np.array(As)
As_np[As_np%max_prime==0]=max(As_np)

sigma = 1
len_As = len(As_np)
for i in reversed(range(2,max(As_np)+1)):
    if (As_np % i).sum()==0:
        As_np = As_np/i
        sigma *= i

print(sigma)

Submission status: Runtime Error

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

def solve(lines):
    def dfs(res, flag, depth):
        if depth == N:
            return res
        if flag:
            return dfs(fractions.gcd(res, A[depth]), True, depth + 1)
        else:
            return max( dfs(res, True, depth + 1), dfs(fractions.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 functools
import math

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

A.sort()
ans = 1

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

print(ans)

Submission status: Runtime Error

Solution code:
import math
import numpy as np

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

ans=0
for i in range(n):
    b=np.array([x for x in a if not x==a[i]])
    for j in range(n-2):
        d=math.gcd(b[0],b[1])
        b=np.delete(b,0)
        b[0]=d
    c=b[0]
    if ans<c: ans=c
print(ans)

Submission status: Runtime Error

Solution code:
import math
import os
import random
import re
import sys
from collections import defaultdict

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

def gcd_list(n, a):
    A = a[0:n] + a[n+1:]
    gcd0 = gcd(A[0], A[1])
    for i in range(2, n-1):
        gcd0 = gcd(gcd0, A[i])

    return gcd0


def solve(n, a):
    if n < 1:
        return 0
    if n == 1:
        return a[0]
    if n == 2:
        return gcd(a[0], a[1])

    dp = [False for _ in range(10001)]

    gcd0 = gcd(a[0], a[1])
    dp[gcd0] = True
    gcd1 = gcd(gcd0, a[2])
    if gcd1 == gcd0:
        zero = gcd(a[1], a[2])
        one = gcd(a[0], a[2])
        if zero > one:
            dp[zero] = True
            gcd0 = zero
        else:
            dp[one] = True
            gcd0 = one
    dp[gcd0] = True
    for i in range(1,n):
        gcd0 = gcd(gcd0, a[i])
        dp[gcd0] = True

    count = 0
    start = 0
    for i in range(len(dp)):
        if dp[i] == True:
            start = i
            break
    if start == len(dp):
        return start
    for i in range(start+1, len(dp)):
        if dp[i] == True:
            return i
    return start

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    print(solve(n,a))

Submission status: Runtime Error

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

def mygcd(A):
    if len(A) == 1:
        return A[0]
    else:
        return fractions.gcd(A[0],mygcd(A[1:]))
        
ans = []
for i in range(N):
    ans.append(mygcd(A[:i]+A[i+1:]))

print(max(ans))

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

Submission status: Runtime Error

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

ans = []

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

def gcd_list(numbers):
    element = gcd(numbers[0], numbers[1])
    if len(numberes)==2:
        return element
    else:
        for i in range(2, len(numbers)):
            element=gcd(element, numbers[i])
        return element

if n == 2:
    print(max(a))
else:
    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 = list(map(int, input().split()))
s = set()
m = []
for i in range(N):
  l = []
  for j in range(1,A[i]):
    if A[i] % j == 0:
      l.append(j)
  if len(m) == 0:
    m.append(max(l))
  for i in l:
    if i in m:
      m.append(i)
print(max(m))

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):
    if len(li) == 1:
        return li[0]
    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:
            gg = gcd_list(li[i+1:])
            bb = [gcd(li[x], gg) for x in range(i+1)]
            bb.sort()
            return bb[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:
n=int(input())
x=list(map(int,input().split()))
S=max(x)
v=0
w=[]
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)
for j in range(n):
  c=x[j]
  if x[j]==S:
    x.pop(j)
    v=1
  else:
    x[j]=S
  if n==1:
    print(x[0])
  else:
    if n==2 and x[0]==S or x[1]==S:
      print(S)
    else:
      element = gcd(x[0], x[1])
    if n==2:
      w.append(element)
    else:
      for i in range(2,len(x)):
          element=gcd(element,x[i])
      w.append(element)
      print(element,x)
  if v==1:
    x.insert(i,S)
    v=0
  else:
    x[j]=c
print(max(w))

Submission status: Runtime Error

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

maxAns = max(A)

Ans = 1

# ゴリおす。最小のAから1ずつ減らして、割り切れなかったAが1個以下だったらそこが解答

l = range(10)

for i in range(maxAns - 1):
    acount = 0
    for Ai in A:
        if Ai % (maxAns - i) != 0:
            acount += 1
    # 割り切れなかった回数を数える
    if acount <= 1:
        Ans = maxAns - i
        break

print(Ans)

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 = [int(x) for x in input().split()]
As = []
for i in A:
    if(not i in As):
        As+=[i]
As.sort()
cand = -1
mingcd = gcd_list(As)
typ = -1
if(N==2):
    print(max(As))
else:
    for i in range(len(As)-1):
        if(mingcd==gcd(As[i],As[i+1])):
            if(i<N-2):
                if(mingcd==gcd(As[i],As[i+2])):
                    cand = i
                else:
                    cand = i+1
                break
            else:
                cand = i+1
    if(cand==-1):
        cand = len(As)-1
    print(gcd_list(As[:cand]+As[cand+1:]))

Submission status: Runtime Error

Solution code:
def gcd(x,y):
    if y == 0:
        #print(x)
        return x
    else:
        return gcd(y, x%y)

# def lcm(x,y):
#     return x/gcd(x,y)*y
#ans=1

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)
    k=len(li)
    for j in range(1,k):
        ans=gcd(li[j-1],li[j])
        #print(ans)
    #print('hoge')
    num_li.append(ans)
    li.insert(i,b)

print(int(max(num_li)))

Submission status: Runtime Error

Solution code:
#ABC125C
import math
import copy
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
ans = -1
for i in range(N):
    tmp = copy.copy(A)
    ans += max(reduce(math.gcd, tmp.pop(i)), ans)
print(ans)

Submission status: Runtime Error

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

#　書き換える前GCD
gcd_min, idnex_min = 0, 0
G = []
gcd_max = 0
for i in range(N):
    row = []
    for j in range(i):
        if i==j:
            row.append(A[j])
        else:
            val = gcd(A[i], A[j])
            row.append(val)
            if val > gcd_max:
                gcd_max = val
    for j in range(N-i):
        row.append(0)
    G.append(row)
    # pprint.pprint(G)

# pprint.pprint(G)
# print(gcd_min)
# Replace
import copy
bn = []
for i in range(N):
    vmin = 0
    for j in range(N):
        if G[j][i] != 0 and G[j][i] > vmin:
            vmin = G[j][i]
    bn.append(copy.copy(vmin))
# print(bn)

bn.sort()
cnt = 0
for i in range(N):
    if bn[i] != 0:
        print(bn[i+1])
        break

Submission status: Runtime Error

Solution code:
import math

def calc_odd(n):
    if(n % 2 != 0):
        return True
    else:
        return False

N = int(input())
A = [int(i) for i in input().split()]
index_min = A.index(min(A))
index_max = A.index(max(A))
check_odd = list(map(calc_odd,A))
answer = 0

if(check_odd.count(True) == 1):
    index_odd = check_odd.index(True)
    A[index_odd] = max(A)
    answer = A[0]
    for i in range(1, N):
        answer = math.gcd(answer, A[i])
else:
    A[index_min] = A[index_max]
    answer = A[0]
    for i in range(1, N):
        answer = math.gcd(answer, A[i])
print(answer)

Submission status: Runtime Error

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

def gcd(a,b):
    

def mygcd(A):
    if len(A) == 1:
        return A[0]
    else:
        return fractions.gcd(A[0],mygcd(A[1:]))
        
ans = []
for i in range(N):
    ans.append(mygcd(A[:i]+A[i+1:]))

print(max(ans))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math
from functools import reduce

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


m = 1
for i in range(N):
    a = A.pop(0)
    g = reduce(math.gcd, A)
    if m < g:
        m = g
    A.append(a)

print(m)

Submission status: Runtime Error

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

# def lcm(x,y):
#     return x/gcd(x,y)*y
#ans=1

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)
    k=len(li)
    for j in range(1,k):
        ans=gcd(li[j-1],li[j])
        print(ans)
    print('hoge')
    num_li.append(ans)
    li.insert(i,b)

print(int(max(num_li)))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
#C
import numpy as np
import math
import re
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
print(gcd_list([1]))
n = int(input())
a = input()
a = re.split(" ",a)
a = list(map(int,a))

m = 0
for i in range(n):
    s = []
    for j in range(n):
        if j != i:
            s.append(a[j])
    x = gcd_list(s)
    if(x > m):
        m = x
print(m)

Submission status: Runtime Error

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

x = []
if N > 2:
    for n, m in [tuple(A[0:2]), tuple(A[1:3]), (A[0], A[2])]: 
        while n != 0:
            l = n
            n = m % n
            m = l
        x.append(m)
    x.sort(reverse=True)
else:
    x.append(A[-1])

y = x.pop(0)
while True:
    tmp = A % y
    if sum(tmp != 0) < 2:
        break
    for i in range(2, y):
        if y % i == 0:
            y = y / i
            break
    if x[0] > y:
        x.append(y)
        y = x.pop(0)
        x.sort(reverse=True)

print(y)

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)
    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-1}
  
  
N = int(input())
A= list(map(int, input().split()))
pri_flag = True

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}

if len(A) > 4:
  for i,num in enumerate(A[3:]):
      if len(kouho) == 1:
          print(1)
          pri_flag = False
          break
      kouho = check(num, kouho, N, i+3)
    
if pri_flag:
    print(max(kouho))

Submission status: Runtime Error

Solution code:
n = int(input())
num_list = list(map(int, input().split()))
num_unique = list(set(num_list))
num_unique.sort()
num_unique.reverse()
max_num = 0
flag = False
for i in range(num_unique[-2], 0, -1):
    if flag and count < 2:
        break
    elif i == 1:
        max_num = 1
        break
    else:
        flag = True
        count = 0
        max_num = i
    for num in num_unique:
        if int(num / max_num) < 1 or num % max_num != 0:
            count += 1
            if count > 1:
                break
print(max_num)

Submission status: Runtime Error

Solution code:
from sympy import isprime
import math

def calc_odd(n):
    if(n % 2 != 0):
        return True
    else:
        return False

N = int(input())
A = [int(i) for i in input().split()]
index_min = A.index(min(A))
index_max = A.index(max(A))
check_odd = list(map(calc_odd,A))
answer = 0

if(check_odd.count(True) == 1):
    index_odd = check_odd.index(True)
    A[index_odd] = max(A)
    answer = A[0]
    for i in range(1, N):
        answer = math.gcd(answer, A[i])
else:
    A[index_min] = A[index_max]
    answer = A[0]
    for i in range(1, N):
        answer = math.gcd(answer, A[i])
print(answer)

Submission status: Runtime Error

Solution code:
import math

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


def gcd_list(numbers):
    if len(numbers) == 1:
        return numbers[0]
    element = math.gcd(numbers[0], numbers[1])
    if len(numbers) == 2:
        return element
    del numbers[:2]
    numbers.append(element)
    gcd_list(numbers)


tmp = 0
gcd_max = 0
for n in range(N):
    tmp = A[n]
    A.remove(A[n])
    gcd = gcd_list(A)
    if gcd >= gcd_max:
        gcd_max = gcd

    A.insert(n, tmp)

print(gcd_max)

Submission status: Runtime Error

Solution code:
import math
import copy
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.deepcopy(num)
  num2.pop(i)
  ab=gcd(num2)
  if ab>ans:
    ans=ab
print(ab)

Submission status: Runtime Error

Solution code:
N  = int(input())

A_list_str = input().split()
A_list_int = list(map(int,A_list_str))

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

def gcd_list(n,numbers):
    KS = gcd(numbers[0],numbers[1])
    for i in range(n):
        KS = gcd(KS,numbers[i])
    return KS
        

SKS = 1
SKS_max = 1 
remove = 0

for i in range(N):
    remove = A_list_int.pop(i)
    SKS = gcd_list(N-1,A_list_int)
    A_list_int.insert(i,remove)
    if SKS > SKS_max:
        SKS_max = SKS

print(SKS_max)

Submission status: Runtime Error

Solution code:
import numpy as np
def mygcd(gA, gB):
    while True:
        gR = gA % gB
        if gR == 0:
            return gB
        gA = gB
        gB = gR

if True:
    N=int(input())
    A=np.unique(list(map(int,input().split())))
else:
    A=np.asarray(range(10**5)[10**4:])
#C=np.asarray(list(map(int,input().split())))

mina = np.min(A)

for i in range(A.size):
    A[i] = mygcd(mina,A[i])
uA=np.unique(A)
max = 0
for a in uA:
    if A[A==a].size > 1:
        continue
    tmpgcd = uA[uA!=a][0]
    for ta in uA[uA!=a][1::]:
        tmpgcd = mygcd(tmpgcd,ta)

    if max < tmpgcd: max = tmpgcd

print(max)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import copy

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

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

    for i in range(len(A)):
        A_poped = copy.copy(A)
        A_poped.pop(i)
        tmp = gcd_list(A_poped)
        if tmp > ret_max:
            ret_max = tmp

    print(ret_max)

Submission status: Runtime Error

Solution code:
import copy
import fraction
import functools


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


n = int(input())
a = list(map(int, input().split()))
nl = set(range(n))
gcd_list = [0]
for i in nl:
    tmp = copy.deepcopy(a)
    tmp.pop(i)
    tmp2 = gcd(*tmp)
    gcd_list.append(tmp2)
ans = max(gcd_list)
print(ans)

Submission status: Runtime Error

Solution code:
def c():
    ans = 0
    N = long(raw_input())
    A = raw_input().split()
    for i in range(N):
        for j in range(i+1, N):
            C = long(A[i])
            D = long(A[j])
            #prlong "C:{}, D:{}".format(C,D)
            if C == D:
                g = C
            elif C > D:
                g = gcd(C, D)
            else:
                g = gcd(D, C)
            if g > ans:
                ans = g
    print ans

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

def main():
    c()
	
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

maxAns = min(A)

Ans = 1

# ゴリおす。最小のAから1ずつ減らして、割り切れなかったAが1個以下だったらそこが解答

l = range(10)

for i in range(maxAns - 1):
    acount = 0
    for Ai in A:
        if Ai % (maxAns - i) != 0:
            acount += 1
    # 割り切れなかった回数を数える
    if acount <= 1:
        Ans = maxAns - i
        break

print(Ans)

Submission status: Runtime Error

Solution code:
#import math
#from functools import reduce

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

    return a


n = int(input())
a = [int(i) for i in input().split()]
L = [0] * (n-1)
for i in range(n-1):
    L[i] = gcd(a[i],a[i+1])

if n == 3:
    L.append(gcd(a[0],a[2]))

L.sort(reverse=True)

for l in L:
    c = 0
    for i in a:
        if i % l != 0:
            c += 1
    if c <= 1:
        ans = l
        break

print(ans)

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 math
import queue

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

ques = [queue.Queue() for i in range(N)]

for i, Ai in enumerate(As):
    qi = ques[i]
    for j in range(2,int(math.sqrt(Ai))+1) :
        if (Ai % j == 0) :
            qi.put(j)
    
flag = True
while flag:
    for i, qi in enumerate(ques):
        if(qi.empty()) :
            As[i] = As[-1]
            flag = False
            break
        else :
            qi.get()

min_num = As[0]
gcd_num = math.gcd(As[0], As[1])
for i in range(2,N) :
    #改善の余地あり
    gcd_num = math.gcd(gcd_num, As[i])
    if (gcd_num==1) :
        break

print(gcd_num)

Submission status: Runtime Error

Solution code:
A = list(map(int,input().split()))
print(A)
import random
A_new = random.sample(A,N-1)
change = random.randint(1,10^9)
A_renew = A_new.append(change)

print(gcd(A_renew))

Submission status: Runtime Error

Solution code:
import math
import functools 

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

# n が 2なら 大きい方を出力して終わり

def euclid(m, n):
  if n == 0:
    return m
  new_m = n
  new_n = m % n
  return euclid(new_m, new_n)

def array_euclid(numbers):
  n = len(numbers)
  if n == 3:
    a = euclid(numbers[0], numbers[1])
    b = euclid(numbers[1], numbers[2])
    c = euclid(numbers[2], numbers[0])

    return max([a, b, c])
  v = numbers[n-1] % numbers[n-2]
  if v == 0:
    if n == 2:
      return numbers[0]
    
    numbers.pop()
    return array_euclid(numbers)

  numbers[n-1] = numbers[n-2]
  numbers[n-2] = v
  return array_euclid(numbers)

print(array_euclid(a))



# n が3になるまでやって、大きい方が答え？

#for i in range(n-1):


#print(euclid(a[0],a[1]))

Submission status: Runtime Error

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

import math
from functools import reduce

ans = []

for i in range(n):
    a = list(numbers)
    del a[i]
    ans.append(reduce(math.gcd, a))
    
print(max(ans))

Submission status: Runtime Error

Solution code:

import numpy as np

def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def split_a(alist):
    result = []
    for i in range(len(alist)):
        result.append(alist[:i] + alist[i+1:])

    return result

gcd_memo = {}

def gcd_with_memo(ar):
    if len(ar) == 1:
        return ar[0]

    if len(ar) == 2:
        a = min(ar[0], ar[1])
        b = max(ar[0], ar[1])
        if (a,b) in gcd_memo.keys():
            return gcd_memo[(a,b)]

        g = np.gcd(a, b)
        gcd_memo[(a, b)] = g
        return g

    return gcd_with_memo(gcd_with_memo(ar[:2]), gcd_with_memo(ar[2:]))



if __name__ == '__main__':
    n, a = read_input()
    cand = split_a(a)

    maxgcd = 0
    for c in cand:
        test = gcd_with_memo(c)
        if test > maxgcd:
            maxgcd = test


    print(maxgcd)

Submission status: Runtime Error

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

def gcd(a,b):
    

def mygcd(A):
    if len(A) == 1:
        return A[0]
    else:
        return fraction.gcd(A[0],mygcd(A[1:]))
        
ans = []
for i in range(N):
    ans.append(mygcd(A[:i]+A[i+1:]))

print(max(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)
    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-1}
  
  
N = int(input())
A= list(map(int, input().split()))
pri_flag = True

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:]):
    if len(kouho) == 1:
        print(1)
        pri_flag = False
        break
    try:
      kouho = check(num, kouho, N, i+3)
    except:
      print(1)
      pri_flag = False
      break
    
if pri_flag:
    print(max(kouho))

Submission status: Runtime Error

Solution code:
A = list(map(int,input().split()))
print(A)
import random
A_new = random.sample(A,N-1)
change = random.randint(1,10^9)
A_renew = A_new.append(change)

print(self.gcd(A_renew))