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( map(int, input().split()))

if n==1:
    print(10**9)
    exit()

def is_prime(n):
    if n == 1:
        return True
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


if len(set(a)) == 1:
    print(a[0])
    exit()

sosu = []

if is_prime(a[0]):
    gcd_a = a[1]
    for i in range(2, n):
        gcd_a = gcd(gcd_a, a[i])
    print(gcd_a)
    exit()
else:
    gcd_a = a[0]

for i in range(1, n):
    tmp = gcd(gcd_a, a[i])
    if tmp == 1:
        sosu.append(a[i])
    else:
        gcd_a = tmp

if len(sosu)>1:
    print(1)
    exit()
elif len(sosu)==1:
    print(gcd_a)
    exit()
else:
    sosu2 = []

    if is_prime(a[0]//gcd_a):
        gcd_a_ = a[1]//gcd_a
        for i in range(2, n):
            gcd_a_ = gcd(gcd_a_, a[i])
        print(gcd_a_*gcd_a)
        exit()
    else:
        gcd_a = a[0]//gcd_a

    for i in range(1, n):
        tmp = gcd(gcd_a_, a[i]//gcd_a)
        if tmp == 1:
            sosu2.append(a[i]//gcd_a)
        else:
            gcd_a_ = tmp

    if len(sosu2) > 1:
        print(gcd_a)
    else:
        print(gcd_a_*gcd_a)

Submission status: Runtime Error

Solution code:
from fraction import gcd

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

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


if len(set(a)) == 1:
    print(a[0])
    exit()


sosu = []


if is_prime(a[0]):
    gcd_a = a[1]
    for i in range(2, n):
        ans = gcd(gcd_a, a[i])
    print(ans)
    exit()
else:
    gcd_a = a[0]

for i in range(1, n):
    tmp = gcd(gcd_a, a[i])
    if tmp == 1:
        sosu.append(a[i])
    else:
        gcd_a = tmp

if len(sosu)>1:
    print(1)
    exit()
elif len(sosu)==1:
    print(gcd_a)
    exit()
else:
    sosu2 = []
    gcd_a_ = a[0]//gcd_a
    for i in range(1, n):
        tmp = gcd(gcd_a_, a[i]//gcd_a)
        if tmp == 1:
            sosu2.append(a[i]//gcd_a)
        else:
            gcd_a_ = tmp

    if len(sosu2) > 1:
        print(gcd_a)
    else:
        print(gcd_a_*gcd_a)

Submission status: Runtime Error

Solution code:
from math import gcd

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] = gcd(l[i], a[i])
    r[n-i-1] = gcd(r[n-i], a[n-i-1])

m = [0]*n

for i in range(n):
    m[i] = gcd(l[i], r[i+1])

print(max(m))

Submission status: Runtime Error

Solution code:
from fractions import gcd

N = int(input())
A = list(map(int,input().split()))
'''
res = 0
for i in range(N):
    tmp = A[i+1:] + A[:i]
    ans = tmp[0]
    for i in range(1,N-1):
        ans = gcd(ans,tmp[i])
    res = max(ans,res)
print(res)
'''

L = [0] * N
R = [0] * N

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

print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n=int(input())
a=list(map(int,input().split()))
left=[a[0]]
for i in range(1,n):left.append(gcd(left[-1],a[i]))
right=[a[n-1]]
for i in range(n-2,-1,-1):right.append(gcd(right[-1],a[i]))
right.reverse()
ans=max(right[1],left[n-2])
print(max(ans,max(gcd(left[i-1],right[i+1])for i in range(1,n-1))))

Submission status: Runtime Error

Solution code:
from math import gcd


def main():
    #####segfunc######
    def segfunc(x, y):
        return gcd(x, y)

    def init(init_val):
        # set_val
        for i in range(n):
            seg[i + num - 1] = init_val[i]
            # built
        for i in range(num - 2, -1, -1):
            seg[i] = segfunc(seg[2 * i + 1], seg[2 * i + 2])

    def update(k, x):
        k += num - 1
        seg[k] = x
        while k:
            k = (k - 1) // 2
            seg[k] = segfunc(seg[k * 2 + 1], seg[k * 2 + 2])

    def query(p, q):
        if q <= p:
            return ide_ele
        p += num - 1
        q += num - 2
        res = ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = segfunc(res, seg[p])
            if q & 1 == 1:
                res = segfunc(res, seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = segfunc(res, seg[p])
        else:
            res = segfunc(segfunc(res, seg[p]), seg[q])
        return res

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

    #####単位元######
    ide_ele = 0

    # num:n以上の最小の2のべき乗
    num = 2 ** (n - 1).bit_length()
    seg = [ide_ele] * 2 * num
    init(a)

    ans = -1
    for i in range(n):
        ans = max(ans, gcd(query(0, i), query(i + 1, n)))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import copy

class SegmentTree:
    def __init__(self, N, func, I):
        self.sz = 2 ** (N-1).bit_length()
        self.func = copy.deepcopy(func)
        self.I = copy.deepcopy(I)
        self.seg = [copy.deepcopy(I) for i in range(self.sz * 2)]

    def assign(self, k, x):
        self.seg[k + self.sz] = copy.deepcopy(x)

    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])

    def update(self, k, x):
        k += self.sz
        self.seg[k] = copy.deepcopy(x)
        while k > 1:
            k //= 2
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])

    def query(self, a, b):
        L = copy.deepcopy(self.I)
        R = copy.deepcopy(self.I)
        a += self.sz
        b += self.sz
        while a < b:
            if a % 2 == 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b % 2 == 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a //= 2
            b //= 2
        return self.func(L, R)

from math import gcd

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

def f(x,y):
    if x * y == 0:
        return x + y
    else:
        return gcd(x,y)

seg = SegmentTree(N + 1, f, 0)
for i in range(N):
    seg.assign(i , A[i])
seg.build()

ans = 1
for i in range(N):
    ans = max(ans , f(seg.query(0 , i) , seg.query(i + 1 , N)))
print(ans)

Submission status: Runtime Error

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

class SegmentTree:
    def __init__(self, N, func, I):
        self.sz = 2 ** (N-1).bit_length()
        self.func = copy.deepcopy(func)
        self.I = copy.deepcopy(I)
        self.seg = [copy.deepcopy(I) for i in range(self.sz * 2)]

    def assign(self, k, x):
        self.seg[k + self.sz] = copy.deepcopy(x)

    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])

    def update(self, k, x):
        k += self.sz
        self.seg[k] = copy.deepcopy(x)
        while k > 1:
            k //= 2
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])

    def query(self, a, b):
        L = copy.deepcopy(self.I)
        R = copy.deepcopy(self.I)
        a += self.sz
        b += self.sz
        while a < b:
            if a % 2 == 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b % 2 == 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a //= 2
            b //= 2
        return self.func(L, R)

from math import gcd

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

def f(x,y):
    if x * y == 0:
        return x + y
    else:
        return gcd(x,y)

seg = SegmentTree(N + 1, f, 0)
for i in range(N):
    seg.assign(i , A[i])
seg.build()

ans = 1
for i in range(N):
    ans = max(ans , gcd(seg.query(0 , i) , seg.query(i + 1 , N)))
print(ans)

Submission status: Runtime Error

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

class SegmentTree:
    def __init__(self, N, func, I):
        self.sz = 2 ** (N-1).bit_length()
        self.func = copy.deepcopy(func)
        self.I = copy.deepcopy(I)
        self.seg = [copy.deepcopy(I) for i in range(self.sz * 2)]

    def assign(self, k, x):
        self.seg[k + self.sz] = copy.deepcopy(x)

    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])

    def update(self, k, x):
        k += self.sz
        self.seg[k] = copy.deepcopy(x)
        while k > 1:
            k //= 2
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])

    def query(self, a, b):
        L = copy.deepcopy(self.I)
        R = copy.deepcopy(self.I)
        a += self.sz
        b += self.sz
        while a < b:
            if a % 2 == 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b % 2 == 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a //= 2
            b //= 2
        return self.func(L, R)


from math import gcd
N = int(input())
A = list(map(int,input().split()))

def f(x,y):
    if x * y == 0:
        return x + y
    else:
        return gcd(x,y)

seg = SegmentTree(N + 1, f, 0)
for i in range(N):
    seg.assign(i , A[i])
seg.build()

ans = 1
for i in range(N):
    ans = max(ans , gcd(seg.query(0 , i) , seg.query(i + 1 , N)))
print(ans)

Submission status: Runtime Error

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

mx = 0
for i in range(n):
    popped = a.pop(i)
    g = a[0]
    for aa in a[1:]:
        g = math.gcd(g, aa)
    a.insert(i, popped)
    mx = max(mx, g)
print(mx)

Submission status: Runtime Error

Solution code:
# import bisect
# import copy
from fractions import gcd


# import math
# import numpy as np
# from collections import Counter, deque
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
import sys
sys.setrecursionlimit(10**3)


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

    # A[0:i]の最大公約数
    def L(i):
        if i == 0:
            return 0
        return gcd(L(i - 1), A[i - 1])

    # A[i:]の最大公約数
    def R(i):
        if i == N:
            return 0
        return gcd(R(i + 1), A[i])

    maxgcd = 0
    for i in range(N):
        maxgcd = max(maxgcd, gcd(L(i), R(i + 1)))

    print(maxgcd)


resolve()

Submission status: Runtime Error

Solution code:
# import bisect
# import copy
from fractions import gcd


# import math
# import numpy as np
# from collections import Counter, deque
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

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

    # A[0:i]の最大公約数
    def L(i):
        if i == 0:
            return 0
        return gcd(L(i - 1), A[i - 1])

    # A[i:]の最大公約数
    def R(i):
        if i == N:
            return 0
        return gcd(R(i + 1), A[i])

    maxgcd = 0
    for i in range(N):
        maxgcd = max(maxgcd, gcd(L(i), R(i + 1)))

    print(maxgcd)


resolve()

Submission status: Runtime Error

Solution code:
from sys import stdin
from math import gcd
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))
    A.insert(0,0)
    A.append(0)

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

    res=0
    for i in range(N):
        res=max(res,gcd(L[i],R[i]))
    print(res)

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
# 区間[i,j]における最小値を返す
# 値の更新をする
import fractions
input = sys.stdin.readline
class segment_tree:
    '''
    init_val(int): 初期化値
    Input(array):  入力
    '''
    def __init__(self, init_val, Input):
        #self.num:n以上の最小の2のべき乗(一番下のNodeの数)
        n=len(Input)
        self.init_val = init_val
        self.num = 2 ** (n - 1).bit_length()
        self.seg = [init_val] * 2 * self.num
        for i in range(n):
            self.seg[i + self.num - 1] = Input[i]
        for i in range(self.num - 2, -1, -1):
            self.seg[i]=self._segfunc(self.seg[2*i+1],self.seg[2*i+2])
    def _segfunc(self, left, right):
        '''
        ここに求めたい関数を入れる
        ex)最小値問題→min, 
        left:左の子
        right:右の子
        '''
        res=fractions.gcd(left,right)
        return res
    def update(self, k, x):
        '''
        k番目の値をxに書き換える
        '''
        k += self.num - 1
        self.seg[k] = x
        while k > 0:
            k = (k - 1) // 2
            self.seg[k] = self._segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
    def query(self, p, q):
        '''
        区間[p,q)の目的の値を取り出す
        '''
        if q <= p:
            return self.init_val
        p += self.num - 1
        q += self.num - 2
        res = self.init_val
        while q - p > 1:
            if p % 2 == 0: #始点が偶数or終点が奇数だと端っこが余る
                res = self._segfunc(res, self.seg[p])
            if q % 2 == 1:
                res = self._segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        res = self._segfunc(res, self.seg[p])
        res = self._segfunc(res, self.seg[q])
        return res
INF = 10 ** 10
n=int(input())
a=list(map(int,input().split()))

# a = [randint(0,N*2) for _ in range(N)]
dp = segment_tree(0, a)
ans=-1
for i in range(n):
  ans=max(ans,fractions.gcd(dp.query(0,i),dp.query(i+1,n)))
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


class SegmentTree:
    # セグ木は 1-indexed
    def __init__(self, n, initial=0):
        """
        n: 配列の大きさ
        initial: 単位元 (RMQでは大きな値)
        """
        self.offset = 2**(n-1).bit_length()  # 2進数表記の長さ
        self.initial = initial
        self.seg = [self.initial] * (2 * self.offset)
        

    def build(self, A):
        """
        A: 処理したい配列
        """
        for i, a in enumerate(A, start=self.offset):
            self.seg[i] = a
        for i in range(self.offset-1,0,-1):
            self.seg[i] = gcd(self.seg[i<<1] ,self.seg[(i<<1)+1])

            
    def update(self, k, a):
        """
        k番目の値をaに変更
        """
        k += self.offset
        self.seg[k] = a
        while k:
            k >>= 1
            self.seg[k] = gcd(self.seg[k<<1], self.seg[(k<<1)+1])

            
    def query(self, a, b):
        """
        区間[a, b)に対して最小公倍数を求める
        """
        a += self.offset
        b += self.offset - 1 
        res = self.initial
        while a < b:
            if a & 1:  # 兄弟の右なら
                res = gcd(res, self.seg[a])
                a += 1
            if not b & 1:  # 兄弟の左なら
                res = gcd(res, self.seg[b])
                b -= 1
            a >>= 1
            b >>= 1
        
        if a == b:
            res = gcd(res, self.seg[a])
        
        return res


if __name__ == "__main__":
    N = int(readline())
    A = [int(i) for i in readline().split()]
    seg = SegmentTree(N)
    seg.build(A)

    ans = seg.query(1, N)
    for i in range(N-2):
        tmp = gcd(seg.query(0, i+1), seg.query(i+2, N))
        ans = max(ans, tmp)
    ans = max(ans, seg.query(0, N-1))

    print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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

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

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

ans = 0
#print(L, R)
for i in range(n):
    ans = max(ans, gcd(L[i], R[i + 1]))
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

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

gcd = math.gcd(A[0], A[1])

for i in range(2, n - 1):
    gcd = math.gcd(gcd, A[i])

ans = gcd
for i in range(1, n - 1):
    gcd1 = A[i - 1]
    gcd2 = A[i + 1]
    for j in range(i - 1):
        gcd1 = math.gcd(gcd1, A[j])
    
    for j in range(i + 2, n - 1):
        gcd2 = math.gcd(gcd2, A[i])
    gcd = math.gcd(gcd1, gcd2)
    ans = max(ans, gcd)
    
print(ans)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import math

n = int(input().rstrip())
numbers = [int(i) for i in input().rstrip().split(" ")]

l_list = [numbers[0]]
for i in range(1, n):
    l_list.append(math.gcd(l_list[i - 1], numbers[i]))

r_list = [numbers[len(numbers) - 1]]
for i in reversed(range(0, n - 1)):
    r_list.insert(0, math.gcd(r_list[0], numbers[i]))

ans = 0
for i in range(n):
    l = 0
    if i > 0:
        l = l_list[i - 1]
    r = 0
    if i < n - 1:
        r = r_list[i + 1]
    if l == 0:
        l = r
    if r == 0:
        r = l
    ans = max(ans, math.gcd(l, r))
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
N=int(input())
A=list(map(int,input().split()))
s=[]
for i in range(N):
  del A[i]
  ans=A[0]
  for j in range(N-1):
    ans=fractions.gcd(ans,A[j])
  s.append(ans)
print(max(s))

Submission status: Runtime Error

Solution code:
import fractions
N=int(input())
A=list(map(int,input().split()))
s=[]
for i in range(N):
  B=A.pop(i)
  for j in range(N-1):
    ans=fractions.gcd(ans,B[j])
  s.append(ans)
print(max(s))

Submission status: Runtime Error

Solution code:
import fractions
import functools

def main():
    n = int(input())
    a = [int(t)for t in input().split()]

    a_gcd = functools.reduce(fractions.gcd,a)
    a = [x//a_gcd for x in a]
    gcdlist = []

    max = 1
    for i in range(n):
        t = a
        del t[i]
        t_gcd = functools.reduce(fractions.gcd,t)
        max = t_gcd if t_gcd>max else max

    print(a_gcd*max(gcdlist))
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import fractions
import functools
 
def main():
    n = int(input())
    a = [int(t)for t in input().split()]
 
    a_gcd = functools.reduce(fractions.gcd,a)
  
  	a = [x//a_gcd for x in a]
    gcdlist = []
 
    for i in range(n):
        t = [x for x in a]
        del t[i]
        t_gcd = functools.reduce(fractions.gcd,t)
        gcdlist.append(t_gcd)
 
    print(a_gcd*max(gcdlist))
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import functools
import math
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(N):
  C=A.pop(i)
  gcd=functools.reduce(math.gcd,A)
  B.append(gcd)
print(max(B))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
gcd_left = [0] * N
gcd_right = [0] * N
chk = 1
for i in range(N):
	if i == 0:
		chk = A[0]
	else:
		chk = fractions.gcd(chk,A[i])
	gcd_left[i] = chk
temp = 0
for i in range(N):
	num = N-1-i
	if i == 0 :
		temp = A[num]
	else:
		temp = fractions.gcd(temp,A[num])
	gcd_right[num] = temp
ans = 0
for i in range(N):
	if i == 0:
		ans = max(ans,gcd_right[1])
	elif i == N-1:
		ans = max(ans,gcd_left[N-2])
	else:
		ans = max(ans,fractions.gcd(gcd_left[i-1],gcd_right[i+1]))
print(ans)

Submission status: Runtime Error

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

import fractions
from functools import reduce

def gcd(nl):
    if len(nl) == 1:
        return int(nl(0))
    else:
        return reduce(fractions.gcd, nl)

ng = gcd(A)
A = [A[i]//ng for i in range(N)]

ans = []
for i in range(N):
    k = A[i]
    del A[i]
    g = gcd(A)
    ans.append(g)
    A.insert(i, k)

f = ng
for i in range(len(ans)):
    f *= ans[i]

print(f)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
N=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(N):
    new1=a[:i]
    new2=a[i+1:N-1]
    g1=reduce(fractions.gcd,new1)
    g2=reduce(fractions.gcd,new2)
    g=fractions.gcd(g1,g2)
    ans.append(g)
print(max(ans))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
N=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(N):
    new1=a[:i]
    new2=a[i+1:]
    g1=reduce(fractions.gcd,new1)
    g2=reduce(fractions.gcd,new2)
    g=fractions.gcd(g1,g2)
    ans.append(g)
print(max(ans))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
N=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(N):
    new1=a[:i]
    new2=a[i+1:]
    g1=reduce(fractios.gcd,new1)
    g2=reduce(fractios.gcd,new2)
    g=fractios.gcd(g1,g2)
    ans.append(g)
print(max(ans))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
N=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(N):
    new1=a[:i]
    new2=a[i+1:]
    g1=reduce(fractios.gcd,new1)
    g2=reduce(fractios.gcd,new2)
    g=fractios.gcd(new1,new2)
    ans.append(g)
print(max(ans))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
N=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(N):
    new=a[:i]+a[i+1:]
    g=reduce(fractios.gcd,new)
    ans.append(g)
print(max(ans))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
N=int(input())
a=list(map(int,input().split()))
ans=[]
for i in range(N):
    new=a[:i]+a[i+1:]
    g=reduce(math.gcd,new)
    ans.append(g)
print(max(ans))

Submission status: Runtime Error

Solution code:

MOD = 1000000007

def main():
    n,m = map(int,input().split())
    al = [False for _ in range(n+1)]
    for i in range(m):
        a = int(input())
        al[a] = True
    
    dp = [0 for _ in range(n+1)]
    dp[0] = 1
    dp[1] = 1 if al[1] == False else 0

    for i in range(2,n+1):
        if not al[i]:
            dp[i] = (dp[i-2] + dp[i-1]) % MOD

    print(dp[n])


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

s1 = [a[0]]
s2 = [a[-1]]
for i in range(1, len(a)-1):
    s1.append(gcd(s1[-1], a[i]))
    s2 = [gcd(s2[-1], a[-(i+1)])] + s2
s1 = [a[-1]] + s1
s2 = s2 + [a[0]]


ans = 0
for i in range(len(s1)):
    ans = max(ans, (gcd(s1[i], s2[i])))

print(max(ans))

Submission status: Runtime Error

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

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

s1 = [a[0]]
s2 = [a[-1]]
for i in range(1, len(a)-1):
    s1.append(gcd(s1[-1], a[i]))
    s2 = [gcd(s2[-1], a[-(i+1)])] + s2
s1 = [a[-1]] + s1
s2 = s2 + [a[0]]


ans = 0
for i in range(len(s1)):
    ans = max(ans, (gcd(s1[i], s2[i])))

print(max(s3))

Submission status: Runtime Error

Solution code:
def divisors(n):
    divisors = set({1, n})
    for i in range(2, int(n**0.5)+1):
        q, r = divmod(n, i)
        if not r:
            divisors.add(i)
            divisors.add(q)
    return divisors

n = int(input())
A = map(int, input().split())
B = (divisors(a) for a in A)
c = Counter(chain_from_iterable(B))
print(max(k for k, v in c.items() if v >= n-1))

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

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

print(sorted(neighbors_gcd)[2])

Submission status: Runtime Error

Solution code:
from fractions import gcd


class SegmentTree():
    _data = []
    _offset = 0
    _size = 0

    def __init__(self, size):
        _size = size
        t = 1
        while t <= size:
            t *= 2
        self._offset = t - 1
        self._data = [0] * (t * 2 - 1)

    def update_all(self, iterable):
        self._data[self._offset:self._offset+self._size] = iterable
        for i in range(self._offset - 1, -1, -1):
            self._data[i] = gcd(self._data[i * 2 + 1], self._data[i * 2 + 2])

    def update(self, index, value):
        i = self._offset + index
        self._data[i] = value
        while i >= 1:
            i = (i - 1) // 2
            self._data[i] = gcd(self._data[i * 2 + 1], self._data[i * 2 + 2])

    def query(start, stop):
        result = 0
        l = start + self._offset
        r = stop + self._offset
        while l < r:
            if l & 1 == 1:
                result = gcd(result, self._data[l])
                l += 1
            if r & 1 == 1:
                r -= 1
                result = gcd(result, self._data[r])
            l >>= 1
            r >>= 1
        return result


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

st = SegmentTree(N)
st.update_all(A)

result = st.query(1, N)
for i in range(1, N - 1):
    result = max(result, gcd(st.query(0, i), st.query(i + 1, N)))
result = max(result, st.query(0, N - 1))
print(result)

Submission status: Runtime Error

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


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

#print(l,r)
r=r[::-1]
ans=[]
for i in range(n):
    ans.append(math.gcd(l[i],r[i+1]))
print(max(ans))

Submission status: Runtime Error

Solution code:
from fractions import gcd

class SegmentTree():
    _data = []
    _offset = 0
    
    def __init__(self, size):
        t = 1
        while t <= size:
            t *= 2
        self._offset = t - 1
        self._data = [0] * (t * 2 - 1)
    
    def update_all(self, iterable):
        for i, v in enumerate(iterable):
            self._data[i + self._offset] = v
        for i in range(self._offset - 1, -1, -1):
            self._data[i] = gcd(self._data[i * 2 + 1], self._data[i * 2 + 2])
    
    def update(self, index, value):
        i = self._offset + index
        self._data[i] = value
        while i >= 1:
            i = (i - 1) // 2
            self._data[i] = gcd(self._data[i * 2 + 1], self._data[i * 2 + 2])
    
    def _query(self, start, stop, index, left, right):
        if right <= start or stop <= left:
            return 0
        if start <= left and right <= stop:
            return self._data[index]
        a = self._query(start, stop, index * 2 + 1, left, (left + right) // 2)
        b = self._query(start, stop, index * 2 + 2, (left + right) // 2, right)
        return gcd(a, b)
    
    def query(self, start, stop):
        return self._query(start, stop, 0, 0, self._offset + 1)

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

st = SegmentTree(N)
st.update_all(A)

result = st.query(1, N)
for i in range(1, N - 1):
    result = max(result, gcd(st.query(0, i), st.query(i + 1, N)))
result = max(result, gcd(st.query(0, i), st.query(0, N - 1)))
print(result)

Submission status: Runtime Error

Solution code:
from fractions import gcd

class SegmentTree():
    _data = []
    _offset = 0
    
    def __init__(self, size):
        t = 1
        while t <= size:
            t *= 2
        self._offset = t - 1
        self._data = [0] * (t * 2 - 1)
    
    def update(self, iterable):
        for i, v in enumerate(iterable):
            self._data[i + self._offset] = v
        for i in range(self._offset - 1, -1, -1):
            self._data[i] = gcd(self._data[i * 2 + 1], self._data[i * 2 + 2])
    
    def update(self, index, value):
        i = self._offset + index
        self._data[i] = value
        while i >= 1:
            i = (i - 1) // 2
            self._data[i] = gcd(self._data[i * 2 + 1], self._data[i * 2 + 2])
    
    def _query(self, start, stop, index, left, right):
        if right <= start or stop <= left:
            return 0
        if start <= left and right <= stop:
            return self._data[index]
        a = self._query(start, stop, index * 2 + 1, left, (left + right) // 2)
        b = self._query(start, stop, index * 2 + 2, (left + right) // 2, right)
        return gcd(a, b)
    
    def query(self, start, stop):
        return self._query(start, stop, 0, 0, self._offset + 1)

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

st = SegmentTree(N)
for i in range(N):
    st.update(i, A[i])

result = st.query(1, N)
for i in range(1, N - 1):
    result = max(result, gcd(st.query(0, i), st.query(i + 1, N)))
result = max(t, gcd(st.query(0, i), st.query(0, N - 1)))
print(result)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce
import copy
N = input()
A = map(int, input())

def gcd(numbers):
    return reduce(fractions.gcd, numbers)
res = 0
for i in range(N):
  partA = copy.deepcopy(A).pop(i)
  if res < gcdres:
    res = gcdres

print(res)

Submission status: Runtime Error

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

from itertools import combinations
a = list(combinations(l, n-1))
#print(a)

from fractions import gcd
from functools import reduce

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

g = []
for i in range(len(a)):
    g.append(gcd_list(a[i]))
#print(g)
print(max(g))

Submission status: Runtime Error

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

from itertools import combinations
a = list(combinations(l, n-1))
#print(a)

from fractions import gcd
from functools import reduce

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

g = []
for i in range(len(a)):
    g.append(gcd_list(a[i]))

print(max(g))

Submission status: Runtime Error

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

from itertools import combinations
a = list(combinations(l, n-1))
#print(a)

from fractions import gcd
from functools import reduce

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

g = []
for i in range(len(a)):
    g.append(gcd_list(a[i]))

print(max(g))