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:
def gcd(a, b):
    if a == b or b == 0:
        return a
    elif a == 0:
        return b
    elif a > b:
        return gcd(a - b, b)
    elif a < b:
        return gcd(a, b - a)

def solve():
    N = int(raw_input())
    arr = [int(_) for _ in raw_input().split()]
    left = [0] * (N + 1)
    right = [0] * (N + 1)
    left[0] = 0
    right[N] = 0
    for i in range(1, N+1):
        left[i] = gcd(left[i - 1], arr[i - 1])
    for i in range(N - 1, 0, -1):
        right[i] = gcd(right[i + 1], arr[i])
    max_gcd = 0
    for i in range(N):
        max_gcd = max(max_gcd, gcd(left[i], right[i+1]))
    print str(max_gcd)

if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    if a == b or b == 0:
        return a
    elif b == 0:
        return a
    elif a > b:
        return gcd(a - b, b)
    elif a < b:
        return gcd(a, b - a)

def solve():
    N = int(raw_input())
    arr = [int(_) for _ in raw_input().split()]
    left = [0] * (N + 1)
    right = [0] * (N + 1)
    left[0] = 0
    right[N] = 0
    for i in range(1, N+1):
        left[i] = gcd(left[i - 1], arr[i - 1])
    for i in range(N - 1, 0, -1):
        right[i] = gcd(right[i + 1], arr[i])
    max_gcd = 0
    for i in range(N):
        max_gcd = max(max_gcd, gcd(left[i], right[i+1]))
    print str(max_gcd)

if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
from functools import reduce

ans = max(reduce(gcd,a[1:n]),reduce(gcd,a[0:n-1]))
if n>2:
    for i in range(1,n - 1):
        ans = max(ans,gcd(reduce(gcd,a[0:i]),reduce(gcd,a[i + 1:n])))
ans

Submission status: Runtime Error

Solution code:
#ABC125C-GCDonBlackboard.py

from sys import stdin
from sys import setrecursionlimit
#import random
from fractions import gcd
from functools import lru_cache

setrecursionlimit(100000)

input = stdin.readline

N = int(input())
A = list(map(int, input().split()))
#A = [random.randrange(1,10**9) for _ in range(N)]

@lru_cache(maxsize=None)
def L(i):
    if i == 0:
        return 0
    else:
        return gcd(L(i-1),A[i-1])

@lru_cache(maxsize=None)
def R(i):
    if i == N:
        return 0
    else:
        return gcd(R(i+1),A[i])

M = []

for i in range(N):
    M.append(gcd(L(i), R(i+1)))

print(max(M))

Submission status: Runtime Error

Solution code:
import fractions as fr
import copy
from functools import reduce
 
N = int(input())
yaku = [0]*N
X = input().split()
X = list(set(X))
if len(X) == 1:
    print(X[0])
    exit()
X = list(map(int, X))
 
 
def gcd_list(numbers):
    return reduce(fr.gcd, numbers)
 
 
for i in range(N):
    Xwork = copy.copy(X)
    del(Xwork[i])
    yaku[i] = gcd_list(Xwork)
 
print(max(yaku))

Submission status: Runtime Error

Solution code:
import fractions as fr
import copy
from functools import reduce
 
N = int(input())
yaku = [0]*N
X = input().split()
X = list(set(X))
X = list(map(int, X))
 
 
def gcd_list(numbers):
    return reduce(fr.gcd, numbers)
 
 
for i in range(N):
    Xwork = copy.copy(X)
    del(Xwork[i])
    yaku[i] = gcd_list(Xwork)
 
print(max(yaku))

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    if a == b or b == 0:
        return a
    elif b == 0:
        return a
    elif a > b:
        return gcd(a - b, b)
    elif a < b:
        return gcd(a, b - a)

def gcd_arr(arr, N):
    if N == 2:
        return gcd(arr[0], arr[1])
    elif N == 1:
        return arr[0]
    else:
        mid = N // 2
        return gcd(gcd_arr(arr[:mid], mid), gcd_arr(arr[mid:], N-mid))

def gcd_arr_with_rm(arr, N, remove = 0):
    return gcd_arr(arr[0:remove] + arr[(remove+1):], N - 1)

def solve():
    N = int(raw_input())
    arr = [int(_) for _ in raw_input().split()]
    max_gcd = 1
    for j in range(N):
        tmp = gcd_arr_with_rm(arr, N, remove = j)
        if tmp > max_gcd:
            max_gcd = tmp
    print str(max_gcd)

if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import math

def gcd_arr(arr, N, remove = 0):
    if remove == 0:
        _gcd = arr[1]
    else:
        _gcd = arr[0]
    for i in range(N):
        if i != remove:
            _gcd = math.gcd(_gcd, arr[i])
    return _gcd

def solve():
    N = int(raw_input())
    arr = [int(_) for _ in raw_input().split()]
    max_gcd = 1
    for j in range(N):
        tmp = gcd_arr(arr, N, remove = j)
        if tmp > max_gcd:
            max_gcd = tmp
    print str(max_gcd)

if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce

N = int(input())
yaku = [0]*N
X = input().split()
X = list(map(int, X))


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


for i in range(N):
    Xwork = copy.copy(X)
    del(Xwork[i])
    yaku[i] = gcd_list(Xwork)

print(max(yaku))

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    if a == b:
        return a
    elif a > b:
        return gcd(a - b, b)
    elif a < b:
        return gcd(a, b - a)

def gcd_arr(arr, N, remove = 0):
    if remove == 0:
        _gcd = arr[1]
    else:
        _gcd = arr[0]
    for i in range(N):
        if i != remove:
            _gcd = gcd(_gcd, arr[i])
    return _gcd

def solve():
    N = int(raw_input())
    arr = [int(_) for _ in raw_input().split()]
    max_gcd = 1
    for i in range(N):
        tmp = gcd_arr(arr, N, remove = i)
        if tmp > max_gcd:
            max_gcd = tmp
    print str(max_gcd)

if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import copy
from fractions import gcd
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:
def gcd(*A):
    if len(A) == 1:
        return A[0]
    elif len(A) == 2:
        a, b = A
        tmp = a % b
        while tmp != 0:
            a, b = b, tmp
            tmp = a % b
        return b
    elif len(A) > 2:
        return gcd(gcd(*A[:2]), *A[2:])

N = int(input())
A = list(map(int, input().split()))
print(max(gcd(*(A[j] for j in range(N) if i != j)) for i in range(N)))

Submission status: Runtime Error

Solution code:
def gcd(*A):
    if len(A) == 2:
        a, b = A
        tmp = a % b
        while tmp != 0:
            a, b = b, tmp
            tmp = a % b
        return b
    else:
        return gcd(gcd(*A[:2]), *A[2:])

N = int(input())
A = list(map(int, input().split()))
print(max(gcd(*(A[j] for j in range(N) if i != j)) for i in range(N)))

Submission status: Runtime Error

Solution code:
#ABC125C-GCDonBlackboard.py

from sys import stdin
from fractions import gcd
#from functools import lru_cache

input = stdin.readline

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

#@lru_cache(maxsize=None)
def L(i):
    if i == 0:
        return 0
    else:
        return gcd(L(i-1),A[i-1])

#@lru_cache(maxsize=None)
def R(i):
    if i == N:
        return 0
    else:
        return gcd(R(i+1),A[i])

M = []

for i in range(N):
    M.append(gcd(L(i), R(i+1)))

print(max(M))

Submission status: Runtime Error

Solution code:
#ABC125C-GCDonBlackboard.py

from sys import stdin
from fractions import gcd
from functools import reduce
from functools import lru_cache

input = stdin.readline

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

#@lru_cache(maxsize=None)
def L(i):
    if i == 0:
        return 0
    else:
        return gcd(L(i-1),A[i-1])

#@lru_cache(maxsize=None)
def R(i):
    if i == N:
        return 0
    else:
        return gcd(R(i+1),A[i])

M = []

for i in range(N):
    M.append(gcd(L(i), R(i+1)))

print(max(M))

Submission status: Runtime Error

Solution code:
#ABC125C-GCDonBlackboard.py

from sys import stdin
from fractions import gcd
from functools import reduce
from functools import lru_cache

input = stdin.readline

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

@lru_cache
def L(i):
    if i == 0:
        return 0
    else:
        return gcd(L(i-1),A[i-1])

@lru_cache
def R(i):
    if i == N:
        return 0
    else:
        return gcd(R(i+1),A[i])

M = []

for i in range(N):
    M.append(gcd(L(i), R(i+1)))

print(max(M))

Submission status: Runtime Error

Solution code:
#ABC125C-GCDonBlackboard.py

from sys import stdin
from fractions import gcd
from functools import reduce
from functools import lru_cache

input = stdin.readline

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

@lru_cache(maxsize=None)
def L(i):
    if i == 0:
        return 0
    else:
        return gcd(L(i-1),A[i-1])

@lru_cache(maxsize=None)
def R(i):
    if i == N:
        return 0
    else:
        return gcd(R(i+1),A[i])

M = []

for i in range(N):
    M.append(gcd(L(i), R(i+1)))

print(max(M))

Submission status: Runtime Error

Solution code:
#ABC125C-GCDonBlackboard.py

from sys import stdin
from math import gcd
from functools import reduce
from functools import lru_cache

input = stdin.readline

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

@lru_cache(maxsize=None)
def L(i):
    if i == 0:
        return 0
    else:
        return gcd(L(i-1),A[i-1])

@lru_cache(maxsize=None)
def R(i):
    if i == N:
        return 0
    else:
        return gcd(R(i+1),A[i])

M = []

for i in range(N):
    M.append(gcd(L(i), R(i+1)))

print(max(M))

Submission status: Runtime Error

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

def gcd(m,n):
    x=max(m,n)
    y=min(m,n)
    if x%y==0:
        return y
    else:
        while x%y!=0:
            z=x%y
            x=y
            y=z
        else:
          return z

As.sort()
gcd1=[gcd(As[0], As[i]) for i in range(N)]
gcd2=[gcd(As[1], As[i]) for i in range(N)]
gcd1.sort()
gcd2.sort()
if gcd1.count(min(gcd1))>=2:
    print(gcd2[2])
else:
    print(gcd1[1])

Submission status: Runtime Error

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

def gcd(m,n):
    x=max(m,n)
    y=min(m,n)
    if x%y==0:
        return y
    else:
        while x%y!=0:
            z=x%y
            x=y
            y=z
        else:
            return z

gcd1.sort()
gcd2.sort()
if gcd1.count(min(gcd1))>=2:
    print(gcd2[2])
else:
    print(gcd1[1])

Submission status: Runtime Error

Solution code:
from functools import reduce
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
gcd_max = 0
if (N > 4):
    for i in range(4):
        gcd_now = reduce(gcd, list(x for x in A if x != A[i]))
        if (gcd_max < gcd_now): gcd_max = gcd_now
    for i in range(N):
        gcd_now = gcd(gcd_max, A[i])
        if (gcd_max < gcd_now): gcd_max = gcd_now
else:
    for i in range(N):
        gcd_now = reduce(gcd, list(x for x in A if x != A[i]))
        if (gcd_max < gcd_now): gcd_max = gcd_now
    
print(gcd_max)

Submission status: Runtime Error

Solution code:
from functools import reduce
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
gcd_max = 0
for i in range(N):
    gcd_now = reduce(gcd, list(x for x in A if x != A[i]))
    if (gcd_max < gcd_now): gcd_max = gcd_now
    
print(gcd_max)

Submission status: Runtime Error

Solution code:
from functools import reduce
from math import gcd
N = int(input())
A = list(map(int,input().split()))
gcd_max = 0
for i in range(N):
    gcd_now = reduce(gcd, list(x for x in A if x != A[i]))
    if (gcd_max < gcd_now): gcd_max = gcd_now
    
print(gcd_max)

Submission status: Runtime Error

Solution code:
from functools import reduce
from math import gcd

N = int(input())
A = [int(a) for a in input().split(" ")]
if N==2:
    print(gcd(*A))
else:
    left = reduce(lambda acc, x: acc+[gcd(x, acc[-1])], A, A[:1])
    right = reduce(lambda acc, x: acc+[gcd(x, acc[-1])], A[::-1], A[-1:])[::-1]

    ans = max([gcd(left[i-1], right[i+1]) for i in range(1,N-1)])
    ans = max([right[1], ans, left[-2]])
    print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
from math import gcd

N = int(input())
A = [int(a) for a in input().split(" ")]
if N==2:
    print(gcd(*A))
    exit()

left = reduce(lambda acc, x: acc+[gcd(x, acc[-1])], A, A[:1])
right = reduce(lambda acc, x: acc+[gcd(x, acc[-1])], A[::-1], A[-1:])[::-1]

ans = max([gcd(left[i-1], right[i+1]) for i in range(1,N-1)])
ans = max([right[1], ans, left[-2]])
print(ans)

Submission status: Runtime Error

Solution code:
def insu(n):
    ys = []
    for i in range(2,  n//2):
        if n % i == 0:
            ys.append(i)
    if n > n//2:
        ys.append(n)

    return ys


l = int(input())
nums = list(map(int, inpuy().split(" ")))
count = {}

for i in range(0, len(nums)):
    tmp = insu(nums[i])
    for n in tmp:
        count.setdefault(n, 0)
        count[n] += 1

rev = {}
for k, v in sorted(count.items(), key=lambda x: -x[0]):
    rev[k] = v

for k, v in rev.items():
    if v == l-1:
        print(k)
        break

Submission status: Runtime Error

Solution code:
#https://atcoder.jp/contests/abc125
# -*- coding: utf-8 -*-

import fractions
import numpy as np
gcd_ufunc = np.frompyfunc(fractions.gcd, 2, 1)


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

gcdList = []
for i in range(n):
        v = a[0:i]+a[i+1:n]
        gcdList.append( int(gcd_ufunc.accumulate(v, dtype=np.object).astype(np.int) ))

print( max(gcdList) )

Submission status: Runtime Error

Solution code:
#https://atcoder.jp/contests/abc125
# -*- coding: utf-8 -*-


import numpy as np

def gcd_strategy():
    import math
    import fractions
    return math.gcd if hasattr(math, "gcd") else fractions.gcd


gcd = gcd_strategy()
gcd_ufunc = np.frompyfunc(gcd, 2, 1)


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

gcdList = []
for i in range(n):
        v = a[0:i]+a[i+1:n]
        gcdList.append( int(gcd_ufunc.accumulate(v, dtype=np.object).astype(np.int) ))

print( max(gcdList) )

Submission status: Runtime Error

Solution code:
#https://atcoder.jp/contests/abc125
# -*- coding: utf-8 -*-

import fraction
from functools import reduce

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

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

gcdList = []
for i in range(n):
        gcdList.append( gcd(a[0:i]+a[i+1:n]) )

print( max(gcdList) )

Submission status: Runtime Error

Solution code:
#https://atcoder.jp/contests/abc125
# -*- coding: utf-8 -*-

import math
from functools import reduce

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

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

gcdList = []
for i in range(n):
        gcdList.append( gcd(a[0:i]+a[i+1:n]) )

print( max(gcdList) )

Submission status: Runtime Error

Solution code:
import math
size=input()
size=int(size)
A=input().split()
GCD=1
for i in range(0,size):
    for j in range(1,size):
        a=int(A[i])
        b=int(A[j])
        if (i==j):
            continue
        candidate=math.gcd(a,b)
        if (candidate>GCD):
            GCD=candidate

print(GCD)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
inp_ints = list(map(int, input().split()))
# ints = list(set(inp_ints))

uniq_ints = list(set(inp_ints))
ints = uniq_ints
for m in uniq_ints:
    if inp_ints.count(m) >= 2:
        ints.append(m)

gcd = 0
result = 1
for i in range(len(ints)):
    gcd = 0
    for m in ints[:i]:
        gcd = math.gcd(gcd, m)
    for m in ints[i+1:]:
        gcd = math.gcd(gcd, m)
    if gcd > result:
        result = gcd

print(result)

Submission status: Runtime Error

Solution code:
import fractions

N = int(input())
inp_ints = list(map(int, input().split()))
ints = list(set(inp_ints))
""" uniq_ints = list(set(inp_ints))

ints = uniq_ints
for m in uniq_ints:
    if inp_ints.count(m) >= 2:
        ints.append(m) """

gcd = 0
result = 1
holed_ints = []
for i in range(N):
    holed_ints = ints[:i] + ints[i+1:]
    gcd = 0
    for j in range(N-1):
        gcd = fractions.gcd(gcd, holed_ints[j])
    if gcd > result:
        result = gcd

print(result)

Submission status: Runtime Error

Solution code:
import fractions

N = int(input())
inp_ints = list(map(int, input().split()))
ints = list(set(inp_ints)) * 2
""" uniq_ints = list(set(inp_ints))

ints = uniq_ints
for m in uniq_ints:
    if inp_ints.count(m) >= 2:
        ints.append(m) """

gcd = 0
result = 1
holed_ints = []
for i in range(N):
    holed_ints = ints[:i] + ints[i+1:]
    gcd = 0
    for j in range(N-1):
        gcd = fractions.gcd(gcd, holed_ints[j])
    if gcd > result:
        result = gcd

print(result)

Submission status: Runtime Error

Solution code:
import fractions

N = int(input())
ints = list(map(int, input().split())).sort()

gcd = 0
result = 1
holed_ints = []
for i in range(len(ints)):
    holed_ints = ints[:i] + ints[i+1:]
    gcd = 0
    for j in range(len(holed_ints)):
        gcd = fractions.gcd(gcd, holed_ints[j])
        if gcd == 1:
            break
    if gcd > result:
        result = gcd

print(result)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
ints = list(map(int, input().split()))
ints.sort(reverse=True)

gcd = 0
result = 1
holed_ints = []
for i in range(N):
    holed_ints = ints[:i] + ints[i+1:]
    gcd = 0
    for j in range(N-1):
        gcd = math.gcd(gcd, holed_ints[j])
        if gcd == 1:
            break
    if gcd > result:
        result = gcd

print(result)

Submission status: Runtime Error

Solution code:
def gcd_seq(seq):
    from math import gcd
    size = len(seq)
    if size == 1:
        return seq[0]
    if size == 2:
        return gcd(seq[0], seq[1])
    ans = gcd(seq[0], seq[1])
    for i in range(2, size):
        ans = gcd(seq[i], ans)
    return ans


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

ANS = gcd_seq(A)  # no change
for i in range(N):
    a = A[:]
    a.pop(i)
    ANS = max((gcd_seq(a), ANS))
print(ANS)

Submission status: Runtime Error

Solution code:
from math import gcd


def gcd_seq(seq):
    size = len(seq)
    if size == 1:
        return seq[0]
    elif size == 2:
        return gcd(seq[0], seq[1])
    ans = gcd(seq[0], seq[1])
    for i in range(2, size):
        ans = gcd(seq[i], ans)
    return ans


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

ANS = gcd_seq(A)  # no change
for i in range(N):
    a = A[:]
    a.pop(i)
    ans = gcd_seq(a)
    ANS = max((ans, ANS))
print(ANS)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from fractions import gcd
n = int(input())
a = list(set(map(int,input().split())))
a.sort(reverse=True)
b = gcd(a[0], a[1])
c = [a[0], a[1]]
for i in range(2, len(a)):
    g1 = gcd(b, a[i])    
    d = []
    for j in c:
        g2 = gcd(j, a[i])
        if g2 > 1:
            d.append(g2)
    c = d
    if b > 1:
        c.append(b)
    b = g1

if c:
    print(max(c))
else:
    print(1)

Submission status: Runtime Error

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

import math
import copy
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

tmax = 1
for i in range(N):
	newA = copy.deepcopy(A)
	newA.pop(i)
	temp = gcd_list(newA)
	if  tmax < temp:
		tmax = temp

print(tmax)

Submission status: Runtime Error

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

import math
import copy

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

tmax = 1
for i in range(N):
	newA = copy.deepcopy(A)
	newA.pop(i)
	temp = gcd_list(newA)
	if  tmax < temp:
		tmax = temp

print(tmax)

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

ini_gcd_list = []
fin_gcd_list = []

for i in range(1, N-1):
  if i == 1:
    ini_pre = gcd(A_list[0], A_list[1])
    ini_gcd_list.append(ini_pre)
    fin_pre = gcd(A_list[-1], A_list[-2])
    fin_gcd_list.append(fin_pre)
    continue
  ini_pre = gcd(ini_pre, A_list[i])
  ini_gcd_list.append(ini_pre)
  fin_pre = gcd(fin_pre, A_list[-i-1])
  fin_gcd_list.append(fin_pre)
gcd_list = [ini_gcd_list[-1], fin_gcd_list[-1]]
#print(gcd_list)
#print(ini_gcd_list)
#print(fin_gcd_list)
if N  == 2:
  print(max(A_list))
for i in range(N-3):
  gcd_list.append(gcd(ini_gcd_list[i], fin_gcd_list[-i-2]))
print(max(gcd_list))

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

ini_gcd_list = []
fin_gcd_list = []

for i in range(1, N-1):
  if i == 1:
    ini_pre = gcd(A_list[0], A_list[1])
    ini_gcd_list.append(ini_pre)
    fin_pre = gcd(A_list[-1], A_list[-2])
    fin_gcd_list.append(fin_pre)
    continue
  ini_pre = gcd(ini_pre, A_list[i])
  ini_gcd_list.append(ini_pre)
  fin_pre = gcd(fin_pre, A_list[-i-1])
  fin_gcd_list.append(fin_pre)
gcd_list = [ini_gcd_list[-1], fin_gcd_list[-1]]
#print(gcd_list)
#print(ini_gcd_list)
#print(fin_gcd_list)
for i in range(N-3):
  gcd_list.append(gcd(ini_gcd_list[i], fin_gcd_list[-i-2]))
print(max(gcd_list))

Submission status: Runtime Error

Solution code:
import math
n=int(input())
A=list(map(int,input().split()))
L=[0]*(n+1)
R=[0]*(n+1)
for i in range(n):
    L[i+1]=math.gcd(L[i],A[i])
for i in range(n,0,-1):
    R[i-1]=math.gcd(R[i],A[i-1])
ans=[]
for k in range(n):
    ans.append(math.gcd(L[k],R[k+1]))
print(max(ans))

Submission status: Runtime Error

Solution code:
# Aiを消した最大公約数Miを求めて、最大のものを出力

import math
from functools import reduce


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


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

M = []
for i in range(0, N):
    if i == 0:
        M.append(gcd(A[1:N]))
    elif i == N - 1:
        M.append(gcd(A[0:N - 1]))
    else:
        M.append(math.gcd(gcd(A[0:i]), gcd(A[(i + 1):N])))

print(max(M))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

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

if len(a) <= 2:
    answer = max(a)
else:
    for i in range(len(a)):
        a_filter = [k for k in a if k < a[i] or k > a[i]]
        answer_b = gcd_list(a_filter)
        if answer_b > answer:
            answer = answer_b
print(answer)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

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

if len(a) == 2:
    answer = max(a)
else:
    for i in range(len(a)):
        val = a[i]
        a_filter = [k for k in a if str(k)!=str(val)]
        answer_b = gcd_list(a_filter)
        if answer_b > answer:
            answer = answer_b
print(answer)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

if len(a) == 2:
    answer = max(a)
else:
    for i in range(len(a)):
        val = a[i]
        a_filter = [k for k in a if str(k)!=str(val)]
        answer_b = gcd_list(a_filter)
        if answer_b > answer:
            answer = answer_b
print(answer)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    if a <= b:
        a,b = b,a
    if a%b == 0:
        return b
    else:
        return gcd(b,a%b)

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

L_gcd = [A[0]]
R_gcd = [A[-1]]

for i in range(1,N):
    L_gcd.append(gcd(L_gcd[i-1],A[i]))
    R_gcd.insert(0,gcd(A[N-i-1],R_gcd[0]))

ans = []
for i in range(N-2):
    ans.append(gcd(L_gcd[i],R_gcd[i+2]))
print(max(ans))

Submission status: Runtime Error

Solution code:
ef gcd(a,b):
    if a <= b:
        a,b = b,a
    if a%b == 0:
        return b
    else:
        return gcd(b,a%b)

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

L_gcd = [A[0]]
R_gcd = [A[-1]]

for i in range(1,N):
    L_gcd.append(gcd(L_gcd[i-1],A[i]))
    R_gcd.insert(0,gcd(A[N-i-1],R_gcd[0]))

ans = max(L_gcd[-1],R_gcd[0])

for i in range(N-2):
    if max(L_gcd[i],R_gcd[i+2])<=ans:
        break
    if gcd(L_gcd[i],R_gcd[i+2])>ans:
        ans = gcd(L_gcd[i],R_gcd[i+2])
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
import fractions import gcd as fgcd
from functools import reduce

def gcd(*numbers):
    return reduce(fgcd, numbers)

str_input = input()
n = int(str_input)

str_input = input()
a = []
for tmp in str_input.split():
    a.append(int(tmp))

index_min = a.index(min(a))
a[index_min] = max(a)

print(gcd(*a))

Submission status: Runtime Error

Solution code:
import sys
import math
from functools import reduce

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

str_input = input()
n = int(str_input)

str_input = input()
a = []
for tmp in str_input.split():
    a.append(int(tmp))

index_min = a.index(min(a))
a[index_min] = max(a)

print(gcd(*a))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math

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


def gcd_list(numbers):
    res = math.gcd(numbers[0], numbers[1])
    if len(numbers) > 2:
        for idx in range(2, len(numbers)):
            res = math.gcd(res, numbers[idx])
    return res


max_gcd = 0
if(N) == 2:
    max_gcd = max(As)
else:
    for i in range(N):
        others = [As[j] for j in range(N) if j != i]
        max_gcd = max(gcd_list(others), max_gcd)

print(max_gcd)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math

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


def gcd_list(numbers):
    res = math.gcd(numbers[0], numbers[1])
    if len(numbers) > 2:
        for idx in range(2, len(numbers)):
            res = math.gcd(res, numbers[idx])
    return res


max_gcd = 0
if(N) == 2:
    max_gcd = max(As)
else:
    for i in range(N):
        others = [As[j] for j in range(N) if j != i]
        max_gcd = max(gcd_list(others), max_gcd)

print(max_gcd)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math

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


def gcd_list(numbers):
    res = math.gcd(numbers[0], numbers[1])
    for idx in range(2, len(numbers)):
        res = math.gcd(res, numbers[idx])
    return res


max_gcd = 0
if(N) == 2:
    max_gcd = max(As)
else:
    for i in range(N):
        others = [As[j] for j in range(N) if j != i]
        max_gcd = max(gcd_list(others), max_gcd)

print(max_gcd)

Submission status: Runtime Error

Solution code:
#include <iostream>

using namespace std;

int lcd(int*,int,int,int);

int main()
{
  int N;
  cin >> N;

  int A[N];
  for(int i=0;i<N;i++) cin >> A[i];

  int l;
  if(N==2){
     if(A[0]>A[1]) cout << A[0] << endl;
     else cout << A[1] << endl;
  } else {
     int max = lcd(A, N, 0, 1);
     for(int i=1;i<N;i++){
        l = lcd(A, N, i);
        if(max<l){
           max = l;
        }
     }
     cout << max << endl;
  }
}

int lcd(int *A, int N, int n){
   int max=1, l=2;
   int B[N];
   for(int i=0;i<N;i++) B[i]=A[i];
   int flag=0;
   while(true){
      for(int i=0;i<N;i++){
         if(i==n){
           continue;
         } 
         if(B[i]<l){
           goto endloop;
         }
      }
      for(int i=0;i<N;i++){
         if(i==n) continue;
         if(B[i]%l!=0){
            flag=1;
            break;
         } else {
            flag=0;
         }
      }

      if(flag==0){
         max*=l;
         for(int i=0;i<N;i++){
            if(i==n) continue;
            B[i] /= l;
         }
      } else {
         l++;
      }
   }
endloop:
      return max;
}

Submission status: Runtime Error

Solution code:
import math
n=int(input())
a=[0]+list(map(int,input().split()))+[0]
b=a[::-1]
l=[0]*n
r=[0]*n
ans=[]
for i in range(1,n):
  l[i]=math.gcd(l[i-1],a[i-1])
for j in range(1,n):
  r[i]=math.gcd(r[i-1],b[i-1])
c=b[::-1]
for k in range(n):
  ans.append(math.gcd(l[k],r[k]))
print(max(ans))

Submission status: Runtime Error

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

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

L_gcd = [A[0]]
R_gcd = [A[-1]]

for i in range(1,N):
    L_gcd.append(gcd(L_gcd[i-1],A[i]))
    R_gcd.insert(0,gcd(A[N-i],R_gcd[A[N-i+1]]))

ans = max(L_gcd[-1],R_gcd[0])

for i in range(N-1):
    if gcd(L_gcd[i],R_gcd[i+2]):
        ans = gcd(L_gcd[i],R_gcd[i+2])
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
from functools import reduce


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


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

max_gcd = 0

for i in range(len(As)):
    others = [As[j] for j in range(len(As)) if j != i]
    max_gcd = max(gcd_list(others), max_gcd)

print(max_gcd)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    if(a == 0):
        return b
    if(b == 0):
        return a

    if(a < b):
        a, b = b, a
    r = a % b
    while(r != 0):
        a, b = b, r
        r = a % b
    return b

def L(i, A):
    if(i == -1):
        return 0
    return gcd(L(i - 1, A), A[i])

def R(i, A, N):
    if(i == N):
        return 0
    return gcd(R(i + 1, A, N), A[i])

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

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

print(max(M))

Submission status: Runtime Error

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

import math
import copy
from functools import reduce

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

ans = 1
temp_A = A
for i in range(N):
    temp_A = copy.deepcopy(A)
    del temp_A[i]
    ans = max(ans, gcd_list(temp_A))

print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
import copy
import math
from functools import reduce

N = int(stdin.readline().rstrip())
data = stdin.readline().rstrip().split()

idata = [int(x) for x in data]

gcds = []
idata_temp = []

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

gcds.append(gcd_list(idata))

for i in range(len(idata)):
    idata_temp = copy.copy(idata)
    idata_temp.pop(i)
    gcds.append(gcd_list(idata_temp))

print(max(gcds))