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
from functools import reduce
import sys
sys.setrecursionlimit(10**6)

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

N = int(input())
A = []
A = list(map(int, input().split()))
len = len(A)
gcd = 1

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

for i in range(len):
    x = A.pop(i)
    print(i)
    if gcd_list(A) > gcd:
        gcd = gcd_list(A)
    A.insert(i, x)
print(gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
import sys
sys.setrecursionlimit(10**6)

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

N = int(input())
A = []
A = list(map(int, input().split()))
len = len(A)
gcd = 1

if gcd_list(A) > gcd:
    gcd = gcd_list(A)

if len > 2:
    for i in range(len):
        x = A.pop(i)
        if gcd_list(A) > gcd:
            gcd = gcd_list(A)
        A.insert(i, x)
print(gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

N = int(input())
A = []
A = list(map(int, input().split()))
len = len(A)
gcd = 1

if gcd_list(A) > gcd:
    gcd = gcd_list(A)

if len > 2:
    for i in range(len):
        x = A.pop(i)
        if gcd_list(A) > gcd:
            gcd = gcd_list(A)
        A.insert(i, x)
print(gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

N=int(input())
A=[]
A=list(map(int,input().split()))
len=len(A)
gcd=1
new=A[0]

if gcd_list(A)>gcd:
    gcd=gcd_list(A)

if(len>2):
    for i in range(len):
        x=A.pop(i)
        if gcd_list(A)>gcd:
            gcd=gcd_list(A)
            new=gcd
            j=i
        A.insert(i,x)
A.pop(j)
A.insert(j,gcd)
print(gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

N=int(input())
A=[]
A=list(map(int,input().split(" ",N)))
len=len(A)
gcd=1
new=A[0]

if gcd_list(A)>gcd:
    gcd=gcd_list(A)

if(len>2):
    for i in range(len):
        x=A.pop(i)
        if gcd_list(A)>gcd:
            gcd=gcd_list(A)
            new=gcd
            j=i
        A.insert(i,x)
A.pop(j)
A.insert(j,gcd)
print(gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

N=int(input())
A=[]
A=list(map(int,input().split(" ",N)))
len=len(A)
gcd=1

if gcd_list(A)>gcd:
    gcd=gcd_list(A)

if(len>2):
    for i in range(len):
        x=A.pop(i)
        if gcd_list(A)>gcd:
            gcd=gcd_list(A)
        A.insert(i,x)

print(gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

N=int(input())
A=[]
A=list(map(int,input().split(" ",N)))
len=len(A)
gcd=1

for i in range(len):
    x=A.pop(i)
    if gcd_list(A)>gcd:
        gcd=gcd_list(A)
    A.insert(i,x)

print(gcd)

Submission status: Runtime Error

Solution code:

import functools
import math

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

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

gcdlist = [0] * n


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

#print(gcdlist)

j = gcdlist.index(max(gcdlist))

#print(j)

a[j] = gcdlist[j]

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

Submission status: Runtime Error

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

n=int(input())
al=input().split()
al_i = [int(s) for s in al]

if (n == 2):
   print(gcd(al_i[0],al_i[1])
　 return
         
fg = [0] * n
bg = [0] * n

for x in range(n):
   if (x == 0):
       fg[0] = al_i[0]
       y = 1
   else:
      while y <= x:
         fg[y] = gcd(fg[y-1], al_i[y])
         y += 1

for x in range(n):
   if (x == 0):
      bg[0] = al_i[n-1]
      y = 1
   else:
      while y <= x:
         bg[y] = gcd(bg[y-1], al_i[n-1-y])
         y += 1

m = 0
gm = 0

for x in range(n):
   if (x == 0):
      g = bg[n-2]
   elif (x == n):
      g = fg[n-2]
   else:
      g = gcd(fg[x-1],bg[n-2-x])
   if (g > gm):
      gm = g

print(gm)

Submission status: Runtime Error

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

n=int(input())
al=input().split()
al_i = [int(s) for s in al]

for x in range(n):
   if (x == 0):
       fg[0] = al_i[0]
       y = 1
   else:
      while y <= x:
         fg[y] = gcd(fg[y-1], al_i[y])
         y += 1
for x in range(n):
   if (x == 0):
      bg[0] = al_i[n-1]
      y = 1
   else:
      while y <= x:
         bg[y] = gcd(bg[y-1], al_i[n-1-y])
         y += 1

m = 0
gm = 0

for x in range(n):
   if (x == 0):
      g = bg[n-2]
   elif (x == n):
      g = fg[n-2]
   else:
      g = fg[x-1] + bg[n-2-x]
   if (g > gm):
      g = gm

print(gm)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from itertools import combinations

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

pattern = list(combinations(a,(len(a)-1)))
#print(pattern)
#print(pattern[0][0])


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

max = 0
for i in range(len(pattern)):
    #print(pattern[i])
    #print(gcd_list(pattern[i]))
    #print(gcd_list(pattern[i]))
    temp = gcd_list(pattern[i])
    if(temp > max):
        max = temp

print(max)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from itertools import combinations

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

pattern = list(combinations(a,n-1))
#print(pattern)
#print(pattern[0][0])


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

max = 0
for i in range(len(pattern)):
    #print(pattern[i])
    #print(gcd_list(pattern[i]))
    #print(gcd_list(pattern[i]))
    temp = gcd_list(pattern[i])
    if(temp > max):
        max = temp

print(max)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

n=int(input())
al=input().split()
al_i = [int(s) for s in al]
m = max(al_i)
gm = 0

for x in range(n):
   t = al_i[x]
   al_i[x] = m
   g = gcd(*al_i)
   al_i[x] = t
   if g>gm:
      gm = g
print(gm)

Submission status: Runtime Error

Solution code:
import math


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

left_gcd_list = [a[0]]
right_gcd_list = [a[n - 1]]

for i in range(1, n):
    left_gcd_list.append(math.gcd(a[i], left_gcd_list[i - 1]))
    right_gcd_list.insert(0, math.gcd(a[n - 1 - i], right_gcd_list[0]))

print(max([left_gcd_list[n - 2]] +
          [math.gcd(left_gcd_list[i], right_gcd_list[i + 2]) for i in range(0, n - 2)] +
          [right_gcd_list[1]]))


if __name__ == '__main__':
    pass

Submission status: Runtime Error

Solution code:
_ = input()
L = list(map(int, input().split()))
L_set = list(set(L))
L_set.sort()
L_set = L_set[::-1]


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    # print(divisors[::-1])
    return divisors[::-1]


def search(yakusu_list):
    for yakusu in yakusu_list:
        cnt = 0
        for l in L:
            if l % yakusu != 0:
                cnt += 1
        if cnt == 1 or cnt == 0:
            print(yakusu)
            return True
        else:
            pass
    return False


if not search(make_divisors(L_set[0])[:-1]):
    if not search(make_divisors(L_set[1])):
        print(1)

Submission status: Runtime Error

Solution code:
import math


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

left_gcd_list = [a[0]]
right_gcd_list = [a[n - 1]]

for i in range(1, n):
    left_gcd_list.append(math.gcd(a[i], left_gcd_list[i - 1]))
    right_gcd_list.insert(0, math.gcd(a[n - 1 - i], right_gcd_list[0]))

print(max([left_gcd_list[n - 2]] +
          [math.gcd(left_gcd_list[i], right_gcd_list[i + 2]) for i in range(0, n - 2)] +
          [right_gcd_list[n - 2]]))


if __name__ == '__main__':
    pass

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
from itertools import combinations

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

pattern = list(combinations(a,n-1))
#print(pattern)
#print(pattern[0][0])


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

max = 0
for i in range(n):
    #print(pattern[i])
    #print(gcd_list(pattern[i]))
    if(gcd_list(pattern[i]) > max):
        max = gcd_list(pattern[i])

print(max)

Submission status: Runtime Error

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

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

for i in range(n):
    gc=a[0]
    for j in range(n):
        if j!=i:
            gc=gcd(gc,b[j])
    ggcd=max(gc,ggcd)

print(ggcd)

Submission status: Runtime Error

Solution code:
import importlib
import_module = lambda name:importlib.import_module(name)

input = import_module('sys').stdin.readline
input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_ints_list = lambda:list(input_ints())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

gcd_base = lambda a,b:import_module('fractions').gcd(a,b) # 最大公約数（2値)
gcd = lambda a:import_module('functools').reduce(gcd_base,a) # 最大公約数（リスト）
lcm_base = lambda a,b:(a*b)//import_module('fractions').gcd(a,b) # 最小公倍数(2値)
lcm = lambda a:import_module('functools').reduce(lcm_base,a,1) # 最小公倍数(リスト)

permutations = lambda a,n:import_module('itertools').permutations(a,n) # 順列
combinations = lambda a,n:import_module('itertools').combinations(a,n) # 組み合わせ
product = lambda a,b:import_module('itertools').product(a,b) # 二つのリストの直積

init_array_1dim = lambda v,n:[v]*n
init_array_2dim = lambda v,n,m:[init_array_1dim for _ in range(m)]

# 四捨五入はround
ceil = lambda a:import_module('math').ceil(a) # 切り上げ
floor = lambda a:import_module('math').floor(a) # 切り捨て

# キュー
convert_list_to_queue = lambda a:import_module('collections').deque(a)
pop_q = lambda a:a.popleft()
push_q = lambda a,e:a.appendleft(e)
push_q_list = lambda a,l:a.extendleft(l) 

# プライオリティキュー
def init_head(a):import_module('heapq').heapify(a)
def heap_push(a,v):import_module('heapq').heappush(a,v)
heap_pop = lambda a:import_module('heapq').heappop(a) # 最小値を取り出す

# 二分探索
bisect_left = lambda a,x:import_module('bisect').bisect_left(a,x)
bisect_right = lambda a,x:import_module('bisect').bisect_left(a,x)
insert_left = lambda a,x:import_module('bisect').insert_left(a,bisect_left(a,x))
insert_right = lambda a,x:import_module('bisect').insert_right(a,bisect_right(a,x))

# 累積和、累積積、累積GCD
cumsum = lambda a:import_module('numpy').cumsum(import_module('numpy').array(a)) # 累積和
cumprod = lambda a:import_module('numpy').cumprod(import_module('numpy').array(a)) # 累積積
cumgcd = lambda a:import_module('numpy').frompyfunc(gcd_base, 2, 1).accumulate(a, dtype=import_module('numpy').object).astype(import_module('numpy').int) # 累積GCD

class UnionFind(object):
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

# グラフで全部到達できる経路が何個あるか
def dfs_graph(v,n,graph,visited):
    if all(visited):return 1 # 全部到達できたら1を返す
    ans = 0
    for i in range(n):
        if not graph[v][i]:continue # 結ぶ線がないときはスキップ
        if visited[i]:continue # 到達済みだったらスキップ
        visited[i] = True
        ans += dfs_graph(i,n,graph,visited)
        visited[i] = False
    return ans

# ワーシャルフロイド（グラフの要素数、グラフ）
def warshall_floyd(n,graph):
    d = init_array_2dim(float("inf"),n,n)
    # 初期化
    for i in range(n):
        d[i][i] = 0
        for j in range(n):
            if graph[i][j]:d[i][j] = 1
    # 距離算出
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

# グラフを初期化（グラフの要素数、グラフの線の両端、有向無向）
def init_graph(n,a,directed=False):
    visited = init_array_1dim(False,n)
    graph = init_array_2dim(False,n,n)
    for e in a:
        graph[e[0]-1][e[1]-1] = True
        if not directed:graph[e[1]-1][e[0]-1] = True # 無向グラフの場合
    return visited,graph

def two_pointers(s,threshold,ope='sum'):
    l,r = 0,0
    base = 0 
    if ope == 'sum':base = 0
    if ope == 'prd':base = 1
    diff = 0
    while r < len(s):
        val = 0
        if ope == 'sum':val = base+s[r]
        if ope == 'prd':val = base*s[r]
        if val <= threshold:
            if ope == 'sum':base += s[r]
            if ope == 'prd':base *= s[r]
            diff = max(diff, r-l+1)
            r += 1
        elif l == r:
            r += 1
            l += 1
        else:
            if ope == 'sum':base -= s[l]
            if ope == 'prd':base //= s[l]
            l += 1
    return diff

def solution():
    import numpy as np
    N = input_int()
    A = np.array(input_ints_list())
    A = np.sort(A)

    max_gcd = -1
    for i in range(min(len(A),3)):
        nota = np.delete(A,i)
        gcd_nota = np.gcd.reduce(nota.tolist())
        max_gcd = gcd_nota if max_gcd < gcd_nota else max_gcd
    
    print(max_gcd)
	
if __name__ == '__main__':
    solution()

Submission status: Runtime Error

Solution code:
import math


def gcd(numbers):
  res = numbers[0]
  for i in range(len(numbers)):
    res = math.gcd(res, numbers[i])
  return res


def main():
  input()
  arr = [int(x) for x in input().split()]
  M = 0
  for i in range(len(arr)):
    arr2 = arr[:i] + arr[i + 1:]
    M = max(M, gcd(arr2))

  print(M)


if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
 
 
def gcd(numbers):
  return reduce(math.gcd, numbers)
 
 
def main():
  N = int(input())
  arr = [int(x) for x in input().split()]
  M = 0
  for i in range(len(arr)):
    arr2 = arr[:i] + arr[i + 1:]
    M = max(M, gcd(arr2))
 
  print(M)
 
 
if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
n=int(input())
lis=list(map(int,input().split()))
li=[lis[0]]
l=[lis[n-1]]
for i in range (0,n-1):
  li.append(fractions.gcd(li[i],lis[i+1]))
  l.append(fractions.gcd(l[i],lis[n-i-2]))
li.insert(0,lis[0])
l.insert(0,lis[n-1])
ans_li=[]
for i in range(0,n-2):
  ans_li.append(fractions.gcd(li[i],l[n-3-i]))
ans_li.insert(0,li[n-2])
ans_li.append(l[n-2])
ans_li.sort()           
ans_li.reverse()
print(ans_li[0])

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = [int(j) for j in input().split()]
gcdmx = 0
for j in range(0,N):
    gcdloc = 0
    C = A[:]
    del C[j]
    for k in range(0,N-1):
        gcdloc = math.gcd(gcdloc,C[k])
    gcdmx = max(gcdloc,gcdmx)
print(gcdmx)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = [int(j) for j in input().split()]
B = [0]*N
B = A[:]
gcdmx = 0
for j in range(0,N):
    gcdloc = 0
    C = B[:]
    del C[j]
    for k in range(0,N-1):
        gcdloc = math.gcd(gcdloc,C[k])
    gcdmx = max(gcdloc,gcdmx)
print(gcdmx)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = [int(j) for j in input().split()]
B = [0]*N
B = A[:]
gcdmx = 0
D = 1
for j in range(0,N):
    D = D * B[j]
for j in range(0,N):
    gcdloc = D
    C = B[:]
    del C[j]
    for k in range(0,N-1):
        gcdloc = math.gcd(gcdloc,C[k])
    gcdmx = max(gcdloc,gcdmx)
print(gcdmx)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = [int(j) for j in input().split()]
B = [0]*N
B = A[:]
D = 1
gcdmx = 0
for k in range(0,N):
        D = D * B[k]
for j in range(0,N):
    C = B[:]
    C[j] = D
    gcdloc = D
    for k in range(0,N):
        gcdloc = math.gcd(gcdloc,C[k])
    gcdmx = max(gcdloc,gcdmx)
print(gcdmx)

Submission status: Runtime Error

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

import math
from functools import reduce
        
def gcd(*numbers):
  return reduce(math.gcd, numbers)
cnt=0
cnt_2=0
k=2

for i in range(N):
  if a[0]==a[i]:
    cnt+=1
if cnt==N:
  x=a[0]
else:
  while cnt_2==N-1:
    for j in range(N):
      l=[]
      if a[j]%k==0:
        cnt_2+=1
        l.append(a[j])
      k+=1    
  x=gcd(*l)

print(x)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


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


def main():
  N = int(input())
  arr = [int(x) for x in input().split()]
  M = 0
  for i in range(len(arr)):
    arr2 = arr[:i] + arr[i + 1:]
    M = max(M, gcd(arr2))

  print(M)


if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
def reduce_gcd(A):
    from math import gcd as GCD
    gcd = A[0]
    for i in A:
        gcd = GCD(gcd, i)
    return gcd

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

MAX = 0;
for i in range(N):
    a = A.pop()

    gcd = reduce_gcd(A)

    if MAX < gcd:
        MAX = gcd

    A.insert(0, a)

print(MAX)

Submission status: Runtime Error

Solution code:
from functools import reduce
import math

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


MAX = 0;
for i in range(N):
    a = A.pop()

    gcd = reduce(math.gcd, A)

    if MAX < gcd:
        MAX = gcd

    A.insert(0, a)

print(MAX)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
N = int(input())
A = [int(i) for i in input().split()]
if N>2:
    GCD = [gcd(*[e for s,e in enumerate(A) if s!=i]) for i in range(N)]
    print(max(GCD))
else:print(math.gcd(*A))

Submission status: Runtime Error

Solution code:
from fractions import gcd


def main(input_1, input_2):
    left = [0] * (input_1+1)
    for i in range(input_1):
        left[i+1] = gcd(left[i], input_2[i])

    right = [0] * (input_1 + 1)
    i = input_1 - 1
    while i >= 0:
        right[i] = gcd(right[i+1], input_2[i])
        i -= 1

    while i >= 0:
        right[i] = gcd(right[i+1], input_2[i])

    res = 0
    for i in range(input_1):
        l = left[i]
        r = right[i+1]
        gcd_val = gcd(l, r)
        if gcd_val > res:
            res = gcd_val

    return res


if __name__ == "__main__":
    input_1 = input()
    input_2 = list(map(int, input().split()))
    print(main(input_1, input_2))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
li = list(map(int,input().split()))
ans = 0
lgcd = [li[0]]
rgcd = [li[-1]]

for i in range(n-1):
    lgcd.append(np.gcd(lgcd[-1],li[i+1]))
    rgcd.insert(0,np.gcd(rgcd[0],li[-(i+2)]))

gcd_list = [lgcd[-2],rgcd[1]]

for i in range(n-2):
    gcd_list.append(np.gcd(lgcd[i],rgcd[i+2]))

print(max(gcd_list))

Submission status: Runtime Error

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
N = int(input())
a = list(map(int,input().split()))
if N==2:
    print(max(a))
else:
    gcd1 = gcd(a[0],a[1])
    gcd2 = gcd(a[0],a[2])
    gcd3 = gcd(a[1],a[2])
    flag1 = flag2 = flag3 = 0
    for i in range(N):
        if a[i]%gcd1 == 0:
            flag1 += 1
        if a[i]%gcd2 == 0:
            flag2 += 1
        if a[i]%gcd3 == 0:
            flag3 += 1
    ans = []
    if flag1 == N-1:
        ans.append(gcd1)
    if flag2 == N-1:
        ans.append(gcd2)
    if flag3 == N-1:
        ans.append(gcd3)
    print(max(ans))

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

odd_list = []
even_list = []

for i in range(N):
    
    if Num_list[i] % 2 == 0:
        even_list.append(Num_list[i])
        
    else:
        odd_list.append(Num_list[i])
        
even_max = max(even_list)
even_min = min(even_list)
odd_max = max(odd_list)
odd_min = min(odd_list)

if len(even_list) < 2:
    even_max = 1
    
elif len(odd_list) < 2:
    odd_max = 1

frac_1 = gcd(even_max,even_min)
frac_2 = gcd(odd_max, odd_min)
frac_3 = gcd(even_max, odd_min)
frac_4 = gcd(odd_max, even_min)

max_frac = max([frac_1, frac_2, frac_3, frac_4])

print(max_frac)

Submission status: Runtime Error

Solution code:
from math import gcd
from itertools import combinations
from functools import reduce


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


def main(input_1, input_2):
    nums_list = list(map(list, list(combinations(input_2, len(input_2)-1))))

    gcd_list = []
    for nums in nums_list:
        calced = calc_gcd(nums)
        gcd_list.append(calced)

    return max(gcd_list)


if __name__ == "__main__":
    input_1 = input()
    input_2 = list(map(int, input().split()))
    print(main(input_1, input_2))

Submission status: Runtime Error

Solution code:
def insu_split(x):
    result = []
    y = 2
    while x >= y:
        if x % y == 0:
            result.append(y)
            x = x // y
        else:
            y += 1
    return result

def extract_same_insu(insu_lists):
    same_insu = []
    for x in insu_lists[0]:
        if all([x in insu_list for insu_list in insu_lists]):
            same_insu.append(x)
    return same_insu

def diff_insu(insu_lists, same_insu):
    result = []
    for insu_list in insu_lists:
        for x in same_insu:
            insu_list.remove(x)
        result.append(insu_list)
    return result

def diff_majority(diffs):
    items = set([x for ls in diffs for x in ls])
    cands = []
    for x in items:
        c = len([0 for ls in diffs if x in ls])
        if c == len(diffs) - 1:
            cands.append(x)
    if len(cands) == 0:
        return 1
    else:
        return max(cands)
        
N = int(input())
A = list(map(int, input().split()))

insu_lists = [insu_split(t) for t in A]
#print(insu_lists)
same_insu = extract_same_insu(insu_lists)
#print(same_insu)
diffs = diff_insu(insu_lists, same_insu)
#print(diffs)
m = diff_majority(diffs)
#print(m)
for x in same_insu:
    m *= x
print(m)

Submission status: Runtime Error

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

from math import gcd

#L_i は、a_0~a_iまでの最大公約数
#R_i は、a_n~a_iまでの最大公約数
#M_i は、a_iを消した場合の最大公約数
L,R,M = [[0 for i in range(n)] for j in range(3)]
L[0] = a[0]
R[n-1] = a[n-1]
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])
M[0] = R[1]
M[n-1] = L[n-1]
for i in range(1,n-1):
    M[i] = gcd(L[i-1],R[i+1])
print(max(M))

Submission status: Runtime Error

Solution code:
import copy

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

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

if n>2:
    memo = list([])

    for k in range(n):
        t = copy.copy(s_all)
        t.pop(k)

        c = gcd(t[0], t[1])

        for i in s:
            c = gcd(c,i)

        memo.append(c)

    print(max(memo))

if n==2:
    print(max(s_all))

Submission status: Runtime Error

Solution code:
import math
import copy

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

if n>2:
    memo = list([])

    for k in range(n):
        t = copy.copy(s_all)
        t.pop(k)

        c = math.gcd(t[0], t[1])

        for i in s:
            c = math.gcd(c,i)

        memo.append(c)

    print(max(memo))

if n==2:
    print(max(s_all))

Submission status: Runtime Error

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

set_a = set(a)
set_a = list(set_a)
len_set_a = len(set_a)
set_a.append(0)
set_a.insert(0, 0)
cd = []
for i, ai in enumerate(set_a[1:len_set_a]):
    common_divisor = 0
    for li in set_a[:i]:
        common_divisor = fractions.gcd(common_divisor,li)
    for ri in set_a[i+1:]:
        common_divisor = fractions.gcd(common_divisor, ri)
    cd.append(common_divisor)
print(max(cd))

Submission status: Runtime Error

Solution code:
import math
n=int(input())
A=list(map(int,input().split()))
ans=1
ans1=A[0]
for i in range(n):
	for j in range(i):
		ans1=math.gcd(ans1,A[j])
	if i<n-1:
		ans2=A[i+1]
	else:
		ans2=A[i-1]
	for j in range(i+1,n):
		ans2=math.gcd(ans2,A[j])
	ans=max(ans,math.gcd(ans1,ans2))
print(ans)

Submission status: Runtime Error

Solution code:
import math
n=int(input())
A=list(map(int,input().split()))
ans=1
ans1=A[0]
for i in range(0,n-1):
	for j in range(i):
		ans1=math.gcd(ans1,A[j])
	if i<n-1:
		ans2=A[i+1]
	else:
		ans2=1
	for j in range(i+1,n):
		ans2=math.gcd(ans2,A[j])
	ans=max(ans,math.gcd(ans1,ans2))
print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

n   = int(input())
aaa = [int(s) for s in input().split()]
max_gcd = 0

for i in range(n):
    bbb = aaa[0:i]
    bbb.extend(aaa[i+1:])
    if max_gcd < gcd_list(bbb):
        max_gcd = gcd_list(bbb)

print(max_gcd)

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce

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

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

n   = int(input())
aaa = [int(s) for s in input().split()]
max_gcd = 0

for i in range(n):
    bbb = aaa[0:i]
    bbb.extend(aaa[i+1:])
    if max_gcd < gcd_list(bbb):
        max_gcd = gcd_list(bbb)

print(max_gcd)

Submission status: Runtime Error

Solution code:
from math import gcd
n,*a=map(int,open(0).read().split())
p=gcd(a[0],a[1])
l=[a[0],p]
c=list(reversed(a))
q=gcd(c[0],c[1])
r=[q]
for i in range(1,n-1):
    p=gcd(p,a[i+1])
    l.append(p)
    q=gcd(q,c[i+1])
    r.append(q)

r=r[::-1]+[a[-1]]
r=r[1:]+[0]
l=[0]+l

print(max(gcd(s,t)for s,t in zip(r,l)))

Submission status: Runtime Error

Solution code:
from math import gcd
n=int(input())
a=[int(i) for i in input().split()]
p=gcd(a[0],a[1])
l=[a[0],p]
c=list(reversed(a))
q=gcd(c[0],c[1])
r=[q]
for i in range(1,n-1):
    p=gcd(p,a[i+1])
    l.append(p)
    q=gcd(q,c[i+1])
    r.append(q)

r=r[::-1]+[a[-1]]
r=r[1:]+[0]
l=[0]+l

print(max(gcd(s,t)for s,t in zip(r,l)))

Submission status: Runtime Error

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

set_a = set(a)
set_a = list(set_a)
if len(a)==2:
    print(max(a))
else:
    if len(set_a)<=2:
        print(max(set_a))
    elif len(set_a)>=3:
        kou1 = fractions.gcd(set_a[0],set_a[1])
        kou2 = fractions.gcd(set_a[1],set_a[2])
        kou3 = fractions.gcd(set_a[0],set_a[2])
        set_kou = set([kou1,kou2,kou3])
        if len(set_kou)==3:
            print(max(kou1,kou2,kou3))
        elif len(set_kou)==2:
            l = list(set_kou)
            print(max(l[0]*l[1]))

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
ans = reduce(math.gcd,a)
if n<=2 or (min(a)==max(a)):
    print(max(a))
else:
    for i in range(n):
        _a = copy.copy(a)
        _a.pop(i)
        tmp = reduce(math.gcd,_a)
        if tmp > ans:
            print(tmp)
            break
        else:
            pass

Submission status: Runtime Error

Solution code:
import math
import copy
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
ans = reduce(math.gcd,a)
if n==2 or (min(a)==max(a)):
    print(max(a))
else:
    for i in range(n):
        _a = copy.copy(a)
        _a.pop(i)
        tmp = reduce(math.gcd,_a)
        if tmp > ans:
            print(tmp)
            break
        else:
            if i != n-1:
                pass
            else:
                print(ans)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
L_A = [0]*(N+1)
R_A = [0]*(N+1)
for i in range(N):
    L_A[1+i] = math.gcd(L_A[i], A[i])
for i in reversed(range(N)):
    R_A[i] = math.gcd(R_A[i+1], A[i])
print(max(math.gcd(L_A[i], R_A[i+1]) for i in range(N)))

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce

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

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

max_gcd = 0

for i in range(n):
    A = original_A[:]
    A.pop(i)
    gcd = gcd_list(A)
    if max_gcd < gcd:
        max_gcd = gcd

print(max_gcd)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

max_gcd = 0

for i in range(n):
    A = original_A[:]
    A.pop(i)
    gcd = gcd_list(A)
    if max_gcd < gcd:
        max_gcd = gcd

print(max_gcd)

Submission status: Runtime Error

Solution code:
from functools import *
from itertools import *

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

def gcd(a, b):
    a , b = (a, b) if a > b else (b, a)
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
        pass
    return b

Bs = sorted(As)
x = gcd(Bs[0], Bs[1])
y = gcd(Bs[1], Bs[2])
z = gcd(Bs[2], Bs[0])
w = max(x, y, z)
print(reduce(gcd, chain([w], islice(Bs, 3, None))))

Submission status: Runtime Error

Solution code:
for i in range(sorted(A)[1],1,-1):
	if(np.sum(A%i==0)>=N-1):
		print(i)
		exit()
print(1)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
N = int(input())
A = [int(i) for i in input().split()]
GCD = [gcd(*[e for s,e in enumerate(A) if s!=i]) for i in range(N)]
print(max(GCD))