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:
#!/usr/bin/env python3
import sys
import fractions
import math


def solve(N: int, A: "List[int]"):
    L = []
    last = A[0]
    for i in range(N):
        last = math.gcd(last, A[i])
        L.append(last)
    last = A[-1]
    R = []
    for i in range(1, N+1):
        last = math.gcd(last, A[-i])
        R.append(last)
    R.reverse()
    maxGCD = max(L[-2], R[-2])
    for i in range(1, N-1):
        maxGCD = max(math.gcd(L[i-1], R[i+1]), maxGCD)
    print(maxGCD)
    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 math


def solve(N: int, A: "List[int]"):
    L = []
    last = A[0]
    for i in range(N):
        last = math.gcd(last, A[i])
        L.append(last)
    last = A[-1]
    R = []
    for i in range(1, N+1):
        last = math.gcd(last, A[-i])
        R.append(last)
    maxGCD = max(L[-2], R[-2])
    for i in range(0, N-1):
        maxGCD = max(math.gcd(L[i], R[i]), maxGCD)
    print(maxGCD)
    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:
list_v = []
list_c = []

N = int(input("宝石の個数:"))

for i in range(N):
    v = int(input("{}番目の宝石の数: ".format(i+1)))
    list_v.append(v)

for i in range(N):
    c= int(input("{}番目の宝石の数: ".format(i+1)))
    list_c.append(c)

result = 0

for i in range(N):
    if (list_v[i] - list_c[i]) > 0:
        result += (list_v[i] - list_c[i])

print(result)

Submission status: Runtime Error

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

L=[0]*(n+1)
R=[0]*(n+1)
ans=0
for i in range(n):
    L[i]=math.gcd(L[i-1],a[i])
for i in reversed(range(n)):
    R[i]=math.gcd(R[i-1],a[i])
for i in range(n):
    if math.gcd(L[i-1],R[i+1]) > ans:
        ans=math.gcd(L[i-1],R[i-1])

print(ans)

Submission status: Runtime Error

Solution code:
#Coding: Utf-8

#ランダムな数字に置換
num=0
a=[]
N= int(input())
a=list(map(str, input().split()))


#最大公約数の計算
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

if len(a)>2:
    c= gcd(a[0],a[1])
    if len(a)>2:
        for i in range(2,N-2):
            c=gcd(c,a[i])
    print(c)

Submission status: Runtime Error

Solution code:
#最大公約数の計算
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

c= gcd(a[0],a[1])
if len(a)>2:
    for i in range(2,N-2):
        c=gcd(c,a[i])

print(c)

Submission status: Runtime Error

Solution code:
import copy

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

def cal(array):
  while(len(array) > 1):
    a = array.pop(0)
    b = array.pop(0)
    array.append(gcd(a, b))
  return array[0]

n = input()
a = input().split()
a = map(lambda x: int(x), a)

answer_list = []

for i in range(int(n)):
  copy_a = copy.copy(a)
  copy_pop_a = copy_a.pop(i)
  answer_list.append(cal(copy_a))

answer = max(answer_list)

print(answer)

Submission status: Runtime Error

Solution code:
def gcd(x, y):
    """
    ユークリッドの互除法を用いて最大公約数を求める
    """
    if not x:
        return y
    return gcd(y % x, x)

def dfs(L, A):
    if not len(L):
        return A
    return gcd(dfs(L[:-1], L[-1]), A)

def get_M_i(A, i):
    """
    i番目のAを取り除いて得られる最大公約数を返す
    """
    L = dfs(A[:i-1], A[i-1]) if i > 0 else 0
    R = dfs(A[i+1:-1], A[-1]) if i+1 < len(A) else 0
    return gcd(L, R)

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

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

    else:
        # i番目のMの値はi番目のAを取り除いて得られるN-1個の整数の最大公約数
        M = [0 for _ in range(N)]

        for i in range(N):
            M[i] = get_M_i(A, i)

        print(max(M))

Submission status: Runtime Error

Solution code:
def gcd(x, y):
    """
    ユークリッドの互除法を用いて最大公約数を求める
    """
    if not x:
        return y
    return gcd(y % x, x)

def dfs(L, A):
    if not len(L):
        return A
    return gcd(dfs(L[:-1], L[-1]), A)

def get_M_i(A, i):
    """
    i番目のAを取り除いて得られる最大公約数を返す
    """
    L = dfs(A[:i-1], A[i-1]) if i > 0 else 0
    R = dfs(A[i+1:-1], A[-1]) if i+1 < len(A) else 0
    return gcd(L, R)

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

    # i番目のMの値はi番目のAを取り除いて得られるN-1個の整数の最大公約数
    M = [0 for _ in range(N)]

    for i in range(N):
        M[i] = get_M_i(A, i)

    print(max(M))

Submission status: Runtime Error

Solution code:
def gcd(x, y):
    """
    ユークリッドの互除法を用いて最大公約数を求める
    """
    if not x:
        return y
    return gcd(y % x, x)

def dfs(L, A):
    if not len(L):
        return A
    return gcd(dfs(L[:-1], L[-1]), A)

def get_M_i(A, i):
    """
    i番目のAを取り除いて得られる最大公約数を返す
    """
    L = dfs(A[:i-1], A[i-1]) if i > 0 else 0
    R = dfs(A[i+1:-1], A[-1]) if i < len(A) else 0
    return gcd(L, R)

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

    # i番目のMの値はi番目のAを取り除いて得られるN-1個の整数の最大公約数
    M = [0 for _ in range(N)]

    for i in range(N):
        M[i] = get_M_i(A, i)

    print(max(M))

Submission status: Runtime Error

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

gcd_from_the_left = []
gcd_from_the_left.append(values[0])
for i in range(N):
	gcd_from_the_left.append(fractions.gcd(gcd_from_the_left[i],values[i]))
gcd_from_the_left.pop(0)

gcd_from_the_right = []
gcd_from_the_right.append(values[-1])
for i in range(N):
	gcd_from_the_right.append(fractions.gcd(gcd_from_the_right[i],values[-i-1]))

gcd_from_the_right.pop(0)

ans = 0
gcd = 0

for i in range(N):
  gcd = fractions.gcd(gcd_from_the_left[i],gcd_from_the_right[-(N-3+i)])
  if gcd > ans:
    ans = gcd
    
gcd = gcd_from_the_left[-2]
if gcd > ans:
  ans = gcd
gcd = gcd_from_the_right[-2]
if gcd > ans:
  ans = gcd
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
from functools import reduce

N = int(input())
A = np.array(list(map(int, input().split())))
Ans = np.zeros((N),dtype = 'int')

for i in range (N):
    data = np.delete(A, i)
    Ans[i] =  reduce(math.gcd, data)

print(max(Ans))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
from functools import reduce

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

N = int(input())
A = np.array(list(map(int, input().split())))
Ans = np.zeros((N),dtype = 'int')

for i in range (N):
    data = np.delete(A, i)
    Ans[i] =  gcd_list(data)

print(max(Ans))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
from functools import reduce

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

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

Ans = np.zeros((N),dtype = 'int')

for i in range (N):
    data = np.delete(A, i)
    Ans[i] =  gcd_list(data)

print(max(Ans))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
from functools import reduce

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

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

Ans = np.zeros((N),dtype = 'int')

for i in range (N):
    data = np.delete(A, i)
    print(data)
    Ans[i] =  gcd_list(data)
    print(Ans[i])

print(max(Ans))

Submission status: Runtime Error

Solution code:
import copy 

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

N = int(input())
T = list(map(int,input().split()))
T.sort()
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
GCD = 0
GCD += LIS[N-1]
if N == 2:
    ANS = max(T[0],T[1])
else:
    #第１項がtarget
    S = copy.copy(T)
    S.pop(0)
    LS = [0]*(N-1)
    LS[0] += S[0]
    for i in range(N-2):
        LS[i+1] += gcd(LS[i],S[i+1])
    ANSA = LS[N-2]

    #その他の場合
    LJ = []
    for i in range(N-1):
        if LIS[i] != LIS[i+1]:
            LJ.append(i+1)

    LK = []
    for j in range(len(LJ)):
        U = copy.copy(T)
        U.pop(LJ[j])
        LS = [0]*(N-1)
        LS[0] += U[0]
        for i in range(N-2):
            LS[i+1] += gcd(LS[i],U[i+1])
        LK.append(LS[N-2])
    ANSB = max(LK)
    ANS = max(ANSA,ANSB)
print(ANS)

Submission status: Runtime Error

Solution code:
import copy 

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

N = int(input())
T = list(map(int,input().split()))
T.sort()
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
GCD = 0
GCD += LIS[N-1]
if N == 2:
    ANS = max(T[0],T[1])
else:
    #第１項がtarget
    S = copy.copy(T)
    S.pop(0)
    LS = [0]*(N-1)
    LS[0] += S[0]
    for i in range(N-2):
        LS[i+1] += gcd(LS[i],S[i+1])
    ANSA = LS[N-2]

    #その他の場合
    LJ = []
    for i in range(N-1):
        if LIS[i] != LIS[i+1]:
            LJ.append(i+1)

    LK = []
    for j in range(len(LJ)):
        U = copy.copy(T)
        U.pop(LJ[j])
        LS = [0]*(N-1)
        LS[0] += U[0]
        for i in range(N-2):
            LS[i+1] += gcd(LS[i],S[i+1])
        LK.append(LS[N-2])
    ANSB = max(LK)
    ANS = max(ANSA,ANSB)
print(ANS)

Submission status: Runtime Error

Solution code:
import copy 

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

N = int(input())
T = list(map(int,input().split()))
T.sort()
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
GCD = 0
GCD += LIS[N-1]
if N == 2:
    ANS = max(T[0],T[1])
else:
    #第１項がtarget
    S = copy.copy(T)
    S.pop(0)
    LS = [0]*(N-1)
    LS[0] += S[0]
    for i in range(N-2):
        LS[i+1] += gcd(LS[i],S[i+1])
    ANSA = LS[N-2]

    #その他の場合
    LJ = []
    for i in range(N-1):
        if LIS[i] != LIS[i+1]:
            LJ.append(i+1)

    LK = []
    for j in range(len(LJ)):
        U = copy.copy(T)
        U.pop(LJ[j])
        print(U)
        LS = [0]*(N-1)
        LS[0] += U[0]
        for i in range(N-2):
            LS[i+1] += gcd(LS[i],S[i+1])
        LK.append(LS[N-2])
    ANSB = max(LK)
    ANS = max(ANSA,ANSB)
print(ANS)

Submission status: Runtime Error

Solution code:
import copy 

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

N = int(input())
T = list(map(int,input().split()))
T.sort()
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
GCD = 0
GCD += LIS[N-1]
#第１項がtarget
S = copy.copy(T)
S.pop(0)
LS = [0]*(N-1)
LS[0] += S[0]
for i in range(N-2):
    LS[i+1] += gcd(LS[i],S[i+1])
ANSA = LS[N-2]

#その他の場合
LJ = []
for i in range(N-1):
    if LIS[i] != LIS[i+1]:
        LJ.append(i+1)

LK = []
for j in range(len(LJ)):
    U = copy.copy(T)
    U.pop(LJ[j])
    LS = [0]*(N-1)
    LS[0] += U[0]
    for i in range(N-2):
        LS[i+1] += gcd(LS[i],S[i+1])
    LK.append(LS[N-2])
ANSB = max(LK)

print(max(ANSA,ANSB))

Submission status: Runtime Error

Solution code:
import sys

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())

N = II()
A_li = LI()

import math
from functools import reduce

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

print( max([gcd_list(A_li[:i]+A_li[i+1:]) for i in range(len(A_li))]) )

Submission status: Runtime Error

Solution code:
import copy 

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

N = int(input())
T = list(map(int,input().split()))
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
F = LIS.index(min(LIS))
if F == 0:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(1)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
    
if F == 0 or F == 1:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(F)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
        
print(ANS)

Submission status: Runtime Error

Solution code:
import copy 

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

N = int(input())
T = list(map(int,input().split()))
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
F = LIS.index(min(LIS))
if F == 1:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(1)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANS = max(ANSU,ANSV)
else:
    S = copy.copy(T)
    S.pop(F)
    LS = [0]*(N-1)
    LS[0] += S[0]
    for i in range(N-2):
        LS[i+1] += gcd(LS[i],S[i+1])
        ANS = LS[N-2]

print(ANS)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if b > a:
        a, b = b, a
    while b:
        a, b = b, a%b
    return a

N = int(input())
T = list(map(int,input().split()))
LIS = []

for i in range(N-1):
    A = gcd(T[i],T[i+1])
    LIS.append(A)
F = LIS.index(min(LIS))
if F == 0:
    T.pop(F)
else:
    T.pop(F+1)
LIS = []
for i in range(N-2):
    A = gcd(T[i],T[i+1])
    LIS.append(A)
print(min(LIS))

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if b > a:
        a, b = b, a
    while b:
        a, b = b, a%b
    return a

N = int(input())
T = list(map(int,input().split()))
LIS = []
for i in range(N-1):
    A = gcd(T[i],T[i+1])
    LIS.append(A)
F = LIS.index(min(LIS))
T.pop(F+1)
LIS = []
for i in range(N-2):
    A = gcd(T[i],T[i+1])
    LIS.append(A)
print(min(LIS))

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce
from copy import deepcopy
input()
n = list(map(int, input().split()))
if len(n) == 1:
    print(n[0])
elif len(n) == 2:
    print(max(n))
else:
    g = [gcd(i, j) for i, j in zip(n[1:], n[:-1])]
    m = g.index(min(g))
    g1 = deepcopy(n)
    g1.pop(m)
    g2 = deepcopy(n)
    g2.pop(m + 1)
    r1 = reduce(gcd, g1)
    r2 = reduce(gcd, g2)
    print(max(r1, r2))

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(map(int,input().split()))
ANS = 0
while True:
    S.sort()
    if S[0] == 1:
        ANS += 1
        break
    if len(S) == 1:
        ANS += S[0]
        break
    elif S[1] % S[0] == 0:
        S.pop(1)
    else:
        S.pop(1)
        S.append((S[1] % S[0]))
        
print(ANS)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
A = list(map(int,input().split(' ')))
L = [0]
R = [0]
ans = 1

for a in A:
    L.append(math.gcd(L[-1],a))

for a in reversed(A):
    R.append(math.gcd(R[-1],a))

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

print(ans)

Submission status: Runtime Error

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

def gcd(lis):
    if len(lis) == 1:
        return lis[0]
    elif len(lis) == 2:
        return gcdm(lis[0],lis[1])
    else:
        print(lis)
        f = gcdm(lis[-2],lis[-1])
        lis.pop()
        lis.pop()
        lis.append(f)
        return gcd(lis)

n = int(input())
l = list(map(int,input().split()))
l.sort()
f = 0
for i in range(n):
    t = [x for x in l]
    t.pop(i)
    k = gcd(t)
    if k > f:
        f = k
print(f)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

max_gcd = 1
for i in range(N):
    i_gcd =  gcd(A[:(i-1)] + A[i:])
    if max_gcd < i_gcd:
        max_gcd = i_gcd

print(max_gcd)

Submission status: Runtime Error

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

yaku=A[0]

max_yaku=1
n=0

for skip in range(N):
    yaku=A[abs(skip-1)]
    for i in range(N):
        if skip!=i:
           
            yaku=math.gcd(A[i],yaku)
    if yaku>max_yaku:
        max_yaku=yaku
    

print(max_yaku)

Submission status: Runtime Error

Solution code:
from math import gcd


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

    L = [0 for _ in range(N + 1)]
    R = [0 for _ in range(N + 1)]

    for i, num in enumerate(nums):
        L[i + 1] = gcd(L[i], num)

    for i in range(N - 2, -1, -1):
        R[i] = gcd(R[i + 1], nums[i + 1])

    print(max(gcd(L[i], R[i]) for i in range(N)))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

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

def gcd(a,b):
    return math.gcd(a,b)

x = [0]
y = [0]

for i in range(n):
    x.append(gcd(x[i], a[i]))
    y.append(gcd(y[i], a[-(i+1)]))

y.reverse()

ans = []
for i in range(n):
    ans.append(gcd(x[i], y[i+1]))

print(max(ans))

Submission status: Runtime Error

Solution code:
import math
n=int(input())
k=input().split()
i=0
j=0
m=0
left_gcd=0
right_gcd=0

answer_list=[]
input_list= [int(i) for i in k]
i=0
for i in range(n):
  m = i+1
  while j<i:
    left_gcd=math.gcd(left_gcd,input_list[j])
    j=j+1
  while (m < n) :
    right_gcd=math.gcd(right_gcd,input_list[m])
    m=m+1

  answer=math.gcd(left_gcd,right_gcd)
  answer_list.append(answer)
  j=0
  m=0
  left_gcd=0
  right_gcd=0

print(max(answer_list))

Submission status: Runtime Error

Solution code:
from fractions import gcd
n = int(input())
li = list(map(int, input().split()))
lil = [0]*n
lir = [0]*n
for k in range(n):
  if k == 0:
    lil[k] = li[0]
    lir[k] = li[-1]
  else:
    lil[k] = gcd(lil[k-1], li[k])
    lir[k] = gcd(lir[k-1], li[-k-1])
    
lir = lir[::-1]
tmp = max(gcd(lil[j-1], lir[j+1]) for j in range(1, n-1))
print(max(tmp, lir[1], lil[-2]))

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):
    tmp_arr = A[:i] + A[i+1:]
    ans_tmp = reduce(math.gcd,tmp_arr)
    if ans < ans_tmp:
        ans = ans_tmp
print(ans)

Submission status: Runtime Error

Solution code:
import math
import fractions

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

AL=[0]*N
AR=[0]*N
for i in range(N):
    if i == 0:
        AL[0] = A[0]
        AR[0] = A[N-1]
    else:
        AL[i] = math.gcd(AL[i-1],A[i])
        AR[i] = math.gcd(AR[i-1],A[N-i-1])

max=0
for i in range(N):
    if i == 0:
        n_ex_gcd =  AR[N-2]
    elif i == N-1:
        n_ex_gcd = AL[N-2]
    else:
        n_ex_gcd = math.gcd(AL[i-1],AR[N-i-2])
    if n_ex_gcd > max:
        max = n_ex_gcd
print(max)

Submission status: Runtime Error

Solution code:
import math

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

AL=[0]*N
AR=[0]*N
for i in range(N):
    if i == 0:
        AL[0] = A[0]
    else:
        AL[i] = math.gcd(AL[i-1],A[i])
for i in range(N):
    if i == 0:
        AR[0] = A[N-1]
    else:
        AR[i] = math.gcd(AR[i-1],A[N-i-1])

max=0
for i in range(N):
    if i == 0:
        n_ex_gcd =  AR[N-2]
    elif i == N-1:
        n_ex_gcd = AL[N-2]
    else:
        n_ex_gcd = math.gcd(AL[i-1],AR[N-i-2])
    if n_ex_gcd > max:
        max = n_ex_gcd
print(max)

Submission status: Runtime Error

Solution code:
import math

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

AL=[0]*N#左からi番目までのGCD
AR=[0]*N#右からi番目までのGCD
for i in range(N):
    if i == 0:
        AL[0] = A[0]
    else:
        AL[i] = math.gcd(AL[i-1],A[i])
for i in range(N):
    if i == 0:
        AR[0] = A[N-1]
    else:
        AR[i] = math.gcd(AR[i-1],A[N-i-1])

max=0
for i in range(N):
    if i == 0:
        n_ex_gcd =  AR[N-2]
    elif i == N-1:
        n_ex_gcd = AL[N-2]
    else:
        n_ex_gcd = math.gcd(AL[i-1],AR[N-i-2])
    if n_ex_gcd > max:
        max = n_ex_gcd
print(max)

Submission status: Runtime Error

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

'''
Result: All Correct
Score: 0
Code length: 91 Byte
Execution Time: 17 ms
Memory usage: 2940 KB
'''

# 最大公約数を計算
# ユークリッドの互除法を用いる
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:
from math import gcd

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = 1
    for i in range(n):
        tmp = -1
        for j in range(n):
            if j == i:
                continue
            if tmp == -1:
                tmp = a[j]
            tmp = gcd(tmp, a[j])
        ans = max(ans, tmp)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from math import gcd
from itertools import accumulate
N=int(input())
A=[int(i) for i in input().split()]
GCD=[]
if len(A)==2:
    print(max(A))
else:
    for i in range(N):
        B=A.copy()
        B.remove(B[i])
        C=list(accumulate(B,gcd))
        GCD.append(C[-1])
    print(max(GCD))

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce

def gcd(n,a):
    array = []
    for i in range(n):
        change_list = copy.copy(a)
        del change_list[i]
        array.append((reduce(math.gcd,change_list)))
    return max(array)


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

print(gcd(n,a))

Submission status: Runtime Error

Solution code:
    """ Euclidean algorithm"""
    if a < b: (a, b) = (b, a)
    if b == 0: return a
    m = a % b
    while m != 0:
        a = b
        b = m
        m = a % b
    return b

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

if N < 2 and 1e5 < N: raise()
for v in A:
    if v < 1 and v < 1e9: raise()

result = []
for skip in range(N):
    l = 0
    r = 0
    for v in range(0, skip):
        l = GCD(l, A[v])
    for v in range(N-1, skip, -1):
        r = GCD(r, A[v])
    result.append(GCD(l, r))

print(max(result))

Submission status: Runtime Error

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

M = []

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


# L(i)はa0, a1 ..., aiの最大公約数
def L(i):
  if i == -1:
    return 0
  else:
    return gcd(L(i-1),a[i])

# R(i)はai, ai+1 ..., aN-1の最大公約数
def R(i):
  if i == n:
    return 0
  else:
    return gcd(R(i+1),a[i])

for i in range(n):
  M.append(gcd(L(i-1),R(i+1)))
  
print(max(M))
#37

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon May 13 09:49:38 2019

@author: avina
"""

from math import gcd
n = int(input())
l = list(map(int, input().strip().split()))
maxe = 0
     
for i in range(n):
    for j in range(n):
        if i != j:
            g = gcd(l[i],l[j])
            maxe = max(maxe, g)
print(maxe)

Submission status: Runtime Error

Solution code:
def GCD(x, y): 
   if y > x:
      y,x = x,y
    while(y): 
       x, y = y, x % y 
  
   return x 
n = int(input())
l = list(map(int, input().strip().split()))
maxe = -1
     
for i in range(n):
    for j in range(n):
        if i != j:
            g = GCD(l[i],l[j])
            maxe = max(maxe, g)
print(maxe)

Submission status: Runtime Error

Solution code:
from math import gcd
n = int(input())
l = list(map(int, input().strip().split()))
maxe = -1
     
for i in range(n):
    for j in range(n):
        if i != j:
            g = gcd(l[i],l[j])
            maxe = max(maxe, g)
print(maxe)

Submission status: Runtime Error

Solution code:
from math import gcd
n = int(input())
l = list(map(int, input().strip().split()))
maxe = -1

for i in range(n):
  for j in range(n):
    g = gcd(l[i],l[j])
    maxe = max(maxe, g)
print(maxe)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

N = int(input())
A = list(map(int,input().split()))
g_max = 0
for i in range(N):
    B = A.copy()
    B[i:i+1] = []
    g = reduce(math.gcd,B)
    if g_max < g:
        g_max = g
print(g_max)

Submission status: Runtime Error

Solution code:
num =int(input())
value = list(map(int, input().split()))
value.sort()
if num == 2:
  answer = value[1]
else:
  cnt = 0
  for i in range(0, num):
      if value[i]%(value[1])!=0:
        cnt += 1
        if cnt == 2:
          break
  if cnt == 1:
    answer = value[1]
  elif cnt == 0:
    answer = value[0]
  else:
    for i in range (0, value[0]):
      cnt = 0
      for j in range(0, num):
        if value[j]%(value[0]-i)!=0:
          cnt += 1
          if cnt == 2:
            break
      if cnt == 1:
        answer = value[0] - i
        break
print(answer)

Submission status: Runtime Error

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

X1 = [0] * (N+2)
X2 = [0] * (N+2)

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

ans = 1
for i in range(N):
    G = math.gcd(X1[i], X2[i+2])
    if ans < G:
        ans = G
print(ans)

Submission status: Runtime Error

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

X1 = [0] * (N+2)
X2 = [0] * (N+2)

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

ans = 1
for i in range(N):
    gcd = math.gcd(X1[i], X2[i+2])
    if ans < gcd:
        ans = gcd
print(ans)

Submission status: Runtime Error

Solution code:
#import math
from functools import reduce

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

def gcds(nums):
    return reduce(gcd, nums)

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

ans = 0
for i in range(len(a)):
    aa = a[:i] + a[(i+1):]
    if ans < gcd(aa):
        ans = gcd(aa)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
As = (int(s) for s in input().split(" "))
if N==2:
  print(max(As))
  return

m = min(As)
f = 0
ans = 0
for i in range(2, m):
  for a in As:
    if(a % i != 0):
      f = 1
      break
  if f==0:
    ans = i
  else:
    f = 0
    
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

ans_l = []
for i in range(len(a)):
    aa = a[:i] + a[(i+1):]
    ans_l.append(gcd(aa))
ans = max(ans_l)
print(ans)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a = [int(i) for i in input().split()]
#print(n)
prefix,suffix=[0]*n,[0]*n
prefix[0]=a[0]
suffix[n-1]= a[n-1]
#print(prefix)
for i in range(1,n):
    prefix[i]= math.gcd(prefix[i-1],a[i])
    suffix[n-i-1]= math.gcd(suffix[n-i],a[n-i-1])
    pass
maxgcd= max(suffix[1],prefix[-2])
for i in range(1,n-1):
    maxgcd = max(maxgcd, math.gcd(prefix[i-1],suffix[i+1]))
print(maxgcd)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import math

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

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

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

print(max([math.gcd(r[i],l[i]) for i in range(n)]))

Submission status: Runtime Error

Solution code:
from math import gcd

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

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

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

print(max([gcd(r[i],l[i]) for i in range(n)]))

Submission status: Runtime Error

Solution code:
from math import gcd

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

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

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

print(max([gcd(r[i],l[i]) for i in range(n)]))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
wh = int(input())
A[wh] = int(input())
ans = 1
for i in range(max(A), 0, -1):
    if all([x % i == 0 for x in A]):
        ans = i
        break
print(ans)

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

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)