Problem:


Score : 300 points

Problem Statement

There are N integers, A_1, A_2, ..., A_N, written on the blackboard.

You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.

Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Output

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Sample Input 1

3
7 6 8

Sample Output 1

2

If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.

Sample Input 2

3
12 15 18

Sample Output 2

6

Sample Input 3

2
1000000000 1000000000

Sample Output 3

1000000000

We can replace an integer with itself.



Sample input:
3
7 6 8


Sample output:
2

Submission status: Runtime Error

Solution code:

import math
a = int(input())
num_list = list(map(int, input().split()))
head_gcd_list = [num_list[0]]
tail_gcd_list = [num_list[-1]]
for i in range(a - 2):
    head_gcd_list.append(math.gcd(head_gcd_list[i], num_list[i+1]))
    tail_gcd_list.append(math.gcd(tail_gcd_list[(i*-1) - 1], num_list[(i*-1) - 2]))
max_gcd = max(head_gcd_list.pop(-1), tail_gcd_list.pop(-1))
for i,j in zip(head_gcd_list, reversed(tail_gcd_list)):
    current_gcd = math.gcd(i, j)
    if(current_gcd > max_gcd):
        max_gcd = current_gcd
print(max_gcd)

Submission status: Runtime Error

Solution code:

import math
input()
num_list = list(map(int, input().split()))
head_gcd_list = [num_list[0]]
tail_gcd_list = [num_list[-1]]
for i in range(len(num_list) - 1):
    head_gcd_list.append(math.gcd(head_gcd_list[i], num_list[i+1]))
    tail_gcd_list.append(math.gcd(tail_gcd_list[(i*-1) - 1], num_list[(i*-1) - 2]))
max_gcd = 0
for i,j in zip(head_gcd_list, reversed(tail_gdc_list)):
    current_gcd = math.gcd(i, j)
    if(current_gcd > max_gcd):
        max_gcd = current_gcd
print(max_gcd)

Submission status: Runtime Error

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

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

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    
    l = []
    for i in range(N):
        l2 = copy.deepcopy(A)
        l2[i] = max(A)
        l.append(l2)
    
    ans = [gcd_list(l3) for l3 in l]
    
    print(max(ans))
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import fraction
from functools import  reduce
N = int(input())
S = list(map(int,input().split()))
GCDs = []
for n in range(N):
    GCDs.append(reduce(fraction.gcd,([S[i] for i in range(N) if i != n])))

print(max(GCDs))

Submission status: Runtime Error

Solution code:
import math
from functools import  reduce
N = int(input())
S = list(map(int,input().split()))
GCDs = []
for n in range(N):
    GCDs.append(reduce(math.gcd,([S[i] for i in range(N) if i != n])))

print(max(GCDs))

Submission status: Runtime Error

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

def gcdl(lis):
    if len(lis)==1:
        return lis[0]
    f = gcd(lis[0], lis[1])
    lis1 = [lis[i] for i in range(2,len(lis))]
    lis1.append(f)
    return gcdl(lis1)

def intlinput():
    return list(map(int,input().split()))

n = int(input())
li = intlinput()
m = []
for i in li:
    tmp = copy.deepcopy(li)
    tmp.remove(i)
    m.append(gcdl(tmp))
print(max(m))

Submission status: Runtime Error

Solution code:
import math
import functools
import copy
N = int(input())
A = list(map(int,input().split()))
max = 0
for i in range(N):
    a = copy.copy(A)
    a.pop(i)
    gcd = functools.reduce(math.gcd,a)
    if gcd>max:
        max = gcd
print(max)

Submission status: Runtime Error

Solution code:
def mygcd(N,A,S):
    if S == 'R':
        A.reverse()
    ans = [0, A[0]]
    for i in range(1, N):
        ans.append(math.gcd(ans[i],A[i]))
    if S == 'R':
        ans.reverse()
    return ans

def GCDonBlack(N,A):
    L = mygcd(N,A,'L')
    R = mygcd(N,A,'R')
    M = [math.gcd(L[i], R[i+1])  for i  in range(0,N)]
    return max(M)

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

Submission status: Runtime Error

Solution code:
import math
import itertools

N = int(input())
Nlist = list(map(int, input().split()))
Mlist = list(itertools.combinations(Nlist,2))
Glist = []
for i in range(len(Mlist)):
    Glist.append(math.gcd(Mlist[i][0],Mlist[i][1]))

if len(Glist)>2:
    Glist = [j for j in Glist if j != min(Glist)]
print(min(Glist))

Submission status: Runtime Error

Solution code:
from fractions import gcd
import numpy as np
import copy as copy
N=int(input())
A_i=list(map(int,input().split()))


def GCD(N,A_i):
  if N==2:
    GCD=max(A_i)
  else:
    GCD=[]
    for i in range(N):
      A=A_i.copy()
      A=np.array(A)
      ind=[True]*N
      ind[i]=False
      A[i]=np.random.choice(A[np.where(ind)],1)
      ans=A[0]
      for j in range(N):
        ans=gcd(ans,A[j])
      GCD.append(ans)
  return max(GCD)

print(GCD(N,A_i))

Submission status: Runtime Error

Solution code:
import math as mt

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


def solve(n: int, a: list):
    lgcd = [0] * (n - 1)
    lgcd[0] = a[0]
    for i in range(1, n - 1):
        lgcd[i] = mt.gcd(a[i], lgcd[i - 1])
    a.reverse()

    rgcd = [0] * (n - 1)
    rgcd[0] = a[0]
    for i in range(1, n - 1):
        rgcd[i] = mt.gcd(a[i], rgcd[i - 1])
    a.reverse()

    ans = [0] * n
    ans[0] = rgcd[n - 2]
    ans[n - 1] = lgcd[n - 2]
    for i in range(1, n):
        ans[i] = mt.gcd(lgcd[i - 1], rgcd[n - 2 - i])

    return max(ans)


print(solve(N, A))

Submission status: Runtime Error

Solution code:
import math

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

if N == 2 :
    print(max(A[0], A[1]))
    exit()

others_gcd = []
for i in range(0, N) :
    max_gcd = 1
    for j in range(0, N) :
        if i == j :
            continue
        gcd = math.gcd(A[i], A[j])
        max_gcd = max(max_gcd, gcd)
    others_gcd.append(max_gcd)

print(max(others_gcd))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

gcdOrg = gcd(nums)
gcdMax = gcdOrg

for i in range(n):
    tempList = list(nums)
    del tempList[i]

    #temp = gcd(filter(index == i, nums))
    temp = gcd(tempList)

    if temp > gcdMax:
        gcdMax = temp

#print(gcdOrg)
print(gcdMax)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

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

def gcd(x, y):
    if x == 0:
        return y
    if y == 0:
        return x
        
    if y > x:
        temp = y
        y = x
        x = temp
    amari = x % y
    if amari == 0:
        return y
    else:
        return gcd(y, amari)
        
def L(i):
    if i == 0:
        return 0
    else:
        return gcd(L(i-1), A[i-2])
        
def R(i):
    if i == N+1:
        return 0
    else:
        return gcd(R(i+1), A[i-1])
        
M = [gcd(L(i), R(i+1)) for i in range(1, N+1)] # i=1,...,N

print(max(M))

Submission status: Runtime Error

Solution code:
import math

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

gcd_l, gcd_r = [0], [0]

for l, r in [(A[i], A[N-i-1]) for i in range(N)]:
    gcd_l.append(math.gcd(gcd_l[-1], l))
    gcd_r.append(math.gcd(gcd_r[-1], r))
gcd_r.reverse()

gcd_nums = [gcd_l[-1]] + [math.gcd(gcd_l[i], gcd_r[i+1]) for i in range(N)]
print(max(gcd_nums))

Submission status: Runtime Error

Solution code:
n = int(input())

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

left = [a[0]]
right = [a[-1]]

from math import gcd

for i in range(n):
    left.append(gcd(left[i], a[i]))
    right.append(gcd(right[i], a[-1-i]))

ans = [right[-2]]

for l, r in zip(left[2:-1], list(reversed(right[1:]))[2:]):
    ans.append(gcd(l, r))

ans.append(left[-2])

print(max(ans))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

n=input()
targets=[int(i) for i in input().split()]
max_gcd = 0
if len(targets) < 3:
    max_gcd = max(targets)
else:
    for i in targets:
        gcd = reduce(fractions.gcd, targets.remove(i))
        if gcd > max_gcd:
            max_gcd = gcd
print(max_gcd)

Submission status: Runtime Error

Solution code:
from math import gcd 


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

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

gcd_r = gcd_r[::-1]

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

print(max(ans))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

n=input()
targets=set([int(i) for i in input().split()])
max_gcd = 0
if targets < 3:
    max_gcd = max(targets)
else:
    for i in targets:
        gcd = reduce(fractions.gcd, targets - {i})
        if gcd > max_gcd:
            max_gcd = gcd
print(max_gcd)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

n=input()
targets=set([int(i) for i in input().split()])
max_gcd = 0
for i in targets:
    gcd = reduce(fractions.gcd, targets - {i})
    if gcd > max_gcd:
        max_gcd  = gcd
print(max_gcd)

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

n=input()
targets=set([int(i) for i in input().split()])
max_gcd =  0
for i in targets:
    gcd = reduce(fractions.gcd, targets - i)
    if gcd > max_gcd:
        max_gcd  = gcd
print(max_gcd)

Submission status: Runtime Error

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


def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    # As = sorted(As, reverse=True)

    memG = 0
    for i in range(N):
        tmp = As[:i] + As[i + 1 :]
        gI = gcd(tmp[0], tmp[1])
        tmp = tmp[2:]
        for t in tmp:
            gI = gcd(t, gI)
            if gI < memG:
                break
        if gI > memG:
            memG = gI
    print("{}".format(memG))


sub()

Submission status: Runtime Error

Solution code:
from math import gcd
from sys import stdin


def mygcd(lst):
    result = lst[0]
    for x in lst[1:]:
        result = gcd(result, x)
    return result


def main():
    _ = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    max_ = 0
    for a in As:
        tmp = As[:]
        tmp.remove(a)
        max_ = max(max_, mygcd(tmp))
    print(max_)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
import functools


def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]

    memG = 0
    for i in range(N):
        tmp = As[:i] + As[i + 1 :]
        g = functools.reduce(math.gcd, tmp)
        if g > memG:
            memG = g
    print("{}".format(memG))


sub()

Submission status: Runtime Error

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


def main():
    _ = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    max_ = 0
    for a in As:
        tmp = As[:]
        tmp.remove(a)
        max_ = max(max_, reduce(gcd, tmp))
    print(max_)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  
n=int(input())
l=list(map(int,input().split()))
if n==2:
  print(max(l))
else:
  ma=0
  if gcd(l[0],l[1])>ma:
    ma=gcd(l[0],l[1])
  if gcd(l[1],l[2])>ma:
    ma=gcd(l[1],l[2])
  if gcd(l[0],l[3]):
    ma=gcd(l[0],l[3])
  print(ma)

Submission status: Runtime Error

Solution code:

from functools import reduce
import math

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

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

    print(algorithm(N, A))


def algorithm(N, A):
    gcdList = [0] * N
    for i in range(N):
        copy_A = A.copy()
        copy_A.pop(i)
        gcdList[i] = gcd_list(copy_A)

    return max(gcdList)




problem()

Submission status: Runtime Error

Solution code:

import math
from functools import reduce


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


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

    print(algorithm(N, A))


def algorithm(N, A):
    gcdList = [0] * N
    for i in range(N):
        copy_A = A.copy()
        copy_A.pop(i)
        gcdList[i] = gcd_list(copy_A)

    return max(gcdList)
problem()

Submission status: Runtime Error

Solution code:

import math
from functools import reduce


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


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

    print(algorithm(N, A))


def algorithm(N, A):
    gcdList = [0] * N
    for i in range(N):
        copy_A = A.copy()
        copy_A.pop(i)
        gcdList[i] = gcd_list(copy_A)

    return max(gcdList)
problem()

Submission status: Runtime Error

Solution code:


import math
from functools import reduce

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


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

    print(algorithm(N, A))


def algorithm(N, A):
    gcdList = [0] * N
    for i in range(N):
        copy_A = A.copy()
        copy_A.pop(i)
        gcdList[i] = gcd_list(copy_A)

    return max(gcdList)

problem()

Submission status: Runtime Error

Solution code:


import math
from functools import reduce

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

    print(algorithm(N, A))


def algorithm(N, A):
    gcdList = [0] * N
    for i in range(N):
        copy_A = A.copy()
        copy_A.pop(i)
        gcdList[i] = gcd_list(copy_A)

    return max(gcdList)

problem()

Submission status: Runtime Error

Solution code:


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

    print(algorithm(N, A))


def algorithm(N, A):
    gcdList = [0] * N
    for i in range(N):
        copy_A = A.copy()
        copy_A.pop(i)
        gcdList[i] = gcd_list(copy_A)

    return max(gcdList)

problem()

Submission status: Runtime Error

Solution code:
import math
N=int(input())
As=str(input())
ListA=As.split()
ListA3=[]
for i in range(0,len(ListA),1):
  r=ListA.pop(0)
  ListA.append(int(r))
for i in range(0,len(ListA),1):
  ListA2=ListA
  ListA2.pop(i)
  for j in range(0,len(ListA2)-1,1):
    a=math.gcd(ListA2[0],ListA2[1])
    ListA2.pop(0)
    ListA2.pop(0)
    ListA2.insert(0,a)
  Q=ListA2[0]
  ListA3.append(Q)
ListA3.sort()
print(ListA3[-1])

Submission status: Runtime Error

Solution code:
import math
N=int(input())
As=str(input())
ListA=As.split()
ListA3=[]
for i in range(0,len(ListA),1):
  ListA2=ListA
  ListA2.pop(i)
  for j in range(0,len(ListA2)-1,1):
    a=math.gcd(ListA2[0],ListA2[1])
    ListA2.pop(0)
    ListA2.pop(0)
    ListA2.insert(0,a)
  Q=ListA2[0]
  ListA3.append(Q)
ListA3.sort()
print(ListA3[-1])

Submission status: Runtime Error

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

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

gcd_list =[]

for i, a in enumerate(A):
    A_except_a = copy.deepcopy(A)
    A_except_a.pop(i)
    
    gcd = reduce(math.gcd, A_except_a)
    gcd_list.append(gcd)

print(max(gcd_list))

Submission status: Runtime Error

Solution code:
#-*- coding:utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

import copy
import math
from functools import reduce

gcd_list =[]

for i, a in enumerate(A):
    A_except_a = copy.deepcopy(A)
    A_except_a.pop(i)
    
    gcd = reduce(math.gcd, A_except_a)
    gcd_list.append(gcd)

print(max(gcd_list))

Submission status: Runtime Error

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

N = int(input())
A = list(map(int,input().split()))
def L(i):
    if i == 0 or i == 1:
        return 0
    else:
        return(gcd(L(i-1),A[i-2]))
def R(i):
    if i == N+1:
        return 0
    else:
        return(gcd(R(i+1),A[i-1]))
gcd_max = 0
for i in range(1,N+1):
    gcd_max = max(gcd_max,gcd(L(i),R(i+1)))
print(gcd_max)

Submission status: Runtime Error

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

N = int(input())
A = list(map(int,input().split()))
def L(i):
    if i == 0 or i == 1:
        return 0
    else:
        return(gcd(L(i-1),A[i-2]))
def R(i):
    if i == N+1:
        return 0
    else:
        return(gcd(R(i+1),A[i-1]))
gcd_max = 0
for i in range(N):
    gcd_max = max(gcd_max,gcd(L(i),R(i+1)))
print(gcd_max)

Submission status: Runtime Error

Solution code:
from functools import reduce

N = int(input())
A = list(map(int,input().split()))
gcd_max = 0
for i in range(N):
    B = A.copy()
    B[i:i+1] = []
    gcd_max = max(gcd_max,reduce(gcd,B))
print(gcd_max)

Submission status: Runtime Error

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

import math
def gcd(list):
    gcd = list[0]
    for a in list:
        gcd = math.gcd(gcd, a)
    return gcd

max_gcd = 0
for i in range(n):
    Ai = A.pop(i)
    max_gcd = max(max_gcd, gcd(A))
    A.insert(i, Ai)

print(max_gcd)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
import math
from functools import reduce
AA_list = [0]
AA_list.extend(A)
AA_list.append(0)

def return_gcd(input_list):
    try:
        return reduce(math.gcd, input_list)
    except:
        return input_list[0]
      
M_list = []
for ii in range(1, N+1):
    M_list.append(math.gcd(return_gcd(AA_list[:ii]), return_gcd(AA_list[ii+1:])))
    
print(max(M_list))

Submission status: Runtime Error

Solution code:
from fractions import gcd

def get_gcd(l):
    if len(l) == 1:
        return l[0]
    elif len(l) == 2:
        return gcd(l[0], l[1])

    return gcd(l[:int(len(l))], l[int(len(l)):])

n = input()

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

def check(v):
    result = 0

    if len(v) == 1:
        return v[0]

    for i in range(len(v)):
        w = v.copy()
        del w[i]
        tmp_result = get_gcd(w)
        if result < tmp_result:
            result = tmp_result

print(check(v))

Submission status: Runtime Error

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

max_gcd = 0
for ii in itertools.combinations(A, len(A)-1):
    if max_gcd < reduce(math.gcd, list(ii)):
        max_gcd = reduce(math.gcd, list(ii))
    
print(max_gcd)

Submission status: Runtime Error

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

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

max_gcd = 0
for ii in itertools.combinations(A, len(A)-1):
    if max_gcd < gcd_list(list(ii)):
        max_gcd = gcd_list(list(ii))
    
print(max_gcd)

Submission status: Runtime Error

Solution code:
from fractions import gcd

def get_gcd(l):
    if len(l) == 1:
        return l[0]
    elif len(l) == 2:
        return gcd(l[0], l[1])

    return gcd(l[:int(len(l))], l[int(len(l)):])

n = input()

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

result = 0
if len(v) == 1:
    print(v[0])
    exit

for i in range(len(v)):
    w = v.copy()
    del w[i]
    tmp_result = get_gcd(w)
    if result < tmp_result:
        result = tmp_result

print(result)

Submission status: Runtime Error

Solution code:
from fractions import gcd

def get_gcd(l):
    if len(l) == 1:
        return l[0]
    elif len(l) == 2:
        return gcd(l[0], l[1])

    return gcd(l[:int(len(l))], l[int(len(l)):])

n = input()

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

result = 0
for i in range(len(v)):
    w = v.copy()
    del w[i]
    tmp_result = get_gcd(w)
    if result < tmp_result:
        result = tmp_result

print(result)

Submission status: Runtime Error

Solution code:
import math, itertools

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

gcdl = []
coml = list(itertools.combinations(a,2))

for x in range(len(coml)) :
    gcdl.append(math.gcd(coml[x][0], coml[x][1])) 

gcdl.sort()
min = gcdl[0]
for x in range(1, len(coml)) :
    if min != gcdl[x] :
        break

print(gcdl[x])

Submission status: Runtime Error

Solution code:
import itertools

import math
from functools import reduce

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


N = int(input())

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

L = list(itertools.combinations(A,N-1))

max = 0

for l in L:
    gl = gcd_list(l)
    if max < gl:
        max = gl

print(max)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


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


N = int(input())
lst = [int(x) for x in input().split()]
ans = 0
if N >= 3:
    for n in range(N):
        temp = gcd([x for x in lst if lst.index(x) != n])
        ans = temp if temp>ans else ans
    print(ans)
else:
    print(max(lst))

Submission status: Runtime Error

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

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

max_gcd = 0
for ii in itertools.combinations(A, len(A)-1):
    if max_gcd < gcd_list(list(ii)):
        max_gcd = gcd_list(list(ii))
    
print(max_gcd)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
import itertools
from functools import reduce

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

max_gcd = 0
for ii in itertools.combinations(A, len(A)-1):
    if max_gcd < gcd_list(list(ii)):
        max_gcd = gcd_list(list(ii))
    
print(max_gcd)

Submission status: Runtime Error

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

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

max_gcd = 0
for ii in itertools.combinations(A, len(A)-1):
    if max_gcd < gcd_list(list(ii)):
        max_gcd = gcd_list(list(ii))
    
print(max_gcd)

Submission status: Runtime Error

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

# print(n)
# print(aList)

import math


import math
from functools import reduce

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

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

#print(gcd_list(aList))

# 1つずつ要素を削りながら最大公約数を検索
maxGCD = 0
for i in range(n):
	tempList = aList.copy()
	# print(i)
	# #print(aList)
	# print(tempList.pop(i))
	# print(tempList)
	# print("---")
	# print(gcd_list(tempList))

	tempList.pop(i)
	gcd = gcd_list(tempList)
	if gcd > maxGCD:
		maxGCD = gcd

print(maxGCD)

Submission status: Runtime Error

Solution code:
import itertools
a=int(input())
b=list(map(int,input().split()))
aak=list(itertools.combinations(b,a-1))
ans=[]
def gud(a,b):
  if a%b==0:
    return b
  else:
    return gud(b,a%b)
def allgud(a):
  if len(a)==1:
    return a[0]
  else:
    a+=(gud(a[0],a[1]),)
    return allgud(a[2:])
ans=list(map(lambda d: allgud(d) ,aak))
print(max(ans))

Submission status: Runtime Error

Solution code:
import itertools
a=int(input())
b=list(map(int,input().split()))
aak=list(itertools.combinations(b,a-1))
ans=[]
def gud(a,b):
  if a%b==0:
    return b
  else:
    return gud(b,a%b)
def allgud(a):
  if len(a)==1:
    return a[0]
  else:
    a+=(gud(a[0],a[1]),)
    return allgud(a[2:])
ans=[]
for i in aak:
  ans+=[allgud(i)]
print(max(ans))

Submission status: Runtime Error

Solution code:
from math import gcd

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

forward = []
backward = [0 for x in range(n)]

if n == 2:
    print(max(a[0], a[1]))
    exit(0)

for i in range(n):
    if i == 0:
        forward.append(a[i])
    else:
        forward.append(gcd(forward[i - 1], a[i]))


for i in range(n - 1, -1, -1):
    if i == n - 1:
        backward[i] = a[i]
    else:
        backward[i] = gcd(backward[i + 1], a[i])


ans = 1

for i in range(n):
    if i == 0:
        ans = max(ans, backward[1])
    elif i == n - 1:
        ans = max(ans, forward[n - 2])
    else:
        ans = max(ans, gcd(forward[i - 1], backward[i + 1]))

print(ans)

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

forward = []
backward = [0 for x in range(n)]

if n == 2:
    print(max(a[0], a[1]))
    exit(0)

for i in range(n):
    if i == 0:
        forward.append(a[i])
    else:
        forward.append(gcd(forward[i - 1], a[i]))


for i in range(n - 1, -1, -1):
    if i == n - 1:
        backward[i] = a[i]
    else:
        backward[i] = gcd(backward[i + 1], a[i])


ans = 1

for i in range(n):
    if i == 0:
        ans = max(ans, backward[1])
    elif i == n - 1:
        ans = max(ans, forward[n - 2])
    else:
        ans = max(ans, gcd(forward[i - 1], backward[i + 1]))

print(ans)

Submission status: Runtime Error

Solution code:
import itertools
a=int(input())
b=list(map(int,input().split()))
aak=list(itertools.combinations(b,a-1))
ans=[]
def gud(a,b):
  if a%b==0:
    return b
  else:
    return gud(b,a%b)
for i in aak:
  for v in range(a-2):
    i+=(gud(i[v],i[v+1]),)
    i+=1
  ans+=[i[-1]]
print(max(ans))

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

forward = []
backward = [0 for x in range(n)]

if n == 2:
    print(max(a[0], a[1]))
    exit(0)

for i in range(n):
    if i == 0:
        forward.append(a[i])
    else:
        forward.append(gcd(forward[i - 1], a[i]))


for i in range(n - 1, -1, -1):
    if i == n - 1:
        backward[i] = a[i]
    else:
        backward[i] = gcd(backward[i + 1], a[i])


ans = 1

for i in range(n):
    if i == 0:
        ans = max(ans, backward[1])
    elif i == n - 1:
        ans = max(ans, forward[n - 2])
    else:
        ans = max(ans, gcd(forward[i - 1], backward[i + 1]))

print ans

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

forward = []
backward = [0 for x in range(n)]

if n == 2:
    print(max(a[0], a[1]))
    exit(0)

for i in range(n):
    if i == 0:
        forward.append(a[i])
    else:
        forward.append(gcd(forward[i - 1], a[i]))


for i in range(n - 1, -1, -1):
    if i == n - 1:
        backward[i] = a[i]
    else:
        backward[i] = gcd(backward[i + 1], a[i])


ans = 1

for i in range(n):
    if i == 0:
        ans = max(ans, backward[1])
    elif i == n - 1:
        ans = max(ans, forward[n - 2])
    else:
        ans = max(ans, gcd(forward[i - 1], backward[i + 1]))

print ans

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-2):
  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:
n = int(input())
a = [int(x) for x in input().split()]

def gcd(x, y):
    #print('gcd({0},{1})'.format(x,y))
    if (y==0):
        return x
    else:
        return gcd(y, x%y)

def gcd_left(i):
    #print('gcd_left({0})'.format(i))

    if i<0:
        return 0
    else:
        return gcd(gcd_left(i-1), a[i])

def gcd_right(i):
    #print('gcd_left({0})'.format(i))
    
    if i>n-1:
        return 0
    else:
        return gcd(a[i],gcd_right(i+1))

def gcd_excepts(i):
    #print('gcd_excepts({0})'.format(i))
    return gcd( gcd_left(i-1), gcd_right(i+1))

m = [gcd_excepts(i) for i in range(n)]

print(max(m))

Submission status: Runtime Error

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

def gcd(x, y):
    #print('gcd({0},{1})'.format(x,y))
    if (y==0):
        return x
    else:
        return gcd(y, x%y)

def gcd_left(i):
    #print('gcd_left({0})'.format(i))

    if i==-1:
        return 0
    else:
        return gcd(gcd_left(i-1), a[i])

def gcd_right(i):
    #print('gcd_left({0})'.format(i))
    
    if i==n:
        return 0
    else:
        return gcd(a[i],gcd_right(i+1))

def gcd_excepts(i):
    #print('gcd_excepts({0})'.format(i))
    if n==1:
        return a[i]
    else:
        return gcd( gcd_left(i-1), gcd_right(i+1))

m = [gcd_excepts(i) for i in range(n)]

print(max(m))

Submission status: Runtime Error

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

def gcd(x, y):
    #print('gcd({0},{1})'.format(x,y))
    if (y==0):
        return x
    else:
        return gcd(y, x%y)

def gcd_left(i):
    #print('gcd_left({0})'.format(i))

    if i==-1:
        return 0
    else:
        return gcd(gcd_left(i-1), a[i])

def gcd_right(i):
    #print('gcd_left({0})'.format(i))
    
    if i==n:
        return 0
    else:
        return gcd(a[i],gcd_right(i+1))

def gcd_excepts(i):
    #print('gcd_excepts({0})'.format(i))

    return gcd( gcd_left(i-1), gcd_right(i+1))

m = [gcd_excepts(i) for i in range(n)]

print(max(m))

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()
    if N == 2:
        print(max(A[0], A[1]))
        return
    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()