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:
from sys import stdin, exit
from math import gcd


rs = lambda: stdin.readline().strip()
ri = lambda: int(rs())
rsl = lambda: stdin.readline().split()
rim = lambda: map(int, rsl())
ril = lambda: list(rim())


N = ri()
A = list(rim())
A.sort()

# List if length of 2 or shorter
if len(A) <= 2:
    print(max(A))
    exit()

# Left Side = [A0, 0, 0, 0, 0]
left_side = [0 for _ in range(N)]
left_side[0] = A[0]

# Right Side = [0, 0, 0, 0, An]
right_side = [0 for _ in range(N)]
right_side[-1] = A[-1]

for i in range(N - 1):  # DP: L1 = gcd(L0, A1); Maximum GCD on very RIGHT of list  (Dir -->)
    left_side[i + 1] = gcd(left_side[i], A[i + 1])
    
for i in range(1, N):   # DP: Rn-2 = gcd(An-2, Rn-1); Maximum GCD on very LEFT of list  (Dir <--)
    right_side[-1 * (i+1)] = gcd(A[-1*(i+1)], right_side[-1*i])
    
max_gcd = 1

# Left
max_gcd = max(max_gcd, right_side[1])
# Max of Right and Left
max_gcd = max(max_gcd, left_side[-2])

for i in range(1, N - 1):
    left = left_side[i - 1]
    # We exclude the number at i here, and compare whether new gcd is greater than previous
    right = right_side[i + 1]

    max_gcd = max(max_gcd, gcd(left, right))

print(max_gcd)

Submission status: Runtime Error

Solution code:
import unittest
import math


def solution(n, a):
    gcd_left = [0]
    gcd_right = [0]
    for i in range(n):
        gcd_left.append(math.gcd(gcd_left[i], a[i]))
        # 順に(0とa[-1]), (a[-1]とa[-2]),...の比較
        # 要は右端から順にgcdを求めている
        gcd_right.append(math.gcd(gcd_right[i], a[-(i + 1)]))

    gcd_right = gcd_right[::-1]  # gcd_right[i]がi番目以降のgcdとなるように反転

    ans = []
    for i in range(n):
        ans.append(math.gcd(gcd_left[i], gcd_right[i + 1]))


    return max(ans)

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

Submission status: Runtime Error

Solution code:
import unittest
import math


def solution(n, a):
    gcd_left = [0]
    gcd_right = [0]
    for i in range(n):
        gcd_left.append(math.gcd(gcd_left[i], a[i]))
        # 順に(0とa[-1]), (a[-1]とa[-2]),...の比較
        # 要は右端から順にgcdを求めている
        gcd_right.append(math.gcd(gcd_right[i], a[-(i + 1)]))

    gcd_right = gcd_right[::-1]  # gcd_right[i]がi番目以降のgcdとなるように反転

    ans = []
    for i in range(n):
        ans.append(math.gcd(gcd_left[i], gcd_right[i + 1]))


    return max(ans)


class MyTestCase(unittest.TestCase):
    def test1(self):
        self.assertEqual(solution(3, [7, 6, 8]), 2)

    def test2(self):
        self.assertEqual(solution(3, [12, 15, 18]), 6)

    def test3(self):
        self.assertEqual(solution(2, [1000000000, 1000000000]), 1000000000)


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

    unittest.main()

Submission status: Runtime Error

Solution code:
def f(v):
    n = len(v)
    g = math.gcd(v[0], v[1])
    for i in range(2, len(v)):
        g = math.gcd(g, v[i])
    return g

sys.stdin.readline()
a=np.array(sys.stdin.readline()[:-1].split(),dtype=np.int32)

g=f(a)
a=a//g
while(len(a) > 3):
    n = len(a)
    l = a[:n//2]
    r = a[n//2:]
    a = l if f(r) == 1 else r

n = len(a)
h = a[0]
if n == 3:
    h = max([f([a[0], a[1]]), f([a[1], a[2]]), f([a[2], a[0]])])
elif n == 2:
    h = f([a[0], a[1]])

print(g * h)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

def f(v):
    return np.gcd.reduce(v)

sys.stdin.readline()
a=np.array(sys.stdin.readline()[:-1].split(),dtype=np.int32)

g=f(a)
a=a//g
while(len(a) > 3):
    n = len(a)
    l = a[:n//2]
    r = a[n//2:]
    a = l if f(r) == 1 else r

n = len(a)
h = a[0]
if n == 3:
    h = max([f([a[0], a[1]]), f([a[1], a[2]]), f([a[2], a[0]])])
elif n == 2:
    h = f([a[0], a[1]])

print(g * h)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

#累積GCD
left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
    #left.append(math.gcd(left[i],a[i]))
    left[i + 1] = (fractions.gcd(left[i],a[i]))
    #right.insert(0,math.gcd(right[0],a[n - 1 - i]))
    right[n - i - 1] = (fractions.gcd(right[n - i],a[n - 1 - i]))

ans = 0
for i in range(n - 1):
    ans = max(ans,math.gcd(left[i],right[i + 1]))
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

def f(v):
    return np.gcd.reduce(v)

sys.stdin.readline()
a=np.array(sys.stdin.readline()[:-1].split(),dtype=np.int64)

g=f(a)
a=a//g
while(len(a) > 3):
    n = len(a)
    l = a[:n//2]
    r = a[n//2:]
    a = l if f(r) == 1 else r

n = len(a)
h = a[0]
if n == 3:
    h = max([f([a[0], a[1]]), f([a[1], a[2]]), f([a[2], a[0]])])
elif n == 2:
    h = f([a[0], a[1]])

print(g * h)

Submission status: Runtime Error

Solution code:
    import fractions
    from functools import reduce
     
    n = int(input())
    a = list(map(int,input().split()))
     
    #累積GCD
    left = [0] * (n + 1)
    right = [0] * (n + 1)
    for i in range(n):
        left[i + 1] = (math.gcd(left[i],a[i]))
        right[n - i - 1] = (math.gcd(right[n - i],a[n - 1 - i]))
     
    ans = 0
    for i in range(n - 1):
        ans = max(ans,fractions.gcd(left[i],right[i + 1]))
    print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import fractions
import functools
import math

def f(v):
    return functools.reduce(fractions.gcd,v)

sys.stdin.readline()
a=np.array(sys.stdin.readline()[:-1].split(),dtype=np.int64)

g=f(a)
a=a//g
while(len(a) > 3):
    n = len(a)
    l = a[:n//2]
    r = a[n//2:]
    a = l if f(r) == 1 else r

n = len(a)
h = a[0]
if n == 3:
    h = max([math.gcd(a[0], a[1]), math.gcd(a[1], a[2]), math.gcd(a[2], a[0])])
elif n == 2:
    h = math.gcd(a[0], a[1])

print(g * h)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import functools
from math import gcd

def f(v):
    return functools.reduce(gcd,v)

sys.stdin.readline()
a=np.array(sys.stdin.readline()[:-1].split(),dtype=np.int64)

g=f(a)
a=a//g
while(len(a) > 3):
    n = len(a)
    l = a[:n//2]
    r = a[n//2:]
    a = l if f(r) == 1 else r

n = len(a)
h = a[0]
if n == 3:
    h = max([gcd(a[0], a[1]), gcd(a[1], a[2]), gcd(a[2], a[0])])
elif n == 2:
    h = gcd(a[0], a[1])

print(g * h)

Submission status: Runtime Error

Solution code:

def gcd(a,b):
    c=max(a,b)
    d=min(a,b)
    while True:
        if c%d==0:
            return d
        c,d=d,c%d

def gcd_list(A):
    if len(A)==2:
        return gcd(A[0],A[1])
    elif len(A)==1:
        return A[0]
    else:
        return gcd(gcd_list(A[len(A)//2:]),gcd_list(A[:len(A)//2]))
max_gcd=1
for i in range(N):
    max_gcd=max(gcd_list(A[:i]+A[i+1:]),max_gcd)
    
print(max_gcd)

Submission status: Runtime Error

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

def gcd(a,b):
    c=max(a,b)
    d=min(a,b)
    while True:
        c,d=d,c%d
        if c%d==0:
            return d

def gcd_list(A):
    if len(A)==2:
        return gcd(A[0],A[1])
    elif len(A)==1:
        return A[0]
    else:
        return gcd(gcd_list(A[len(A)//2:]),gcd_list(A[:len(A)//2]))
max_gcd=1
for i in range(N):
    max_gcd=max(gcd_list(A[:i]+A[i+1:]),max_gcd)
    
print(max_gcd)

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce

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

for i in range(n):
	a_tmp = copy.copy(a)
	a_tmp.remove(a_tmp[i])
	divisor = reduce(math.gcd, a_tmp)
	ans.append(divisor)

print(max(ans))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import copy

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

for i in range(n):
	a_tmp = copy.copy(a)
	a_tmp.remove(a_tmp[i])
	divisor = reduce(math.gcd, a_tmp)
	ans.append(divisor)

print(ans)
print(max(ans))

Submission status: Runtime Error

Solution code:
import math


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

    index = list(range(N))
    forward = index.copy()
    forward[0] = 0
    for i in index[:-1]:
        forward[i+1] = math.gcd(A[i], forward[i])

    backward = index.copy()
    backward.append(0)
    for i in reversed(index):
        backward[i] = math.gcd(A[i], backward[i+1])

    # print(forward)
    # print(backward)

    M = [math.gcd(f, b) for f, b in zip(forward, backward[1:])]
    # print(M)
    print(max(M))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math

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

R = [0]
L = [0]
ans = 0

for i in range(1,n):
    R.append(math.gcd(R[i-1],a[i-1]))
    L.append(math.gcd(L[i-1],a[-i]))

L.reverse()
for i in range(1,len(R)+1):
    ans = max(ans,math.gcd(R[i-1],L[-i]))

ans = max(ans,R[-1],L[0])

print(ans)

Submission status: Runtime Error

Solution code:
import math
from itertools import combinations, chain

def gcd(numbers):
  gcds = numbers.__next__()
  for x in numbers:
    gcds = math.gcd(gcds, x)
  return gcds

def main():
  N = int(input().strip())
  A = list(map(int, input().strip().split()))
  
  gcds = []
  for i in range(N):
    gcds.append(gcd(chain(A[:i], A[i+1:])))
  
  print(max(gcds))
 
if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
#import sys
#input = sys.stdin.readline


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


def main():
    n = int(input())
    A = list(map(int, input().split()))
    gcdA = [0]*n
    gcdB = [0]*n
    gcdA[0] = A[0]
    gcdB[0] = A[n-1]
    for i in range(1, n):
        gcdA[i] = gcd(A[i], gcdA[i-1])
        gcdB[i] = gcd(A[n-i-1], gcdB[n-1])
    ans = max(gcdA[n-2], gcdB[1])
    for i in range(1, n):
        ans = max(ans, gcd(gcdA[i-1], gcdB[i+1]))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline


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


def main():
    n = int(input())
    A = list(map(int, input().split()))
    gcdA = [0]*n
    gcdB = [0]*n
    gcdA[0] = A[0]
    gcdB[0] = A[n-1]
    for i in range(1, n):
        gcdA[i] = gcd(A[i], gcdA[i-1])
        gcdB[i] = gcd(A[n-i-1], gcdB[n-1])
    ans = max(gcdA[n-2], gcdB[1])
    for i in range(1, n):
        ans = max(ans, gcd(gcdA[i-1], gcdB[i+1]))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
from itertools import combinations

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

def main():
  N = int(input().strip())
  A = list(map(int, input().strip().split()))
  
  gcds = []
  for i in range(N):
    gcds.append(gcd([*A[:i], *A[i+1:]]))
  
  print(max(gcds))
 
if __name__ == '__main__':
  main()

Submission status: Runtime Error

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

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

l = [0]*N
r = [0]*N

l[0] = A[0]
r[-1] = A[-1]

for x in range(1,N):
    y = N - 1 - x
    l[x] = gcd(A[x],l[x-1])
    r[y] = gcd(A[y],r[y+1])

l.insert(0,0)
l.append(0)
r.insert(0,0)
r.append(0)

o = 1

for x in range(N):
    x += 1
    o = max(o,gcd(l[x-1],r[x+1]))

print(max(o))

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a = list(map(int, input().split()))
ans=0
for remove in range(n):
    if remove==0:
        total_gcd=a[1]
    else:
        total_gcd=a[0]
    for i in range(n):
        if i==remove:
            continue
        total_gcd=math.gcd(total_gcd, a[i])
    ans = max(ans, total_gcd)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from math import gcd

N = int(input())

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


if len(A) < 3:
    print(max(A))
    sys.exit()


left_side = [0 for _ in range(N)]
left_side[0] = A[0]

right_side = [0 for _ in range(N)]
right_side[-1] = A[-1]



for i in range(N -1):
    left_side[i + 1] = gcd(left_side[i], A[i + 1])

for i in range(1, N):
    right_side[-1* (i + 1)] = gcd(right_side[-1* i], A[ -1 *(i + 1)])


max_gcd = 1 
for i in range(1, N -1 ):
    left = left_side[i - 1]
    right = right_side[i + 1]
    max_gcd = max(max_gcd, gcd(left, right))




print(max_gcd)

Submission status: Runtime Error

Solution code:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
left=right=[0]*n
for i in range(1,n):
    left[i]=gcd(left[i-1],a[i-1])
for i in range(n-1)[::-1]:
    right[i]=gcd(right[i+1],a[i+1])
ans=[gcd(x[i],y[i]) for i in range(n)]
print(max(ans))

Submission status: Runtime Error

Solution code:
import math

def leave_one_out(array):
  max_gcd = -1
  for i in range(len(array)):
    if i == 0:
      gcd = array[1]
      k = 2
    elif i == 1:
      gcd = array[0]
      k = 2
    else:
      gcd = array[0]
      k = 1
    for j in range(k, len(array)):
      if i == j:
        continue
      gcd = math.gcd(array[j], gcd)
    max_gcd = max(gcd, max_gcd)
  return max_gcd

def main():
  N = int(input().strip())
  A = list(map(int, input().strip().split()))
  print('%d' % leave_one_out(A))

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
import math

def leave_one_out(array):
  max_gcd = -1
  for i in range(len(array)):
    if i == 0:
      gcd = array[1]
      k = 2
    elif i == 1:
      gcd = array[0]
      k = 2
    else:
      gcd = array[0]
      k = 1
    for j in range(k, len(array)):
      if i == j:
        continue
      gcd = math.gcd(array[j], gcd)
    max_gcd = max(gcd, max_gcd)
  return max_gcd

def main():
  N = int(input().strip())
  A = list(map(int, input().strip().split()))
  print(leave_one_out(A))

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
import math
from itertools import combinations

def leave_one_out(array):
  max_gcd = 0
  for i in range(len(array)):
    if i == 0:
      gcd = array[1]
      k = 2
    elif i == 1:
      gcd = array[0]
      k = 2
    else:
      gcd = array[0]
      k = 1
    for j in range(k, len(array)):
      if i == j:
        continue
      gcd = math.gcd(array[j], gcd)
    max_gcd = max(gcd, max_gcd)
  return max_gcd

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

def main():
  N = int(input().strip())
  A = list(map(int, input().strip().split()))
  #N = int(1e3)
  #A = [int(1e9)] * N
  divs_dict = dict()
  
  print(leave_one_out(A))
  """
  for a in A:
    divs = make_divisors(a)
    for d in divs:
      if d in divs_dict.keys():
        divs_dict[d] += 1
      else:
        divs_dict[d] = 1
  
  result_divs = []
  for k in divs_dict.keys():
    if divs_dict[k] >= N-1:
      result_divs.append(k)
  print(sorted(result_divs)[-1])
  """

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import math
INF = float("inf")


class SegmentTree(object):
    # セグメント木

    def __init__(self, N):
        """サイズNの配列を元にしたセグメント木
        """
        # 単位元
        self.idelem = 0
        # 比較関数
        self.func = GCD

        self.N0 = 2**(math.ceil(math.log2(N)))
        self.tree = [self.idelem]*(2*self.N0)

    def update(self, k, x):
        """k番目の値をxに更新
        """
        k += self.N0-1
        self.tree[k] = x
        while k > 1:
            k = (k-1)//2
            self.tree[k] = self.func(self.tree[2*k+1], self.tree[2*k+2])

    def query(self, l, r):
        """区間[l, r)の最小値
        """
        l += self.N0-1
        r += self.N0-1
        s = self.idelem
        while l < r:
            if r % 2 == 0:
                r -= 1
                s = self.func(s, self.tree[r])

            if l % 2 == 0:
                s = self.func(s, self.tree[l])
                l += 1
            l //= 2
            r //= 2
        return s

    def __str__(self):
        return str(self.tree[self.N0-1:-1])


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


def GCDs(*a):
    # リストで入力しないよう注意。
    if len(a) == 0:
        return -1  # エラー

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

    res = a[0]
    for i in range(1, len(a)):
        res = GCD(res, a[i])
    return res


def solve(N: int, A: "List[int]"):

    st = SegmentTree(N)
    for i, a in enumerate(A):
        st.update(i, a)

    buf = []
    for i in range(N):
        buf.append(GCD(st.query(0, i), st.query(i+1, N)))
    print(max(buf))

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from fractions import Fraction
import functools

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

ans = 0

for i in range(N):
    A_i = A[:i-1] + A[i:]
    ans = max(ans, functools.reduce(fractions.gcd, A_i))

print(ans)

Submission status: Runtime Error

Solution code:
import fraction
import functools

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

ans = 0

for i in range(N):
    A_i = A[:i-1] + A[i:]
    ans = max(ans, functools.reduce(fraction.gcd, A_i))

print(ans)

Submission status: Runtime Error

Solution code:
import math
import functools

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

ans = 0

for i in range(N):
    A_i = A[:i-1] + A[i:]
    ans = max(ans, functools.reduce(math.gcd, A_i))

print(ans)

Submission status: Runtime Error

Solution code:
import math
import functools

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

ans_list = []

for i in range(N):
    A_i = A[:i-1] + A[i:]
    ans_list.append(functools.reduce(math.gcd, A_i))

print(max(ans_list))

Submission status: Runtime Error

Solution code:
#C - GCD on Blackboard
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

def gcdList(num):
    if len(num) == 1:
        return num[0]
    else:
        return gcd(num[0], gcdList(num[1:]))
    
n = int(input())
a = list(map(int, input().split()))
ans = 0

for i in range(n):
    ans = max(ans, gcdList(a[:i]+a[i+1:]))
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

_ = input()
A = list(map(int, input().split()))
#print("A", A)

result = 1
for i, a in enumerate(A):
    #print("ignore", a)
    A.pop(i)
    #print("current A", A)

    result = max(result, reduce(math.gcd, A))
    
    A.insert(i, a)
    #print("org A", A)
    #print("---")

print(result)

Submission status: Runtime Error

Solution code:
import numpy as np
import fractions

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

maxA = np.max(A)

if(maxA == np.min(A)):
    print(maxA)
else:
    #check = (np.unique(maxA // np.arange(1,maxA)))[::-1]
    #check = minA // np.arange(1,minA)
    check = np.arange(1,maxA)[::-1]
    for i in check:
        #全てのAに対してiで割り切れるか＝最大公約数
        #iで割り切れた数＝len(A)-1なら，残りの数にiをかけて最大公約数に出来る．
        num = np.sum((A % i>0))
        if(num < 2):
            #j = A[np.where(A % i>0)][0]
            #print(i,j,i*j//math.gcd(i,j))
            #if(i*j//fractions.gcd(i,j) < 10**9):
            print(i)
            break

Submission status: Runtime Error

Solution code:
import numpy as np
import fractions

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

maxA = np.max(A)

if(maxA == np.min(A)):
    print(maxA)
else:
    check = np.unique(maxA // np.arange(1,maxA))
    #check = minA // np.arange(1,minA)
    for i in check[::-1]:
        #全てのAに対してiで割り切れるか＝最大公約数
        #iで割り切れた数＝len(A)-1なら，残りの数にiをかけて最大公約数に出来る．
        num = np.sum((A % i>0))
        if(num < 2):
            j = A[np.where(A % i>0)][0]
            #print(i,j,i*j//math.gcd(i,j))
            if(i*j//fractions.gcd(i,j) < 10**9):
                print(i)
                break

Submission status: Runtime Error

Solution code:
import numpy as np
import fractions

N = int(input())
A = np.array([int(i) for i in (input()).split(" ")])
minA = np.min(A)

if(minA == np.max(A)):
    print(minA)
else:
    check = np.unique(minA // np.arange(1,minA))
    #check = minA // np.arange(1,minA)
    for i in check[::-1]:
        #全てのAに対してiで割り切れるか＝最大公約数
        #iで割り切れた数＝len(A)-1なら，残りの数にiをかけて最大公約数に出来る．
        num = np.sum((A % i>0))
        if(num < 2):
            j = A[np.where(A % i>0)][0]
            #print(i,j,i*j//math.gcd(i,j))
            if(i*j//fractions.gcd(i,j) < 10**9):
                print(i)
                break

Submission status: Runtime Error

Solution code:
import numpy as np
import math

N = int(input())
A = np.array([int(i) for i in (input()).split(" ")])
minA = np.min(A)

if(minA == np.max(A)):
    print(minA)
else:
    check = np.unique(minA // np.arange(1,minA))
    #check = minA // np.arange(1,minA)
    for i in check[::-1]:
        #全てのAに対してiで割り切れるか＝最大公約数
        #iで割り切れた数＝len(A)-1なら，残りの数にiをかけて最大公約数に出来る．
        num = np.sum((A % i>0))
        if(num < 2):
            j = A[np.where(A % i>0)][0]
            #print(i,j,i*j//math.gcd(i,j))
            if(i*j//math.gcd(i,j) < 10**9):
                print(i)
                break

Submission status: Runtime Error

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math


def gcd_ab(a,b):
  while a != b:
    if a > b:
      a,b = [b,a]
    if a == 0:
      return b
    b = b-a
  return a


if __name__ == "__main__": 
  N = int(input())
  An = list(map(int, sys.stdin.readline().rstrip().split()))
  cum = [[0,0] for i in range(N+2)]

  for i in range(N):
    cum[i+1][0] = math.gcd(cum[i][0], An[i])
    cum[N-i][1] = math.gcd(cum[N-i+1][1], An[N-i-1])

  ans = [0 for i in range(N)]
  for i in range(1,N+1):
    ans[i-1] = math.gcd(cum[i-1][0], cum[i+1][1])
  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(" ")])
minA = np.min(A)

if(minA == np.max(A)):
    print(minA)
else:
    check = np.unique(minA // np.arange(1,minA))
    for i in check[::-1]:
        #全てのAに対してiで割り切れるか＝最大公約数
        #iで割り切れた数＝len(A)-1なら，残りの数にiをかけて最大公約数に出来る．
        if(np.sum((A % i>0)) < 2):
            print(i)
            break

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    a, b = min(a, b), max(a, b)
    if b == 0:
        return 0
    elif a == 0:
        return b
    else:
        return gcd(a, b%a)
def left(list, index):
    if index == 0:
        return 0
    else:
        return gcd(left(list, index-1), list[index-1])
def right(list, index):
    if index == len(list):
        return 0
    else:
        return gcd(right(list, index+1), list[index])
def ex_gcd(list, index):
    return gcd(left(list,index), right(list,index+1))
N = int(input())
A = [int(x) for x in input().split()]
if N == 2:
    print(max(A[0], A[1]))
else:
    tmp = 0
    for i in range(N):
        if tmp < ex_gcd(A, i):
            tmp = ex_gcd(A, i)
    print(tmp)

Submission status: Runtime Error

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math



def gcd(a,b):
  while a != b:
    a,b = sorted([a,b])
    if a == 0:
      return b
    b = b-a
  return a


if __name__ == "__main__": 
  N = int(input())
  An = list(map(int, sys.stdin.readline().rstrip().split()))
  cuml = An.copy()
  cumr = An.copy()

  for i in range(1, N):
    cuml[i] = gcd(cuml[i-1], An[i])
    cumr[N-i-1] = gcd(cumr[N-i], An[N-i-1])

  cuml = [0] + cuml + [0]
  cumr = [0] + cumr + [0]

  ans = 0
  for i in range(1,N+1):
    ans = max(ans, gcd(cuml[i-1], cumr[i+1]))
  print(ans)

Submission status: Runtime Error

Solution code:
import math

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

# s = [-1, *a[:-1]]
# t = [*a[1:], -1]
s = [-1] * n
t = [-1] * n
for x in range(0, n - 1):
    s[x + 1] = a[x]
for x in range(1, n):
    t[x - 1] = a[x]

for x in range(1, n - 1):
    s[x + 1] = math.gcd(s[x + 1], s[x])
for x in range(n - 2, 0, -1):
    t[x - 1] = math.gcd(t[x - 1], t[x])

ans = -float('inf')
for x, y in zip(s, t):
    if x == -1:
        ans = max(ans, y)
    elif y == -1:
        ans = max(ans, x)
    else:
        ans = max(ans, math.gcd(x, y))
    
print(ans)

Submission status: Runtime Error

Solution code:
#import math
import fraction

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

L=[0,0]
for ai in A:
    #L.append(gcd(L[-1],ai))
    L.append(fraction.gcd(L[-1],ai))
    print(L)

R=[0,0]
for ai in A[::-1]:
    #R.append(gcd(R[-1],ai))
    R.append(fraction.gcd(L[-1],ai))
    print(R)

print(max(fraction.gcd(l,r) for l,r in zip(L,reversed(R))))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc125_c
import fractions, functools, itertools

# input
n = int(input())
A = [int(s) for s in input().split()]
# get ans
x = A[0]
y = A[1]
def divisors(n):
     for i in range(2, n):
        if n%i == 0:
            yield i
ds = set(divisors(x)) + set(divisors(y))
def condition(d):
    not_div = (a%d != 0 for a in A)
    not_div = (1 if b else 0 for b in not_div)
    return sum(not_div) <= 1
ans = max(filter(condition, ds))
# output
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

s = [-1, *a[:-1]]
t = [*a[1:], -1]
for x in range(1, n - 1):
    s[x + 1] = math.gcd(s[x + 1], s[x])
for x in range(n - 2, 0, -1):
    t[x - 1] = math.gcd(t[x - 1], t[x])

ans = -float('inf')
for x, y in zip(s, t):
    if x == -1:
        ans = max(ans, y)
    elif y == -1:
        ans = max(ans, x)
    else:
        ans = max(ans, math.gcd(x, y))
    
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
from fractions import gcd
from functools import reduce
l = [(hoge.append(gcd(hoge[i-1], a[i])), hoge)[1] for hoge in [[a[0]]] for i in range(1, n)][0]
r = reversed([(hoge.append(gcd(hoge[i-1], a[n-i-i])), hoge)[1] for hoge in [[a[0]]]for i in range(1, n)][0])
print (reduce(lambda x,y:max(x,y),[gcd(l[i-1]if 0<i else r[i+1],r[i+1] if i<n-1 else l[i-1])for i in range(n)]))

Submission status: Runtime Error

Solution code:
from functools import reduce
from math import gcd
N =  int(input())
A =  list(map(int, (input().split(' '))))


gcds = []
for i in range(len(A)):
    A[:i] + A[i+1:]
    gcds.append(reduce(gcd, A[:i]+A[i+1:]))

print(max(gcds))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
def gcd(*numbers):
    return reduce(math.gcd, numbers)
num = []
for i in range(N):
    temp = A[0:i] + A[i+1:]
    num.append(gcd(temp))
print(max(num))

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
N=int(input())
A=list(map(int,input().split()))

L=[0,0]
for ai in A:
    L.append(gcd(L[-1],ai))
    print(L)

R=[0,0]
for ai in A[::-1]:
    R.append(gcd(R[-1],ai))
    print(R)

print(max(gcd(l,r) for l,r in zip(L,reversed(R))))

Submission status: Runtime Error

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

from fractions import gcd

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

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

ans = 1
for i in range(n):
    tmp = 1
    l = tl[i - 1] if 0 < i else tr[i + 1]
    r = tr[i + 1] if i < n - 1 else tl[i - 1]
    ans = max(gcd(l,r))
print(ans)

Submission status: Runtime Error

Solution code:
n = input()
a_list = [i for i in input().split()]

m = min(a_list)
mini = 1
for i in reversed(range(m+1)):
  flag = 0
  if(i==0):
    break
  for a in a_list:
    if(a%i != 0):
       break
    else:
       flag += 1
  if(flag == n):
    mini = i
    break
print(mini)

Submission status: Runtime Error

Solution code:
import math

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

gcd = math.gcd

l = [0]*N
r = [0]*N

l[0] = A[0]
r[-1] = A[-1]

for x in range(1,N):
    l[x] = gcd(A[x],l[x-1])

for x in range(N-2,-1,-1):
    r[x] = gcd(A[x],r[x+1])

l.insert(0,0)
l.append(0)
r.insert(0,0)
r.append(0)

o = []

for x in range(N):
    o.append(gcd(l[x-1],r[x+1]))

print(max(o))

Submission status: Runtime Error

Solution code:
import sys,math
input=sys.stdin.readline
N=int(input())
num = list(map(int,input().split()))
left=[0]*(N+1)
right=[0]*(N+1)
for i in range(N):
  j = N-i-1#初期値=4
  left[i+1] = math.gcd(left[i],num[i])
  right[j] = math.gcd(right[j+1],num[j])
ans=0
for k in range(N):
  ans = max(ans,math.gcd(left[k],right[k+1]))
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

print(gcd(*arr))

Submission status: Runtime Error

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

A.sort(reverse = True)
c = 0

for i in range(max(A),1,-1):
    c = 0

    for j in A:
        if j % i != 0:
            c = c + 1
            if c >= 2:
                break
    else:
        if c <= 1:
            break
print(i)

Submission status: Runtime Error

Solution code:
from functools import reduce
import fractions

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

def gcd(data):
    if len(data) == 1:
        return data[0]
    return reduce(lambda x, y: fractions.gcd(x, y), data)

gcds = []

for i in range(1, n-1):
    gcds.append(gcd(A[0:i] + A[i+1:n]))

print(max(gcds))

Submission status: Runtime Error

Solution code:
from functools import reduce
import fractions

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

def gcd(data):
    if len(data) == 1:
        return data[0]
    return reduce(lambda x, y: fractions.gcd(x, y), data)

gcds = []

for i in range(1, n-2):
    gcds.append(gcd(A[0:i] + A[i+1:n]))

print(max(gcds))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

    max = 1
    for i in range(N):
        tmp = A.copy()
        tmp.pop(i)
        gcd = gcd_list(tmp)
        if max < gcd:
            max = gcd

    print(max)