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 fractions import gcd

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

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

bwd = [A[-1]]
for i in range(N-2, -1, -1):
    bwd.append(gcd(bwd[-1], A[i]))
bwd.reverse()

gmax = max(fwd[-2], bwd[1])
for i in range(1, N-1):
    gmax = max(gmax, gcd(fwd[i-1], bwd[i+1]))

print(gmax)

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

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

bwd = [A[-1]]
for i in range(N-2, -1, -1):
    bwd.append(gcd(bwd[-1], A[i]))
bwd.reverse()

gmax = max(fwd[-2], bwd[1])
for i in range(1, N-1):
    g = gmax = max(gmax, gcd(fwd[i-1], bwd[i+1]))

print(gmax)

Submission status: Runtime Error

Solution code:
from math import gcd

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

g = 0
for i in range(n):
    g = gcd(a[i], g)
    fw[i] = g

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

gmax = max(bw[1], fw[n-2])
for i in range(1, n-1):
    g = gcd(fw[i-1], bw[i+1])
    if gmax < g:
        gmax = g

print(gmax)

Submission status: Runtime Error

Solution code:
import fractions
import functools
import numpy as np

N = int(input())
A_array = [int(A_i_str) for A_i_str in set(input().split())]

scores = [0 for i in range(N)]
gcds = {}
for i, A_i in enumerate(A_array):
  for j, A_j in enumerate(A_array[i + 1:]):
    A_max = max(A_i, A_j)
    A_min = min(A_i, A_j)
    idx = (A_min, A_max)

    if idx in gcds:
      gcd = gcds[idx]
    else:
      gcd = fractions.gcd(A_i, A_j)
      gcds[idx] = gcd

    scores[i] = scores[i] + gcd
    scores[i + j + 1] = scores[i + j + 1] + gcd

min_score = scores[0]
min_score_idx = 0
for i, score in enumerate(scores):
  if score < min_score or (score == min_score and A_array[i] < A_array[min_score_idx]):
    min_score = score
    min_score_idx = i

A_array.pop(min_score_idx)
print(functools.reduce(fractions.gcd, A_array))

Submission status: Runtime Error

Solution code:
from math import gcd

def cR(A, i):
    if i == len(A):
        return 0
    else:
        g = 0
        for i in range(i, len(A)):
            g = gcd(g, A[i])
        return g

def cL(A, i):
    if i == 1:
        return 0
    else:
        g = 0
        for i in range(i+1):
            g = gcd(g, A[i])
        return g


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

g = A[n-1]
for i in range(n-1, -1, -1):
    R[i] = gcd(g, A[i])

g = A[0]
for i in range(1,n+1):
    L[i] = gcd(g, A[i-1])

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

# print(L, R, M)
print(max(M))

Submission status: Runtime Error

Solution code:
import math
def gcd(a,b):
    if a == 0 or b == 0:
        return max(a,b)
    else:
        return math.gcd(a,b)


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

L = [0]
R = [0]
for i in range(N):
    L.append(gcd(L[-1],A[i]))
    R = [gcd(R[0],A[N-1-i])] + R
M = [gcd(i,j) for i,j in zip(L[:-1],R[1:])]
print(max(M))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

ans = 0
b = []
for i in range(n):
   b = a[:]
   b.pop(i)
   ans = max(ans,gcd_list(b))

print(ans)

Submission status: Runtime Error

Solution code:
N = raw_input()
A = raw_input()

N = int(N)

Aa = A.split(" ")
Aa = map(lambda x: int(x), Aa)

divs = []

W = []
for a in Aa:
  div = []
  for i in range(1,a+1):
    if a % i == 0:
      div.append(i)
      W.append(i)
  m = max(div)
  divs.append(div)

W = sorted(W)

sets = list(sorted(set(W)))

max_cnt = N - 1
for w in reversed(sets):
  cnt = W.count(w)
  if max_cnt <= cnt :
    break

print(w)

Submission status: Runtime Error

Solution code:
from math import 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)

    divisors.sort()
    return divisors

N = int(input())
A = list(map(int,input().split()))
l = []
setl = []
for i in range(N):
    l.append(make_divisors(A[i]))
    setl = sorted(list(set(setl + l[i])))
cntl = [0 for i in range(len(setl))]

for i in range(N):
    for j in range(len(l[i])):
        cntl[setl.index(l[i][j])] += 1

setl.reverse()
cntl.reverse()
for i in range(len(cntl)):
    if cntl[i] == N or cntl[i] == N-1:
        print(str(setl[i]))
        break

Submission status: Runtime Error

Solution code:
from math import 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)

    divisors.sort()
    return divisors

N = int(input())
A = list(map(int,input().split()))
l = []
setl = []
for i in range(N):
    l.append(make_divisors(A[i]))
    setl = sorted(list(set(setl + l[i])))
cntl = [0 for i in range(len(setl))]

for i in range(N):
    for j in range(len(l[i])):
        cntl[setl.index(l[i][j])] += 1

setl.reverse()
cntl.reverse()
for i in range(len(cntl)):
    if cntl[i] == N or cntl[i] == N-1:
        print(str(setl[i]))
        exit()

Submission status: Runtime Error

Solution code:
from math import 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)

    divisors.sort()
    return divisors

N = int(input())
A = list(map(int,input().split()))
l = []
setl = []
for i in range(N):
    l.append(make_divisors(A[i]))
    setl = sorted(list(set(setl + l[i])))
cntl = [0 for i in range(len(setl))]
for i in range(N):
    cntl[i] = 0
    for j in range(len(l[i])):
        cntl[setl.index(l[i][j])] += 1

setl.reverse()
cntl.reverse()
for i in range(len(setl)):
    if cntl[i] == N or cntl[i] == N-1:
        print(str(setl[i]))
        exit()

Submission status: Runtime Error

Solution code:
import math
import functools
import fractions
from functools import reduce
import itertools
gcd3 = 0
gcd4 = 0
ans = 0
N = int(input())
values = ([int(x) for x in input().split()])

divided_values = [values[i::2] for i in range(2)]

values1 = divided_values[0].copy()
values2 = divided_values[1].copy()
gcd1 = functools.reduce(fractions.gcd,values1)
gcd2 = functools.reduce(fractions.gcd,values2)

for i in range(len(values1)):
  tem = values1.pop(i)
  gcd3 = fractions.gcd(gcd2,functools.reduce(fractions.gcd,values1))
  values1.insert(i,tem)
  if gcd3>gcd4:
    gcd4 = gcd3
    ans = gcd3

if len(values2)>1:
  for i in range(len(values2)):
    tem = values2.pop(i)
    gcd3 = fractions.gcd(gcd1,functools.reduce(fractions.gcd,values2))
    values2.insert(i,tem)
    if gcd3>gcd4:
      gcd4 = gcd3
      ans = gcd3
    
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# AtCoder Beginner Contest 125
# C - GCD on Blackboard

# 最大公約数を計算
# ユークリッドの互除法を用いる
def gcd(x, y):
    while x != y:
        x, y = (x-y,y) if x>y else (y-x,x)
    return x

# N個の整数に対する最大公約数の計算
def calc(n, an):
    if n == 2:
        return gcd(an[0], an[1])
    else:
        return gcd(an[0], calc(n-1, an[1:]))


n = int(input())
an = [int(x) for x in input().split(' ')]

if n == 2:
    print(max(an))
else:
    #N-1個の組み合わせに対する最大公約数で最大のものを選ぶ
    # N-1個の組み合わせ
    bn = [[an[j] for j in range(n) if i != j] for i in range(n)]
    gcds = [calc(n-1, ary) for ary in bn]
    print(max(gcds))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# AtCoder Beginner Contest 125
# C - GCD on Blackboard

# N-1個の全パターンの最大公約数の最大値でOK

# 最大公約数を計算
# ユークリッドの互除法を用いる
def gcd(x, y):
    # 大きい方をaに
    a, b = (x,y) if x>y else (y,x)
    if a == b:
        return a
    else:
        return gcd(a-b,b)

# N個の整数に対する最大公約数の計算
def calc(n, an):
    if n == 2:
        return gcd(an[0], an[1])
    else:
        return gcd(an[0], calc(n-1, an[1:]))


n = int(input())
an = [int(x) for x in input().split(' ')]

if n == 2:
    print(max(an))
else:
    #N-1個の組み合わせに対する最大公約数で最大のものを選ぶ
    # N-1個の組み合わせ
    bn = [[an[j] for j in range(n) if i != j] for i in range(n)]
    gcds = [calc(n-1, ary) for ary in bn]
    print(max(gcds))

Submission status: Runtime Error

Solution code:
# 最大公約数を計算
# ユークリッドの互除法を用いる
def gcd(x, y):
    # 大きい方をaに
    a, b = (x,y) if x>y else (y,x)
    if a == b:
        return a
    else:
        return gcd(a-b,b)

# N個の整数に対する最大公約数の計算
def calc(n, an):
    if n == 2:
        return gcd(an[0], an[1])
    else:
        return gcd(an[0], calc(n-1, an[1:]))


n = int(input())
an = [int(x) for x in input().split(' ')]

if n == 2:
    print(max(an))
else:
    #N-1個の組み合わせに対する最大公約数で最大のものを選ぶ
    # N-1個の組み合わせ
    bn = [[j for j in an if i != j] for i in an]
    gcds = [calc(n-1, ary) for ary in bn]
    print(max(gcds))

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
A = list(map(int, input().split()))
C=[]
for i in range(N):
     C.append(copy.copy(A))
B = []
for i in range(N):
    del C[i][i]
    B.append(C[i])
import math
from functools import reduce
D =[] #Aから一つを除いたものの最大公約数のリスト
for i in range(N):
    D.append(reduce(math.gcd,B[i]))
maxi = max(D)
print(maxi)

Submission status: Runtime Error

Solution code:
from math import gcd

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

lgcd, rgcd = [], []
for i in range(n):
    if i == 0:
        lgcd.append(a[0])
        rgcd.append(a[n-1])
        continue

    lgcd.append(gcd(lgcd[i-1], a[i]))
    rgcd.append(gcd(rgcd[i-1], a[-1-i]))

maxgcd = 1
for i in range(n):
    if i == 0:
        tempgcd = rgcd[n-1]
    elif i == n-1:
        tempgcd = lgcd[n-1]
    else:
        tempgcd = gcd(lgcd[i-1], rgcd[n-2-i])
    maxgcd = max(maxgcd, tempgcd)
print(maxgcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

maxgcd = 0
for i in range(len(a)):
    temp = gcd(a[:i] + a[i + 1:])
    if temp > maxgcd:
        maxgcd = temp

print(maxgcd)

Submission status: Runtime Error

Solution code:
import math
n=int(input())
lst=list(map(int,input().split()))
xlst=list(reversed(lst))
#1~5と6のgcdは1~6のgcd
#i番目の左側と右側のgcdを求める
#left[i-1]はlstのi番目までのgcd
#xright[i]はlstのnからi-
#lstのi+1番目は右から見たらn-i+1番目



left=[lst[0]]
xright=[lst[n-1]]
for i in range(1,len(lst)):
    left.append(math.gcd(left[i-1],lst[i]))

for i in reversed(range(0,len(lst)-1)):
    xright.append(math.gcd(xright[n-i-2],lst[i]))

print(xright,left)
#i-1番目までの左からのgcdはleft[i-2]
#i＋1番目以上のgcdは right[i+2]
result=1
for i in range(1,n-1):
    a=math.gcd(left[i-1],xright[n-i-2])
    if a>result:
        result=a
print(max(result,xright[n-2],left[n-2]))

Submission status: Runtime Error

Solution code:
import math
n=int(input())
lst=list(map(int,input().split()))
xlst=list(reversed(lst))
#1~5と6のgcdは1~6のgcd
#i番目の左側と右側のgcdを求める
#left[i-1]はlstのi番目までのgcd
#xright[i]はlstのnからi-
#lstのi+1番目は右から見たらn-i+1番目



left=[lst[0]]
xright=[lst[n-1]]
for i in range(1,len(lst)):
    left.append(math.gcd(left[i-1],lst[i]))

for i in reversed(range(0,len(lst)-1)):
    xright.append(math.gcd(xright[n-i-2],lst[i]))

print(xright,left)
#i-1番目までの左からのgcdはleft[i-2]
#i＋1番目以上のgcdは right[i+2]
result=1
for i in range(1,n-1):
    a=math.gcd(left[i-1],xright[i-1])
    if a>result:
        result=a
print(max(result,xright[n-2],left[n-2]))

Submission status: Runtime Error

Solution code:
import math
n=int(input())
lst=list(map(int,input().split()))
xlst=list(reversed(lst))
#1~5と6のgcdは1~6のgcd
#i番目の左側と右側のgcdを求める
#left[i-1]はlstのi番目までのgcd
#xright[i]はlstのnからi-
#lstのi+1番目は右から見たらn-i+1番目



left=[lst[0]]
xright=[lst[n-1]]
for i in range(1,len(lst)):
    left.append(math.gcd(left[i-1],lst[i]))

for i in reversed(range(0,len(lst)-1)):

    xright.append(math.gcd(xright[n-i-2],lst[i]))


#i-1番目までの左からのgcdはleft[i-2]
#i＋1番目以上のgcdは right[i+2]
result=1
for i in range(n):
    a=math.gcd(left[i-1],xright[i-1])
    if a>result:
        result=a
print(result)

Submission status: Runtime Error

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

def solve():
  n = 3
  a = [7, 6, 8]
  left = [0] * n + 1
  right = [0] * n + 1
  for i in range(1,n + 1):
    left[i] = gcd(left[i - 1], a[i - 1])
  for i in range(n - 1, 0, -1):
    right[i] = gce(right[i + 1], a[i])
  max_gcd = 0
  for i range(n):
    max_gcd = max(max_gcd, gcd(left[i], right[i]))
  print max_gcd
        
if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)


"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


n = ip()                                     #入力整数1つ
#a,b,t= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#k = ip()                      #入力セット(整数改行あり)(1/2)
#v=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
if n==2:
    print(max(a))
else:
    ans = []
    s = [a[0]]
    for i in range(1,n):
        s.append(fractions.gcd(s[i-1],a[i]))
    r = [a[n-1]]
    for i in range(n-2,-1,-1):
        r.append(fractions.gcd(r[i-1],a[i]))
    r = r[::-1]
 #   print(s,"from left")
 #   print(r,"from right")
    ans.append(r[1])
    for i in range(1,n-1):
        ans.append(fractions.gcd(s[i-1],r[i+1]))
    ans.append(s[n-2])
    print(max(ans))

Submission status: Runtime Error

Solution code:
from fractions import gcd

n = int(input())
a = [int(i) for i in input().split()]
l,r,ans = [a[0]],[a[-1]],[gcd(a[0],a[-1])]
if len(a) == 2:
    print(gcd(a[0],a[1]))
    exit()
for i in range(1,n//2+1):
    l.append(gcd(a[i-1],a[i]))
    r.append(gcd(a[n-i],a[n-i-1]))
    ans.append(r[-1])
    ans.append(l[-1])
ans = list(set(ans))
print(ans[1])

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
A = list(map(int, input().split()))
def gcd(x, y):
    d = max(x,y) - min(x,y)
    if d > 0: return d
    else: return x

gcdSet = []
maxGcd = 0
for x in range(N):
    B = copy.deepcopy(A)
    del B[x]
    temp = []
    while len(B) > 1:
        temp.clear()
        for i in range(0,len(B),2):
            if i == len(B) - 1:
                temp.append(B[i])
            else:
                temp.append(gcd(B[i], B[i+1]))
        B.clear()
        B = temp
    gcdSet.append(B[0])
print(max(gcdSet))

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
def gcd(x, y):
    d = max(x,y) - min(x,y)
    if d > 0: return d
    else: return x

gcdSet = []
maxGcd = 0
for x in range(N):
    B = copy.deepcopy(A)
    del B[x]
    temp = []
    while len(B) > 1:
        temp.clear()
        for i in range(0,len(B),2):
            if i == len(B) - 1:
                temp.append(B[i])
            else:
                temp.append(gcd(B[i], B[i+1]))
        B.clear()
        B = temp
        print(B)
    gcdSet.append(B[0])
print(max(gcdSet))

Submission status: Runtime Error

Solution code:
import math

nn = int(input())
aa = list(map(int, input().split()))
gcd_list = list(range(nn))

for ii in range(nn):
    aa2 = [x for x in aa]
    del aa2[ii]
    gcd0 = aa2[0]
    for jj in range(nn-1):
        gcd0 = math.gcd(gcd0, aa2[jj])
    gcd_list[ii] = gcd0
    
gcd = max(gcd_list)
print(gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

nn = int(input())
aa = list(map(int, input().split()))
gcd_list = list(range(nn))

for ii in list(range(nn)):
    aa2 = [x for x in aa]
    del aa2[ii]
    gcd_list[ii] = gcd(*aa2)
    
gcd = max(gcd_list)
print(gcd)

Submission status: Runtime Error

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

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

max = 0

if N <= 2:
  print(max(A))
else:
  for i in range(N):
    temp = A.pop(0)
    ans = gcd(A[0], A[1])
    for j in A[1:]:
      ans = gcd(ans, j)
    if max < ans:
      max = ans
    A.append(temp)
  print(max)

Submission status: Runtime Error

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

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

max = 0

for i in range(N):
  temp = A.pop(0)
  ans = gcd(A[0], A[1])
  for j in A[1:]:
    ans = gcd(ans, j)
  if max < ans:
    max = ans
  A.append(temp)
print(max)

Submission status: Runtime Error

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

max_value = 0

for i in range(n):
    list_temp = copy.copy(list_a)
    del list_temp[i]
    temp=list_temp[0]
    for i in range(n-1):
        temp=math.gcd(temp, list_temp[i])
    if max_value<temp:
        max_value = temp

print(max_value)

Submission status: Runtime Error

Solution code:

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

L = [0]*(N+2)
R = [0]*(N+2)
M = [0]*(N+2)

import fractions

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

M = [gractions.gcd(L[i-1],R[i]) for i in range(1,N+1)]
print(max(M))

Submission status: Runtime Error

Solution code:
import fractions


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

  gcd_l = [0]
  gcd_r = [0]
  for i in range(N):
      gcd_l.append(fractions.gcd(gcd_l[i], A[i]))
      gcd_r.append(fractions.gcd(gcd_r[i], A[-(i+1)]))
  gcd_r = gcd_r[::-1]

  ans = []
  for i in range(N):
      ans.append(fractions.gcd(gcd_l[i], gcd_r[i+1]))
  print(max(ans))

Submission status: Runtime Error

Solution code:
import fractions



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

gcd_l = [0]
gcd_r = [0]
for i in range(N):
    gcd_l.append(fractions.gcd(gcd_l[i], A[i]))
    gcd_r.append(fractions.gcd(gcd_r[i], A[-(i+1)]))
gcd_r = gcd_r[::-1]

ans = []
for i in range(N):
    ans.append(fractions.gcd(gcd_l[i], gcd_r[i+1]))
print(max(ans))

Submission status: Runtime Error

Solution code:
import fractions


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

    gcd_l = [0]
    gcd_r = [0]
    for i in range(N):
        gcd_l.append(fractions.gcd(gcd_l[i], A[i]))
        gcd_r.append(fractions.gcd(gcd_r[i], A[-(i+1)]))
    gcd_r = gcd_r[::-1]

    ans = []
    for i in range(N):
        ans.append(fractions.gcd(gcd_l[i], gcd_r[i+1]))

	print(max(ans))

Submission status: Runtime Error

Solution code:
import copy
from functools import reduce
 
def gcd_list(numbers):
    return reduce(fractions.gcd,numbers)
  
n = int(input())
a = list(map(int,input().split()))
a2 = copy.deepcopy(a)
res = []
for i in range(0,n):
    a2.pop(i)
    res.append(gcd_list(a2))
    a2 = copy.deepcopy(a)
print(max(res))

Submission status: Runtime Error

Solution code:
import fractions


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

    gcd_l = [0]
    gcd_r = [0]
    for i in range(N):
        gcd_l.append(fractions.gcd(gcd_l[i], A[i]))
        gcd_r.append(fractions.gcd(gcd_r[i], A[-(i+1)]))
    gcd_r = gcd_r[::-1]

    ans = []
    for i in range(N):
        ans.append(fractions.gcd(gcd_l[i], gcd_r[i+1]))

print(max(ans))

Submission status: Runtime Error

Solution code:
import copy
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd,numbers)
n = int(input())
a = list(map(int,input().split()))
a2 = copy.copy(a)
res = []
for i in range(0,n):
    a2.pop(i)
    res.append(gcd_list(a2))
    a2 = copy.copy(a)
print(max(res))

Submission status: Runtime Error

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

if N==2:
       print(max(s))

ans_l=[]
i=0
while i<N:
       j=0
       while j<N:
              p=0
              if i!=j:
                     p=math.gcd(s[i],s[j])
                     ans_l.append(p)
              j+=1
       
       i+=1
print(max(ans_l))

Submission status: Runtime Error

Solution code:
import math
N=int(input())
s=list(map(int,input().split()))
print(s)
if N==2:
       print(max(s))

ans_l=[]
i=0
while i<N:
       j=0
       while j<N:
              p=0
              if i!=j:
                     p=math.gcd(s[i],s[j])
                     ans_l.append(p)
              j+=1
       
       i+=1
print(max(ans_l))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import copy

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

n = int(input())

a = list(map(int,input().split()))
a2 = copy.deepcopy(a)
res = []
for i in range(0,n):
    a2.pop(i)
    res.append(gcd(a2))
    a2 = copy.deepcopy(a)
print(max(res))

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
def k(n,x):
    if x==0:
        return n
    else:
        return k(x,n%x)
T=0
for i in a[1:]:
    T=k(i,T)
ans=[T]
TT=0
for i in a[:-1]:
    TT=k(i,TT)
ans+=[TT]
L=[0 for i in range(n)]
R=[0 for i in range(n)]
for i in range(n-2):
    L[i]=k(a[i],L[i-1])
    R[i]=k(a[i+2],R[i-1])
    ans+=[k(L[i],R[i])]
print(max(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
def k(n,x):
    if x==0:
        return n
    else:
        return k(x,n%x)
L=[0 for i in range(n)]
R=[0 for i in range(n)]
T=0
for i in a[1:]:
    T=k(i,T)
ans=[T]
for i in range(n-1):
    L[i]=k(a[i],L[i-1])

    for j in range(i+2,nn=int(input())
a=[int(i) for i in input().split()]
def k(n,x):
    if x==0:
        return n
    else:
        return k(x,n%x)
L=[0 for i in range(n)]
R=[0 for i in range(n)]
T=0
for i in a[1:]:
    T=k(i,T)
ans=[T]
for i in range(n-1):
    L[i]=k(a[i],L[i-1])

    for j in range(i+2,n):
        R[i]=k(a[j],R[i])

    ans+=[k(L[i],R[i])]
print(max(ans))):
        R[i]=k(a[j],R[i])

    ans+=[k(L[i],R[i])]
print(max(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 = map(int,input().split())
a = list(map(int, a))
a1 = a
res = 0
count = 0
count1 = 0
for i in a:
    for j in a1:
        if count != count1 and gcd(i,j)>res:
            res = gcd(i,j)
        count1 = count1 + 1
    count = count + 1
    count1 = 0
print(res)

Submission status: Runtime Error

Solution code:
import math

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

gcd_l = [0] * N

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

gcd_r = [0] * N

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

gcd_lr = [0] * N

for i in range(N):
    if i == 0:
        gcd_lr[i] = gcd_r[i + 1]
    elif 1 <= i <= N - 2:
        gcd_lr[i] = math.gcd(gcd_l[i - 1], gcd_r[i + 1])
    elif i == N - 1:
        gcd_lr[i] = gcd_l[i - 1]

print(max(gcd_lr))

Submission status: Runtime Error

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

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

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

right_gcd=[a_array[-1]]
for i in range(n-2,0,-1):
    b=gcd(b,a_array[i])
    right_gcd.append(b)

ans_gcd=[right_gcd[n-2],left_gcd[n-2]]

for i in range(n-2):
    ans_gcd.append(gcd(left_gcd[i],right_gcd[n-i-3]))

print(max(ans_gcd))

Submission status: Runtime Error

Solution code:
import functools
import math

N = int(input())
A = list(map(int, input().split()))
answer = 0
for i in range(N):
  tmp = A.copy()
  tmp.pop(i)
  gcd = functools.reduce(math.gcd, tmp)
  
  if answer < gcd:
    answer = gcd

print(int(answer))

Submission status: Runtime Error

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

import math
from functools import reduce

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

cnt = 0

for i in range(n):
  tmp = l
  del tmp[i]
  gcd = gcd(tmp)
  
  if gcd > cnt:
    cnt = gcd
  	
print(cnt)

Submission status: Runtime Error

Solution code:
from math import gcd
import itertools

n = int(input())
nums = sorted(list(map(int, input().split())))

gcds = {}
for pair in itertools.combinations(nums, 2):
    gcds[tuple(pair)] = gcd(*pair)

gcds = sorted(set(gcds.values()))
if len(gcds) > 1:
    print(gcds[1])
else:
    print(gcds[0])

Submission status: Runtime Error

Solution code:
from math import gcd
import itertools

n = int(input())
nums = sorted(list(map(int, input().split())))

gcds = {}
for pair in itertools.combinations(nums, 2):
    gcds[tuple(pair)] = gcd(*pair)

print(list(set(gcds.values())).pop(1))

Submission status: Runtime Error

Solution code:

# coding: utf-8

# In[1]:

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


# In[2]:

#import copy
#import numpy as np
try:
    from fraction import gcd
except:
    from math import gcd


# In[ ]:

# 左からn個の最大公約数を求める O(n)
# 右からn個の最大公約数を求める O(n)
# n個目を抜いた最大公約数は n-1個目までの公約数とn+1個目からの公約数との公約数


# In[3]:

lg = [1]*(N)
rg = [1]*(N)
ans = 0


# In[4]:

#print(lg)
#print(rg)
#print(A)


# In[5]:

lg[0] = A[1]
rg[0] = A[N-2]
lg[1] = A[0]
rg[1] = A[N-1]
#print(lg, rg)
for i in range(1, N-1):
    #print(i)
    lg[i+1] = gcd(lg[i], A[i])
    #print(lg[i], A[i])
    rg[i+1] = gcd(rg[i], A[N-1-i])
    #print(rg[N-1-i], A[N-1-i])
#print(lg, rg)

for i in range(N):
    #print(i, lg[i], rg[N-i-1])
    tmp = gcd(lg[i], rg[N-i-1])
    #print(tmp)
    if ans < tmp:
        ans = tmp
    #print(ans)


# In[6]:

print(ans)


# In[ ]:

"""
[42 54 69 92 12 23]のとき
 1 [54 69 92 12 23]の最大公約数
 2 [42 69 92 12 23]
 3 [42 54 92 12 23]
 4 [42 54 69 12 23]

"""

Submission status: Runtime Error

Solution code:
from math import gcd

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

fore_gcd = [data[0]]
for i in data[1:-1]:
    fore_gcd.append(gcd(fore_gcd[-1], i))

back_gcd = [data[-1]]
for i in data[::-1][1:-1]:
    back_gcd.append(gcd(back_gcd[-1], i))

gcd_list = [fore_gcd[-1]]
for fore, back in zip(fore_gcd[::-1][1:], back_gcd[:-1]):
    gcd_list.append(gcd(fore, back))
gcd_list.append(back_gcd[-1])

print(max(gcd_list))

Submission status: Runtime Error

Solution code:

# coding: utf-8

# In[ ]:

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


# In[ ]:

import copy
#import numpy as np


# In[3]:

def get_divisor_list(A):
    divisor_list = [1]
    if A == 1:
        return divisor_list
    else:
        for i in range(2, A//2+1):
            if A%i == 0:
                divisor_list.append(i)
        divisor_list.append(A)
        return divisor_list


# In[4]:

all_db = []
for i in range(N):
    all_db.append(set(get_divisor_list(A[i])))
#print(all_db)


# In[5]:

gcd_list = []
for i in range(N):
    all_dbc = copy.copy(all_db)
    all_dbc.pop(i)
    gcds = all_dbc[0].intersection(*all_dbc)
    gcd_list.append(max(gcds))
print(max(gcd_list))


# In[ ]:

Submission status: Runtime Error

Solution code:

# coding: utf-8

# In[1]:

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


# In[2]:

import copy
#import numpy as np


# In[3]:

def get_divisor_list(A):
    divisor_list = [1]
    if A == 1:
        return divisor_list
    else:
        for i in range(2, A//2+1):
            if A%i == 0:
                divisor_list.append(i)
        divisor_list.append(A)
        return divisor_list


# In[4]:

all_db = []
for i in range(N):
    all_db.append(set(get_divisor_list(A[i])))
#print(all_db)


# In[5]:

gcd_list = []
for i in range(N):
    all_dbc = copy.copy(all_db)
    all_dbc.pop(i)
    gcds = {all_db}.intersection(*all_dbc)
    gcd_list.append(max(gcds))
print(max(gcd_list))


# In[7]:

set().intersection({1, 2, 3})


# In[ ]:

"""
try:
    from math import gcd as ogcd
except:
    from fractions import gcd as ogcd
from functools import reduce

def gcd(*numbers):
    return reduce(ogcd, numbers)
"""


# In[4]:

"""
gcd_list = []
for i in range(N):
    Ac = copy.copy(A)
    Ac.pop(i)
    #print(Ac)
    gcd_list.append(gcd(*Ac))
"""


# In[5]:

#print(np.max(np.array(gcd_list)))


# In[ ]:

Submission status: Runtime Error

Solution code:
import sys
from math import gcd

def input():
	return sys.stdin.readline()

N = int(input())
A = [int(_) for _ in input().split()]
p1 = [0] * N
p2 = [0] * N

p1[0] = A[0]
p2[-1] = A[-1]

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

m = max(p1[-2], p2[1])

if N > 2:
	for i in range(1, N-1):
		m = max(m, gcd(p1[i-1], p2[i+1]))

print(m)

Submission status: Runtime Error

Solution code:

# coding: utf-8

# In[17]:

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


# In[21]:

import copy
import numpy as np


# In[6]:

import math
from functools import reduce

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


# In[26]:

gcd_list = []
for i in range(N):
    Ac = copy.copy(A)
    Ac.pop(i)
    #print(Ac)
    gcd_list.append(gcd(*Ac))


# In[ ]:

print(np.max(np.array(gcd_list)))

Submission status: Runtime Error

Solution code:

#NOT AC

import functools
import math

# 整数の入力
n = input()
n = int(n)

# いくつあるかわからないときのスペース区切りの整数の入力
a = input().split()
a = list(map(int,a))

gcdlist = [0] * n

i = 0
for i in range(0,n):
    check = [0] * n
    check[:] = a[:] #リストのコピーの時の作法
    del check[i]
    gcdlist[i] = functools.reduce(math.gcd, check)

#print(gcdlist)

j = max(gcdlist)

print(j)

#a[j] = gcdlist[j]

#print(functools.reduce(math.gcd,a))

Submission status: Runtime Error

Solution code:
import functools
import math

# 整数の入力
n = input()
n = int(n)

# いくつあるかわからないときのスペース区切りの整数の入力
a = input().split()
a = list(map(int,a))

gcdlist = [0] * n

i = 0
for i in range(0,n):
    check = [0] * n
    check[:] = a[:] #リストのコピーの時の作法
    del check[i]
    gcdlist[i] = functools.reduce(math.gcd, check)

#print(gcdlist)

j = gcdlist.index(max(gcdlist))

print(j)