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


def solve():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    m = []
    for i in range(n):
        l, r = a[:i], a[i + 1:]
        gcd_l, gcd_r = 0, 0
        if len(l) == 1:
            gcd_l = l[0]
        else:
            for j in range(len(l) - 1):
                gcd_l = math.gcd(l[j], l[j + 1])
        if len(r) == 1:
            gcd_r = r[0]
        else:
            for j in range(len(r) - 1):
                gcd_r = math.gcd(r[j], r[j + 1])
        m.append(math.gcd(gcd_l, gcd_r))
    return max(m)


if __name__ == "__main__":
    print(solve())

Submission status: Runtime Error

Solution code:
import math


def solve():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    m = [0] * n
    for i in range(n):
        l, r = a[:i], a[i + 1:]
        gcd_l, gcd_r = 0, 0
        if len(l) == 1:
            gcd_l = l[0]
        else:
            for j in range(len(l) - 1):
                gcd_l = math.gcd(l[j], l[j + 1])
        if len(r) == 1:
            gcd_r = r[0]
        else:
            for j in range(len(r) - 1):
                gcd_r = math.gcd(r[j], r[j + 1])
        m.append(math.gcd(gcd_l, gcd_r))
    return max(m)


if __name__ == "__main__":
    print(solve())

Submission status: Runtime Error

Solution code:
import math


def solve():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    m = [0] * n
    for i in range(n):
        l, r = a[:i], a[i + 1:]
        gcd_l, gcd_r = 0, 0
        if len(l) == 1:
            gcd_l = l[0]
        else:
            for j in range(len(l) - 1):
                gcd_l = math.gcd(l[j], l[j + 1])
        if len(r) == 1:
            gcd_r = r[0]
        else:
            for j in range(len(r) - 1):
                gcd_r = math.gcd(r[j], r[j + 1])
        m.append(math.gcd(gcd_l, gcd_r))
    print(m)
    return max(m)


if __name__ == "__main__":
    print(solve())

Submission status: Runtime Error

Solution code:
import math


def solve():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    if n == 2:
        return math.gcd(a[0], a[1])
    cand1 = math.gcd(a[1], a[2])
    cand2 = math.gcd(a[0], a[2])
    return max(cand1, cand2)


if __name__ == "__main__":
    print(solve())

Submission status: Runtime Error

Solution code:
import math


def solve():
    n = int(input())
    a = list(map(int, input().split()))
    min_even = min([i for i in a if i % 2 == 1])
    min_odd = min([i for i in a if i % 2 == 0])
    a1 = sorted([i for i in a if i != min_odd])
    cand1 = math.gcd(a1[0], a1[1])
    a2 = sorted([i for i in a if i != min_even])
    cand2 = math.gcd(a2[0], a2[1])
    return max(cand1, cand2)


if __name__ == "__main__":
    print(solve())

Submission status: Runtime Error

Solution code:
from math import gcd
n = int(input())
a = [int(x) for x in input().split()]

if n == 2:
    print(max(a))
else:
    x, y, z = a[0], a[1], a[2]
    p, q, r = gcd(x, y), gcd(y, z), gcd(z, x)
    gcd_max = max(p, q, r)
    if gcd_max == p:
        without = z
    elif gcd_max == q:
        without = x
    else:
        without = y

    k = gcd(gcd_max, without)   
    for i in range(3, n):
        a_i = a[i]
        if a_i % gcd_max != 0:
            l = gcd(gcd_max, a_i)
            if l >= k:
                gcd_max = l
            else:
                gcd_max = k
                without = a_i
        k = gcd(k, a_i)
    print(gcd_max)

Submission status: Runtime Error

Solution code:
from math import gcd
n = int(input())
a = [int(x) for x in input().split()]

if n == 2:
    print(max(a))
else:
    
    x, y, z = a[0], a[1], a[2]
    p, q, r = gcd(x, y), gcd(y, z), gcd(z, x)
    gcd_max = max(p, q, r)
    if gcd_max == p:
        without = z
    elif gcd_max == q:
        without = x
    else:
        without = y

    k = gcd(gcd_max, without)   
    for i in range(3, n):
        a_i = a[i]
        if a_i % gcd_max != 0:
            l = gcd(gcd_max, a_i)
            if l >= k:
                gcd_max = l
            else:
                gcd_max = k
                without = a_i
        k = gcd(k, a_i)
print(gcd_max)

Submission status: Runtime Error

Solution code:
import functools
import math
n = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(n-1):
    b = a.pop(i)
    gcd = functools.reduce(math.gcd, a)
    c = max(c,gcd)
    a.insert(i, b)
print(c)

Submission status: Runtime Error

Solution code:
from math import gcd

n = int( input() )
a = list( map( int, input().split() ) )
left = [0]*n
right = [0]*n

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

right[-1] = a[-1]
for i in range(2,n+1):
    right[-i] = gcd(right[-i+1], a[-i])

max_gcd = 0
for i in range(n):
    if i == 0 and max_gcd < right[1]:
        max_gcd = right[1]
    elif i == n-1 and max_gcd < left[n-2]:
        max_gcd = left[n-2]
    if i >= 1 and i <= n-2 and max_gcd < gcd( left[i-1], right[i+1]):
        max_gcd = gcd( left[i-1], right[i+1])

print(max_gcd)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

m1 = [0] * (N + 1)
m2 = [0] * (N + 1)
for i in range(1, N + 1):
  m1[i] = fractions.gcd(m1[i - 1], a_list[i - 1])
  m2[n - i] = fractions.gcd(m2[n - i + 1], a_list[n - i])

m = [0] * N
for i in range(N):
  m[i] = fractions.gcd(m1[i], m2[i + 1])

print(max(m))

Submission status: Runtime Error

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

for i in range(n):
    for j in range(n):
        b = math.gcd(a[i], a[j])
        if b != 1:
            ans.append(b)

if ans.count(1) > 1 :
    print(0)
else:
    print(max(ans))

Submission status: Runtime Error

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

for i in range(n):
    for j in range(i):
        b = math.gcd(a[i], a[j])
        if b != 1:
            ans.append(b)

if ans.count(1) > 1 :
    print(0)
else:
    print(max(ans))

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if a < b:
        a,b = b,a
    if b == 0:
        return a
    if a%b == 0:
        return b
    return gcd(b, a%b)
N = int(input())
a = map(int,input().split())
g1=[0 for i in range(N)]
g2=[0 for i in range(N)]
g1[0]=a[0]
g2[N-1]=a[N-1]
for i in range(1,N):
  g1[i]=gcd(g1[i-1],a[i])
for i in range(N-2,-1,-1):
  g2[i]=gcd(g2[i+1],a[i])
ans=1
for i in range(N-2):
  a=gcd(g1[i],g2[i+2])
  ans=max(ans,a)
ans=max(ans,g1[N-2],g2[1])
print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if a < b:
        a,b = b,a
    if b == 0:
        return a
    if a%b == 0:
        return b
    return gcd(b, a%b)
N = int(input())
A = map(int,input().split())
g1=[0 for i in range(N)]
g2=[0 for i in range(N)]
g1[0]=a[0]
g2[N-1]=a[N-1]
for i in range(1,N):
  g1[i]=gcd(g1[i-1],a[i])
for i in range(N-2,-1,-1):
  g2[i]=gcd(g2[i+1],a[i])
ans=1
for i in range(N-2):
  a=gcd(g1[i],g2[i+2])
  ans=max(ans,a)
ans=max(ans,g1[N-2],g2[1])
print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if a < b:
        a,b = b,a
    if b == 0:
        return a
    if a%b == 0:
        return b
    return gcb(b, a%b)
N = int(input())
A = map(int,input().split())
g1=[0 for i in range(N)]
g2=[0 for i in range(N)]
g1[0]=a[0]
g2[N-1]=a[N-1]
for i in range(1,N):
  g1[i]=gcd(g1[i-1],a[i])
for i in range(N-2,-1,-1):
  g2[i]=gcd(g2[i+1],a[i])
ans=1
for i in range(N-2):
  a=gcd(g1[i],g2[i+2])
  ans=max(ans,a)
ans=max(ans,g1[N-2],g2[1])
print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if a < b:
        a,b = b,a
    if b == 0:
        return a
    if a%b == 0:
        return b
    return gcb(b, a%b)
  
N = int(input())
A = map(int,input().split())
g1=[0 for i in range(n)]
g2=[0 for i in range(n)]
g1[0]=a[0]
g2[n-1]=a[n-1]
for i in range(1,n):
  g1[i]=gcd(g1[i-1],a[i])
for i in range(n-2,-1,-1):
  g2[i]=gcd(g2[i+1],a[i])
ans=1
for i in range(n-2):
  a=gcd(g1[i],g2[i+2])
  ans=max(ans,a)
ans=max(ans,g1[n-2],g2[1])
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

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

gcds=[left[n-2], right[1]]
for i in range(n-2):
    gcds.append(math.gcd(left[i], right[i+2]))

print(max(gcds))

Submission status: Runtime Error

Solution code:
import math

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

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

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

Submission status: Runtime Error

Solution code:
import math

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

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

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

Submission status: Runtime Error

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

right_gcd = [0]*(n)
left_gcd = [0]*(n)
right_gcd[n-1] = a[n-1]
left_gcd[0] = a[0]

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

for i in range(n-1):
    left_gcd[i+1] = math.gcd(left_gcd[i],a[i+1])

gcd = [0]*n
for i in range(n):
    if i == 0:
        gcd[i] = right_gcd[1]
    elif i == n-1:
        gcd[i] = left_gcd[n-2]
    else:
        gcd[i] = math.gcd(left_gcd[i-1],right_gcd[i+1])

print(max(gcd))

Submission status: Runtime Error

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

def divisor(x, m):
    ret = []
    for i in range(1, int(x**0.5)+1):
        if i >= m:
            return ret
            
        if x % i == 0:
            ret.append(i)
            compl = x//i
            if i*i != x and compl < m:
                ret.append(compl)
    return ret

divisor_dict = {}
m = 10 ** 10
for i in range(len(A)):
    if i==3:
        m = 0
        for key, val in divisor_dict:
            if val >= 2 and key > m:
                m = key
    
    div = divisor(A[i], m)
    for j in div:
        if j in divisor_dict:
            divisor_dict[j] += 1
        else:
            divisor_dict[j] = 1
        
max_val = 0
for key, val in divisor_dict.items():
    if val >= N-1 and key > max_val:
        max_val = key

print(max_val)

Submission status: Runtime Error

Solution code:
#125
import fractions
n = int(input())
a = [int(x) for x in input().split(' ')]
all_m = []
for i in range(1,n-1):
    a_1 = a[:i]
    a_2 = a[i+1:]
    m_1 = a_1[0]
    m_2 = a_2[0]
    for j in range(len(a_1)-1):
        m_1 = fractions.gcd(m_1,a_1[j+1])
    for j in range(len(a_2)-1):
        m_2 = fractions.gcd(m_2,a_2[j+1])
    all_m.append(fractions.gcd(m_1,m_2))
m = a[1]
for j in range(1,n-1):
    m = fractions.gcd(m,a[j+1])
all_m.append(m)
m = a[0]
for j in range(n-2):
    m = fractions.gcd(m,a[j+1])
all_m.appendm(m)
print(max(all_m))

Submission status: Runtime Error

Solution code:
#125
import fractions
n = int(input())
a = [int(x) for x in input().split(' ')]
all_m = []
for i in range(1,n-1):
    a_1 = a[:i]
    a_2 = a[i+1:]
    m_1 = a_1[0]
    m_2 = a_2[0]
    for j in range(len(a_1)-1):
        m_1 = fractions.gcd(m_1,a_1[j+1])
    for j in range(len(a_2)-1):
        m_2 = fractions.gcd(m_2,a_2[j+1])
    all_m.append(fractions.gcd(m_1,m_2))
m = a[1]
for j in range(1,n):
    m = fractions.gcd(m,a[j+1])
all_m.append(m)
m = a[0]
for j in range(n-1):
    m = fractions.gcd(m,a[j+1])
all_m.appendm(m)
print(max(all_m))

Submission status: Runtime Error

Solution code:
#125
import 
n = int(input())
a = [int(x) for x in input().split(' ')]
all_m = []
for i in range(1,n-1):
    a_1 = a[:i]
    a_2 = a[i+1:]
    m_1 = a_1[0]
    m_2 = a_2[0]
    for j in range(len(a_1)-1):
        m_1 = math.gcd(m_1,a_1[j+1])
    for j in range(len(a_2)-1):
        m_2 = math.gcd(m_2,a_2[j+1])
    all_m.append(fractions.gcd(m_1,m_2))
m = a[1]
for j in range(1,n):
    m = math.gcd(m,a[j+1])
all_m.append(fractions.gcd(m))
m = a[0]
for j in range(n-1):
    m = math.gcd(m,a[j+1])
all_m.append(fractions.gcd(m))
print(max(all_m))

Submission status: Runtime Error

Solution code:
import math

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

A.sort()

for i in range(1,math.ceil(A[N-1]**0.5)):
    if A[N-1]%i ==0:
        mx_div.append(i)
        mx_div.append(A[N-1]//i)
mx_div.sort()
mx_div.reverse()

num=min(A[0],mx_div[0])

f = 0

for i in range(num,0,-1):
    f = 0
    for j in range(N):
        if A[j]%i !=0:
            f +=1
    if f<=1:
        print(i)
        exit()

Submission status: Runtime Error

Solution code:
import math  # fractions

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

l_gcd = [0]
for i in range(n):
    l_gcd.append(math.gcd(l_gcd[-1], a[i]))
# print(l_gcd)

r_gcd = [0]
for i in range(n):
    r_gcd.append(math.gcd(r_gcd[-1], a[-(i+1)]))
r_gcd.reverse()
# print(r_gcd)

for i in range(n):
    ans = max(ans, math.gcd(l_gcd[i], r_gcd[i+1]))
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

for i in range(n):
    b = a[:i]+a[i+1:]
    ans = max(reduce(math.gcd, b), ans)

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import functools
from math import gcd
# from fractions import gcd
 
def solve(N: int, A: "List[int]"):
    L = [0] * (N)
    R = [0] * (N)
 
    L[0] = A[0]
    for i in range(1, N):
        L[i] = gcd(L[i-1], A[i-1])
 
    R[N-1] = A[N-1]
    for i in reversed(range(0,N-1)):
        R[i] = gcd(R[i+1], A[i+1])
 
    # print(L)
    # print(R)
 
    ans = 0
    for i in range(N):
        ans = max(ans, gcd(L[i], R[i]))
 
    print(ans)
 
    return
 
 
# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
#!/usr/bin/env python3
import sys
import functools,math


def solve(N: int, A: "List[int]"):
    L = [0] * (N+2)
    R = [0] * (N+2)

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

    R[N] = A[N-1]
    for i in reversed(range(0,N+1)):
        R[i] = math.gcd(A[i-1], R[i+1])

    # print(L)
    # print(R)

    ans = 0
    for i in range(1,N):
        if(L[i-1] == 0):
            ans = max(ans, R[i+1])
        elif(R[i-1] == 0):
            ans = max(ans, R[i-1])
        else:
            ans = max(ans, math.gcd(L[i-1], R[i+1]))

    print(ans)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
n=int(input())
a=list(map(int,input().split()))
c=[1]*n
for i in range(n):
  b=[k for k in a if k != i ]
  for j in range(2,min(b)):
      d=[b[l]%j for l in range(n-1)]
      if sum(d) ==0:
         c[i]=j
print(max(c))

Submission status: Runtime Error

Solution code:
n=input()
a=list(map(int,input().split()))
c=[1]*n
for i in range(n)
  b=[k for k in a if k != i ]
  for j in range(2,min(b))
      d=[b[l]%j for l in range(n-1)]
      if sum(d) ==0:
         c[i]=j
print(max(c))

Submission status: Runtime Error

Solution code:
n=input()
a=list(map(int,input().split()))
c=[1]*n
for i in range(n)
  b=a.pop(i)
  for j in range(2,min(b))
      d=[b[l]%j for l in range(n-1)]
      if sum(d) ==0:
         c[i]=j
print(max(c))

Submission status: Runtime Error

Solution code:
n=input()
a=list(map(int,input().split()))
c=[1]*n
for i in range(n)
  b=[k if k != i for k in a]
  for j in range(2,min(b))
      d=[b[l]%j for l in range(n-1)]
      if sum(d) ==0:
         c[i]=j
print(max(c))

Submission status: Runtime Error

Solution code:
n=input()
a=list(map(int,input().split()))
c=[1]*n
for i in range(n)
  b=[a[k] if k != i for k in range(a)]
  for j in range(2,min(b))
      d=[b[l]%j for l in range(n-1)]
      if sum(d) ==0:
         c[i]=j
print(max(c))

Submission status: Runtime Error

Solution code:
n=input()
a=list(map(int,input().split))
c=[1]*n
for i in range(n)
  b=[a[k] if k != i for k in range(a)]
  for j in range(2,min(b))
      d=[b[l]%j for l in range(n-1)]
      if sum(d) ==0:
         c[i]=j
print(max(c))

Submission status: Runtime Error

Solution code:
n=input()
a=list(map(int,input().split))
c=[1]*n
for i in range(n)
  b=[a[k] if k /= i for k in range(a)]
  for j in range(2,min(b))
      d=[b[l]%j for l in range(n-1)]
      if sum(d) ==0:
         c[i]=j
print(max(c))

Submission status: Runtime Error

Solution code:
n=input()
a=list(map(int,input().split))
c=[1]*n
for i in range(n)
  b=[a[k] if k /= i for k in range(a)]
  for j in range(2,min(b))
     for l in range(n-1)
     if b[l] %  j ==0:
      c[i]=j
print(max(c))

Submission status: Runtime Error

Solution code:
n=input()
a=list(map(int,input().split))
c=[1]*n
for i in range(n)
  b=[k if k /= i for k in range(a)]
  for j in range(1,min(b))
     for l in range(n-1)
     if b[l] %  j ==0:
      c[i]=j
print(max(c))

Submission status: Runtime Error

Solution code:
n=input()
a=list(map(int,input().split))
c=[1]*n
for i in range(n)
b=[k if k /= i for k in range(a)]
for j in range(1,min(b))
for l in range(n-1)
if b[l] %  j ==0:
  c[i]=j
print(max(c))

Submission status: Runtime Error

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

gcd_max=1

import functools
import math

for i in range(N):
    a = A.popleft()
    gcd_max = max(gcd_max, functools.reduce(math.gcd, A))
    A.append(a)

print(gcd_max)

Submission status: Runtime Error

Solution code:
from collections import deque
from copy import copy

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

def gcd_of_array(_array):
    _array_copy = copy(_array)
    array_of_gcd = deque([])
    n = len(_array_copy)
    if n == 1:
        return _array[0]
    if n % 2 == 1:
        a = _array_copy.pop()
        array_of_gcd.append(a)
    for i in range(0,N-1,2):
        array_of_gcd.append(gcd(_array_copy.pop(),_array_copy.pop()))

    return gcd_of_array(array_of_gcd)

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

gcd_max=1

for i in range(N):
    a = A.popleft()
    gcd_max = max(gcd_max, gcd_of_array(A))
    A.append(a)

print(gcd_max)

Submission status: Runtime Error

Solution code:
from collections import deque
from copy import copy
from copy import deepcopy

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

def gcd_of_array(_array):
    _array_copy = _array.copy()
    array_of_gcd = deque([])
    n = len(_array_copy)
    if n == 1:
        return _array[0]
    if n % 2 == 1:
        a = _array_copy.pop()
        array_of_gcd.append(a)
    for i in range(0,N-1,2):
        array_of_gcd.append(gcd(_array_copy.pop(),_array_copy.pop()))

    return gcd_of_array(array_of_gcd)

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

gcd_max=1

for i in range(N):
    a = A.popleft()
    gcd_max = max(gcd_max, gcd_of_array(A))
    A.append(a)

print(gcd_max)

Submission status: Runtime Error

Solution code:
from math import gcd
N = int(input())
A = list(map(int,input().split()))
top = [0]*(N+1)
bot = [0]*(N+1)
for i in range(N):
    top[i+1] = gcd(top[i],A[i])
    bot[N-i-1]= gcd(bot[N-i],A[N-i-1])
# print(top,bot)
ans = 0
for i in range(N):
    # print(gcd(top[i], bot[i + 1]))
    ans = max(ans,gcd(top[i],bot[i+1]))
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
x=[]

for i in range(n):
  for j in range(i+1,n):
      x.append(a[i]%a[j])

y=[]
if str(x).count('0')==n+1:
  print(a[-2])
elif len(x)==1:
  if x==[0]:
    print(a[0])
  else:
    print(x[0])
else:
  for i in range(n):
    cnt=0
    for j in range(n):
      if a[j]%x[i]==0:
        cnt+=1
      if cnt>=n-1:
        y.append(x[i])
  print(max(y))

Submission status: Runtime Error

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

import numpy as np
import fractions as frc
from functools import reduce
from copy import deepcopy

x2=deepcopy(x)

def gcd_list(lst):
    return reduce(frc.gcd, lst)

while True:
	n=len(x)
	g=[]
	if n<=5:
		if n==2:
			res=max(x)
			break
		else:
			for i in range(n):
				f=[]
				for j in range(n):
					if j!=i:            
						f.append(x[j])
				g.append(gcd_list(f))
			idx=np.argmax(g)
			rm=x[idx]
			x3=[c for c in x2 if c!=rm]
			res=gcd_list(x3)
			break
	sp=n//2
	y=x[:sp]
	z=x[sp:]
	y_gcd=gcd_list(y)
	z_gcd=gcd_list(z)
	if y_gcd>z_gcd:
		x=z
	else:
		x=y

print(res)

Submission status: Runtime Error

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

import numpy as np
import fractions as frc
from functools import reduce
from copy import deepcopy

x2=deepcopy(x)

def gcd_list(lst):
    return reduce(frc.gcd, lst)

while True:
	n=len(x)
	g=[]
	if n<=5:
		if n==2:
			res=max(x)
			break
		else:
			for i in range(n):
				f=[]
				for j in range(n):
					if j!=i:            
						f.append(x[i])
				g.append(gcd_list(f))
			idx=np.argmax(g)
			rm=x[idx]
			x3=[c for c in x2 if c!=rm]
			res=gcd_list(x3)
			break
	sp=n//2
	y=x[:sp]
	z=x[sp:]
	y_gcd=gcd_list(y)
	z_gcd=gcd_list(z)
	if y_gcd>z_gcd:
		x=z
	else:
		x=y

print(res)

Submission status: Runtime Error

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

import numpy as np
import fractions as frc
from functools import reduce
from copy import deepcopy

x2=deepcopy(x)

def gcd_list(lst):
    return reduce(frc.gcd, lst)

while True:
	n=len(x)
	g=[]
	if n<=5:
		if n==2:
			res=max(x)
			break
		else:
			for i in range(n):
				f=[c for c in x if c!=x[i]]
				g.append(gcd_list(f))
			idx=np.argmax(g)
			rm=x[idx]
			x3=[c for c in x2 if c!=rm]
			res=gcd_list(x3)
			break
	sp=n//2
	y=x[:sp]
	z=x[sp:]
	y_gcd=gcd_list(y)
	z_gcd=gcd_list(z)
	if y_gcd>z_gcd:
		x=z
	else:
		x=y

print(res)

Submission status: Runtime Error

Solution code:
#-*- using:utf-8 -*-

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

def gcd(a,b):
#    print("gcd %d %d" %(a,b))
    n = 0
    if a == b:
        return a
    elif a > b:
        n = euclidean(a,b)

    elif a < b:
        n = euclidean(b,a)

    else:
        pass

    return n

def left(i,a):
    cd = 0
    for p in range(i):
        #cd0 = left(0) = 0
        #cd1 = left(1) = gcd(cd0,a[0])
        #cd2 = left(2) = gcd(cd1,a[1])
#        print("left %d %d" %(cd,a[p]))
        cd = gcd(cd,a[p])
#        print("left %d" %cd)
    return cd

def right(i,a):
    cd = 0
    for p in range(i,m)[::-1]:
        #cdn+1 = right(n+1) = 0
        #cdn   = right(n)   = gcd(cdn+1,a[n])
        #cdn-1 = right(n-1) = gcd(cdn,a[n-1])
#        print("right %d %d" %(cd,a[p]))
        cd = gcd(cd,a[p])
#        print("right %d" %cd)
    return cd

def blackboard(n,a):
    candidate = 0
    maxnum = 0
    b = list(map(int,a))

    p = m // 2 # round down
    q = -(-m // 2) #round up
#    print("i %d j %d" %(p,q))
    maxnum = gcd(left(p,b),right(q,b))

    return maxnum
  
  if __name__ == '__main__':
    n = raw_input()
    a = raw_input().split()
    global m
    m = int(n)
    print("%d" %(blackboard(m,a)))

Submission status: Runtime Error

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

#最大公約数を求めるfunction
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a  

def gcd_list(list,N):
  a = list[0]
  for i in range(1, N):
      b = gcd(a, list[i])
  return b

for i in range(N):
  newA = copy.copy(A)
  if i != N-1:
    newA[i] = newA[i+1]
  else:
    newA[i] = newA[i-1]
  ans = max(gcd_list(newA,N),ans)
print(ans)

Submission status: Runtime Error

Solution code:
from fractions import*
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
for i in range(N):
    C=A.copy()
    del C[i]
    if len(C)==1:
        print(max(A))
        exit()
    B[i]=gcd(*C)
print(max(B))

Submission status: Runtime Error

Solution code:
from fractions import*
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
for i in range(N):
    C=A.copy()
    del C[i]
    print(C)
    B[i]=gcd(*C)
print(max(B))

Submission status: Runtime Error

Solution code:
import fractions as f
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
for i in range(N):
    C=A.copy()
    del C[i]
    print(C)
    B[i]=f.gcd(*C)
print(max(B))

Submission status: Runtime Error

Solution code:
import math
import numpy as np
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
for i in range(N):
    C=A.copy()
    del C[i]
    print(C)
    B[i]=math.gcd(*C)
print(max(B))

Submission status: Runtime Error

Solution code:
import math
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
for i in range(N):
    C=A.copy()
    del C[i]
    print(C)
    B[i]=math.gcd(*C)
print(max(B))

Submission status: Runtime Error

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

L = [0]
g = 0
for i in range(N-1):
    g = math.gcd(g, A[i])
    L.append(g)

R = []
g = 0
for i in range(N-1):
    g = math.gcd(g, A[N-1-i])
    R.append(g)
R.reverse()
R.append(0)

ans = 0
for i in range(N):
    ans = max(ans, math.gcd(L[i],R[i]))

print(ans)

Submission status: Runtime Error

Solution code:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    A = sorted(list(map(int, sys.stdin.readline().split())))
    if n==2:
        print(gcd(*A))
    else:
        ans = gcd(*A[1:n])
        p = A.pop(1)
        temp_ans = gcd(*A)
        if temp_ans > ans:
            ans = temp_ans
        print(ans)

    # else:
    #     ans = gcd(*A[1:n])
    #     for i in range(n):
    #         p = A.pop(i)
    #         temp_ans = gcd(*A)
    #         if temp_ans > ans:
    #             ans = temp_ans
    #         A.insert(i,p)
    #     print(ans)

Submission status: Runtime Error

Solution code:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    if n==2:
        print(gcd(*A))
    else:
        ans = gcd(*A[1:n])
        for i in range(n):
            p = A.pop(i)
            temp_ans = gcd(*A)
            if temp_ans > ans:
                ans = temp_ans
            A.insert(i,p)
        print(ans)

Submission status: Runtime Error

Solution code:
import fractions

N = int(input())
A = list(map(int, input().split()))
L = [0] * (N+1)
R = [0] * (N+2)
M = [0] * (N+1)

for i in range(1, N+1):
  L[i] = fractions.gcd(L[i-1], A[i-1])
  R[N-i+] = fractions.gcd(R[N-i+2], A[i-1])

for i in range(1, N+1):
  M[i] = fractions.gcd(L[i], R[i+1])

print(max(M[1:]))

Submission status: Runtime Error

Solution code:
import fractions

N = int(input())
A = list(map(int, input().split()))
L = [0] * (N+1)
R = [0] * (N+2)
M = [0] * (N+1)

for i in range(1, N+1):
  L[i] = fractions.gcd(L[i-1], A[i])
  R[N-i] = fractions.gcd(R[N-i+1], A[i])

for i in range(1, N+1):
  M[i] = fractions.gcd(L[i], R[i+1])

print(max(M[1:]))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N=int(input())
A=list(map(int,input().split()))
from fractions import gcd
from functools import reduce
minimumgcd=10**10
Agcd=A[0]
for i in range(1,N):
    Agcd=gcd(Agcd,A[i])
    if minimumgcd>Agcd:
        minimumgcd=Agcd
        Achange=i
B=A[:Achange]+A[Achange+1:]
C=A[1:]

minimumgcd=10**10
A=B
Agcd=A[0]
for i in range(1,N-1):
    Agcd=gcd(Agcd,A[i])
    if minimumgcd>Agcd:
        minimumgcd=Agcd
        Bchange=i
D=A[:Bchange]+A[Bchange+1:]+[A[Achange]]

print(max(reduce(gcd,B),reduce(gcd,C),reduce(gcd,D)))

Submission status: Runtime Error

Solution code:
import fractions as f

N = int(input())

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

rightGCD = []
leftGCD = []

rightGCD.append(0)
rightGCD.append(A[0])
tmp = A[0]
for x in A[2:]:
    tmp = f.gcd(tmp,x)
    rightGCD.append(tmp)

leftGCD.insert(0,0)
leftGCD.insert(0,A[-1])
tmp = A[-1]
for x in A[1:N-3:-1]:
    tmp = f.gcd(tmp,x)
    leftGCD.insert(0,tmp)

ans = 0

for i in range(N):
    if i==0:
        ans = max(ans,leftGCD[i])
        continue
    if i==N-1:
        ans = max(ans,rightGCD[i])
        continue

    ans = max(ans,f.gcd(rightGCD[i],leftGCD[i]))

#print(leftGCD)
#print(rightGCD)
print(ans)