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: Wrong Answer

Solution code:
from fractions import gcd
# ユークリッド互除法
#def gcd(n, m):
#    return n if m == 0 else gcd(m, n%m)

N = int(input())
a = list(map(int, input().split()))
r = [a[-1]]
l = [a[0]]
for i in range(1, N-1):
    r.append(gcd(l[i-1], a[i]))
    l.append(gcd(r[i-1], a[-1-i]))
ans = r[-1]    
for i in range(N-2):
    ans = max(ans, gcd(l[i], r[-2-i]))
ans = max(ans, l[-1])
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
# ユークリッド互除法
#def gcd(n, m):
#    return n if m == 0 else gcd(m, n%m)

N = int(input())
a = list(map(int, input().split()))
r = [a[-1]]
l = [a[0]]
for i in range(1, N-1):
    r.append(gcd(l[i-1], a[i]))
    l.append(gcd(r[i-1], a[-i-1]))
ans = r[-1]    
for i in range(N-2):
    ans = max(ans, gcd(l[i], r[-i-2]))
ans = max(ans, l[-1])
print(ans)

Submission status: Wrong Answer

Solution code:
# ユークリッド互除法
def gcd(n, m):
    return n if m == 0 else gcd(m, n%m)

N = int(input())
a = list(map(int, input().split()))
m = [0]*N
r = [a[-1]]
l = [a[0]]
for i in range(1, N-1):
    r.append(gcd(l[i-1], a[i]))
    l.append(gcd(r[i-1], a[-i-1]))
ans = r[-1]    
for i in range(N-2):
    ans = max(ans, gcd(l[i], r[-i-2]))
ans = max(ans, l[-1])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import fractions
from functools import reduce
from copy import copy
input = sys.stdin.readline

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

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

for i in range(n):
    if ans < gcd_list(a[:i]+a[i+1::]):
        ans = gcd_list(a[:i]+a[i+1::])
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import fractions
from functools import reduce
from copy import copy
input = sys.stdin.readline

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

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

for i in range(n):
    l = copy(a)
    l.pop(i)
    if ans < gcd_list(l):
        ans = gcd_list(l)
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()

from fractions import gcd

L = [0]*N  # L[i] = A[0]からA[i]までの最大公約数
R = [0]*N  # R[i] = A[i]からA[N-1]までの最大公約数

for i in range(N-1):
    if i == 0:
        L[i] = A[i]
        R[N-1-i] = A[N-1-i]
    else:
        L[i] = gcd(L[i-1],A[i])
        R[N-1-i] = gcd(R[N-i],A[N-1-i])

a = max(L[N-1],R[1])

if N == 2:
    print(a)
else:
    print(max(a,max(gcd(L[i],R[i+2]) for i in range(N-2))))

Submission status: Wrong Answer

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

import fractions
from functools import reduce

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

ans = 0
ans_before = 0

for i in range(N):
    ans_before = ans
    ans = max(gcd_list([a for j, a in enumerate(A) if j!=i]), ans)
    if ans_before != 0 and ans != ans_before:
        break
    
print(ans)

Submission status: Wrong Answer

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

import fractions
from functools import reduce

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

ans = 0

for i in range(N):
    if ans == 0:
        ans = gcd_list([a for j, a in enumerate(A) if j!=i])
        
    elif gcd_list([a for j, a in enumerate(A) if j!=i]) > ans:
        ans = gcd_list([a for j, a in enumerate(A) if j!=i])
        break
        
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

input = lambda: sys.stdin.readline().rstrip()
INF = 10 ** 9 + 7


def factorize_dict(n):
    b = 2
    fct = defaultdict(lambda: 0)
    while b ** 2 <= n:
        while n % b == 0:
            n //= b
            fct[b] += 1
        b += 1
    if n > 1:
        fct[n] += 1
    return fct


def solve():
    N = int(input())
    A = list(map(int, input().split()))
    fct = [defaultdict(lambda:0)] * N

    for i in range(N):
        fct[i] = factorize_dict(A[i])

    primes = set()
    for i in range(N):
        for k, v in fct[i].items():
            primes |= set([k])

    primes = list(primes)

    gcd = [1] * len(primes)
    pmax_list = [1] * len(primes)
    for i, p in enumerate(primes):
        pmin = INF
        pcount = [0 for _ in range(30)]
        for j in range(N):
            pmin = min(pmin, fct[j][p])
            pcount[fct[j][p]] += 1
        gcd[i] = p ** pmin

        for k in range(29, 0, -1):
            pcount[k - 1] += pcount[k]

        for k in range(29, -1, -1):
            if pcount[k] == N - 1:
                pmax_list[i] = p ** k
                break

    mulmax = 1
    ind = -1
    for i in range(len(primes)):
        if mulmax < pmax_list[i] / gcd[i]:
            mulmax = pmax_list[i] / gcd[i]
            ind = i

    ans = 1
    for i in range(len(primes)):
        if i == ind:
            ans *= pmax_list[i]
        else:
            ans *= gcd[i]

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

def gcd_list(numbers):
  if numbers != []:
    return reduce(fractions.gcd, numbers)
  else:
    return 0

if __name__ == '__main__':
  n = int(input())
  a_lst = [int(elem) for elem in input().split()] 
  left_gcd = [0] * n
  right_gcd = [0] * n
  ans = 0
  for i in range(0,n):
    left_gcd[i] = gcd_list(a_lst[:i])
    right_gcd[i] = gcd_list(a_lst[i+1:])
  print(left_gcd, right_gcd)
  for i in range(n):
    ans = max(ans, fractions.gcd(left_gcd[i],right_gcd[i]))
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
"""
あるn以外の最大公約数が, 最大になる組み合わせ
7 6 8 -> gcd(7,6)=1, gcd(6,8)=2 gcd(7,8)=1
12 15 18 -> gcd(12,15)=3, gcd(15,18)=3, gcd(12, 18)=6
1 2 4 6 -> 2,4,6のやつがでかい
"""
l = [0 for _ in range(n)]
tmp = 0
for i in range(n):
	tmp = gcd(tmp, a[i])
	l[i] = tmp
r = [0 for _ in range(n)]
a = a[::-1]
tmp = 0
for i in range(n):
	tmp = gcd(tmp, a[i])
	r[i] = tmp

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)[::-1]
"""
あるn以外の最大公約数が, 最大になる組み合わせ
7 6 8 -> gcd(7,6)=1, gcd(6,8)=2 gcd(7,8)=1
12 15 18 -> gcd(12,15)=3, gcd(15,18)=3, gcd(12, 18)=6
1 2 4 6 -> 2,4,6のやつがでかい
"""
if n == 2:
	print(a[0])
	exit()
ans = 0
for i in range(n):
	tmp = 0
	for j in range(n):
		if j != i:
			tmp = gcd(tmp, a[j])
		if tmp <= ans:
			break
	ans = max(tmp, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from fractions import gcd
    input=sys.stdin.readline
    n=int(input())
    a=tuple(map(int,input().split()))
    ide_ele=0
    num=2**(n-1).bit_length()
    seg=[ide_ele]*2*num
    def init(init_val):
        for i in range(n):
            seg[i+num-1]=init_val[i]
        for i in range(num-2,-1,-1):
            seg[i]=gcd(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]=gcd(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=gcd(res,seg[p])
            if q&1==1:
                res=gcd(res,seg[q])
                q-=1
            p=p//2
            q=(q-1)//2
        if p==q:
            res=gcd(res,seg[p])
        else:
            res=gcd(gcd(res,seg[p]),seg[q])       
        return res

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd

# segfunc: 問題に応じて設定
def segfunc(x, y):
    return min(x, y)


# 配列aで初期化
def init(a):
    for i in range(n):
        seg[i+num-1] = a[i]    
    for i in range(num-2, -1, -1) :
        seg[i] = segfunc(seg[2*i+1], seg[2*i+2]) 


# a[k]の値をxに更新
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])


# [p, q)についてsegfuncを適用したものを返す
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 = list(map(int, input().split()))

ide_ele = 0
num = 2 ** (len(bin(n - 1)) - 2)
seg = [ide_ele] * 2 * num
init(a)

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

print(res)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

# segfunc: 問題に応じて設定
def segfunc(x, y):
    return min(x, y)


# 配列aで初期化
def init(a):
    for i in range(n):
        seg[i+num-1] = a[i]    
    for i in range(num-2, -1, -1) :
        seg[i] = segfunc(seg[2*i+1], seg[2*i+2]) 


# a[k]の値をxに更新
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])


# [p, q)についてsegfuncを適用したものを返す
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(res, segfunc(seg[p], seg[q]))
    
    return res


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

ide_ele = 0
num = 2 ** (len(bin(n - 1)) - 2)
seg = [ide_ele] * 2 * num
init(a)

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

print(res)

Submission status: Wrong Answer

Solution code:
#前からと後ろ側から最大公約数を求めていけば途中で抜くべき値がある。2つ直すことはできないのでどちらかは最大になる。
#0と何かの数字xの最大公約数はx

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

Submission status: Wrong Answer

Solution code:
#前からと後ろ側から最大公約数を求めていけば途中で抜くべき値がある。2つ直すことはできないのでどちらかは最大になる。
#0と何かの数字xの最大公約数はx

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

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
n=int(input())
s=list(map(int,input().split()))

if n==2:
  print(max(s))
  exit()
ma=1
for i in range(len(s)-1):
  t=s[i]
  s[i]=s[i+1]
  c=reduce(gcd,s)
  ma=max(ma,c)
  s[i]=t

print(ma)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
n=int(input())
s=list(map(int,input().split()))

if n==2:
  print(max(s))
  exit()
ma=1
for i in range(len(s)-1):
  t=s[i]
  s[i]=s[i+1]
  c=reduce(gcd,s)
  ma=max(ma,c)
  s[i]=t
else:
  t=s[i]
  s[i]=s[i-1]
  c=reduce(gcd,s)
  ma=max(ma,c)
  s[i]=t
print(ma)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
n=int(input())
s=list(map(int,input().split()))
b = reduce(gcd, s)

if len(s)==2:
  print(max(s))
  exit()

ma=1
for i in range(len(s)-1):
  t=s[i]
  s[i]=s[i+1]
  c=reduce(gcd,s)
  ma=max(ma,c)
  s[i]=t
else:
  t=s[i]
  s[i]=s[i-1]
  c=reduce(gcd,s)
  ma=max(ma,c)
  s[i]=t
print(ma)

Submission status: Wrong Answer

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

'''
'init(a)': 配列aで初期化。O(N)
'update(k,x)': a[k]をxに変更 O(logN)
'query(p,q)': [p,q)について "segfunc" したものを返す O(logN)
'ide_ele' : 単位元。
'''


def segfunc(x, y):
    return fractions.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


#####単位元######
ide_ele = A[-1]

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

init(A)

# print(query(0, 2))

ans = 1
for i in range(N):
    if i == 0:
        ans = max(ans, query(1, N))
    elif i == N-1:
        ans = max(ans, query(0, N-1))
    else:
        ans = max(ans, fractions.gcd(query(0, i), query(i+1, N)))
print(ans)

Submission status: Wrong Answer

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

'''
'init(a)': 配列aで初期化。O(N)
'update(k,x)': a[k]をxに変更 O(logN)
'query(p,q)': [p,q)について "segfunc" したものを返す O(logN)
'ide_ele' : 単位元。
'''


def segfunc(x, y):
    return fractions.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


#####単位元######
ide_ele = A[-1]

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

init(A)

# print(query(0, 2))

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

Submission status: Wrong Answer

Solution code:
# ABC125C

from fractions import gcd
from functools import reduce

n = int(input())
a = list(set(map(int, input().split())))
n = len(a)
if n == 1:
    print(a[0])
elif n == 2:
    print(max(a[0], a[1]))
else:
    max_value = 0
    for i in range(n):
        memo = a.pop(0)
        x = reduce(gcd, a)
        if x > max_value:
            max_value = x
        a.append(memo)
    print(max_value)

Submission status: Wrong Answer

Solution code:
# ABC125C

from fractions import gcd
from functools import reduce

n = int(input())
a = list(set(map(int, input().split())))
print(a)
n = len(a)
if n == 1:
    print(a[0])
elif n == 2:
    print(max(a[0], a[1]))
else:
    max_value = 0
    for i in range(n):
        memo = a.pop(0)
        x = reduce(gcd, a)
        if x > max_value:
            max_value = x
        a.append(memo)
    print(max_value)

Submission status: Wrong Answer

Solution code:
# ABC125C

from fractions import gcd
from functools import reduce

n = int(input())
a = list(set(map(int, input().split())))
n = len(a)
if n == 1:
    print(a[0])
elif n == 2:
    print(gcd(a[0], a[1]))
else:
    max_value = 0
    for i in range(n):
        memo = a.pop(0)
        x = reduce(gcd, a)
        if x > max_value:
            max_value = x
        a.append(memo)
    print(max_value)

Submission status: Wrong Answer

Solution code:
# ABC125C

from fractions import gcd
from functools import reduce

n = int(input())
a = list(set(map(int, input().split())))
n = len(a)
if n == 1:
    print(a[0])
elif n == 2:
    print(reduce(gcd, a))
else:
    max_value = 0
    for i in range(n):
        memo = a.pop(0)
        x = reduce(gcd, a)
        if x > max_value:
            max_value = x
        a.append(memo)
    print(max_value)

Submission status: Wrong Answer

Solution code:
# ABC125C

from fractions import gcd
from functools import reduce

n = int(input())
a = list(set(map(int, input().split())))
n = len(a)
if n == 1:
    print(a[0])
else:
    max_value = 0
    for i in range(n):
        memo = a.pop(0)
        x = reduce(gcd, a)
        if x > max_value:
            max_value = x
        a.append(memo)
    print(max_value)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from heapq import heapify, heappop, heappush
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

# ここから書き始める
n = int(input())
a = list(map(int, input().split()))

# 愚直解(TLE)
ans_stupid = 0
for i in range(n):
    ans_stupid = (ans_stupid, gcd_list(a[:i] + a[i + 1:]))
print(ans_stupid)

left = [0 for i in range(n)]
right = [0 for i in range(n)]
ans = 0
for i in range(n):
    if i == 0:
        left[i] = a[i]
    else:
        left[i] = gcd(left[i - 1], a[i])
for i in reversed(range(n)):
    if i == n - 1:
        right[i] = a[i]
    else:
        right[i] = gcd(right[i + 1], a[i])
# print("left =", left)
# print("right =", right)
for i in range(n):
    if i == 0:
        ans = max(ans, right[i + 1])
    elif i == n - 1:
        ans = max(ans, left[i - 1])
    else:
        ans = max(ans, gcd(left[i - 1], right[i + 1]))
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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

gcd_left = [gcd_right[-1]] + gcd_left
gcd_right = gcd_right + [gcd_left[0]]
ans = 1
for i in range(N):
    ans = max(ans, gcd(gcd_left[i], gcd_right[i + 1]))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd

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

L = [0] * N  # 左からi番目までのgcdをメモった配列
R = [0] * N  # 右からi番目までのgcdをメモった配列
L[0] = A[0]
R[0] = A[N - 1]
for i in range(1, N):
    L[i] = gcd(L[i - 1], A[i])
    R[i] = gcd(R[i - 1], A[N - 1 - i])

ans = 0
for i in range(N):
    ans = max(ans, gcd(L[i], R[N - i - 3]))
ans = max(ans, R[N - 2])
print(ans)

Submission status: Wrong Answer

Solution code:
# 最大公約数(mathは3.5以降) 
from functools import reduce
import fractions #(2020-0405  fractions→math)
def lcm_base(x, y):
    return  fractions.gcd(x, y) # 「//」はフロートにせずにintにする
def lcm_list(numbers):
    return reduce(lcm_base, numbers)
def lcm_fukusu(*numbers):
    return reduce(lcm_base, numbers)

# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A_np =np.array(A)

#Aの隣り合う要素の最大公約数
ans =[]
if N==2:
    ans =max(A)
    print(ans)
    exit()
else:
    for i in range(N-1):
        ans.append(lcm_fukusu(A[i],A[i+1]))
    ans.append(lcm_fukusu(A[0],A[-1])) #len(A) ==3の時必要
    ans =list(set(ans))
    ans.sort()
if len(ans) !=1:
    print(ans[1])
elif len(ans) ==1:
    print(ans[0])

Submission status: Wrong Answer

Solution code:
import sys
N=int(input())
A=list(map(int,input().split()))
A.sort()
MIN=min(A[1],10**5)
for i in range(MIN,0,-1):
  miss=0
  for k in range(N):
    if A[k]%i != 0:
      miss+=1
      if miss==2:
        break
    if k==N-1:
      ans=i
      print(ans)
      sys.exit()

Submission status: Wrong Answer

Solution code:
import sys
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

def gcd_list(ln):
    if len(ln) == 1:
        return ln[0]
    tmp = gcd(ln[0], ln[1])
    for x in ln[2:]:
        tmp = gcd(tmp, x)
    return tmp

n = int(input())
a = list(map(int, sys.stdin.readline().split()))
ans = 0
for i in range(min(n, 4)):
    tmp = gcd_list(a[:i] + a[i+1:])
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

def gcd_list(ln):
    tmp = gcd(ln[0], ln[1])
    for x in ln[2:]:
        tmp = gcd(tmp, x)
    return tmp

n = int(input())
a = list(map(int, sys.stdin.readline().split()))
if n == 2:
    print(max(a))
else:
    ans = 0
    for i in range(min(n, 4)):
        tmp = gcd_list(a[:i] + a[i+1:])
        if tmp > ans:
            ans = tmp
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

def gcd_list(ln):
    tmp = gcd(ln[0], ln[1])
    for x in ln[2:]:
        tmp = gcd(tmp, x)
    return tmp
    
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
if n == 2:
    print(max(a))
else:
    c = [gcd_list(a[:i] + a[i+1:]) for i in range(min(n, 4))]
    c.sort()
    print(c[-1])

Submission status: Wrong Answer

Solution code:
import sys
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

def gcd_list(ln):
    tmp = gcd(ln[0], ln[1])
    for x in ln[2:]:
        tmp = gcd(tmp, x)
    return tmp
    
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
if n == 2:
    print(max(a))
else:
    c = [gcd_list(a[:i] + a[i+1:]) for i in range(min(n, 4))]
    c.sort()
    print(c[2])

Submission status: Wrong Answer

Solution code:
import sys
from functools import reduce
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n
def gcd_list(numbers):
    return reduce(gcd, numbers)

n = int(input())
a = list(map(int, sys.stdin.readline().split()))
c = [gcd_list(a[:i] + a[i+1:]) for i in range(min(n, 20))]
c.sort()
if n == 2:
    print(c[1])
else:
    print(c[2])

Submission status: Wrong Answer

Solution code:
import sys
from functools import reduce
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n
def gcd_list(numbers):
    return reduce(gcd, numbers)

n = int(input())
a = list(map(int, sys.stdin.readline().split()))
c = [gcd_list(a[:i] + a[i+1:]) for i in range(min(n, 5))]
c.sort()
if n == 2:
    print(c[1])
else:
    print(c[2])

Submission status: Wrong Answer

Solution code:
import sys
from functools import reduce
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n
def gcd_list(numbers):
    return reduce(gcd, numbers)

n = int(input())
a = list(map(int, sys.stdin.readline().split()))
c = [gcd_list(a[:i] + a[i+1:]) for i in range(n)]
c.sort()
if n == 2:
    print(c[1])
else:
    print(c[2])

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
max_num = [[reduce(gcd, [A[i], A[j]]) for j in range(i, len(A))] for i in range(len(A))]
max_num = [max(i[1:]) for i in max_num if len(i[1:]) > 0 ]
print(max(max_num))

Submission status: Wrong Answer

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

n = int(input())
aaa = list(map(int, input().split()))
cnt_l = [0] * (n - 1)
cnt_r = [0] * (n - 1)

cnt_l[0] = aaa[0]
for i in range(1, n - 1):
    cnt_l[i] = gcd(cnt_l[i - 1], aaa[i])

aaa.reverse()
cnt_r[0] = aaa[0]
for i in range(1, n - 1):
    cnt_r[i] = gcd(cnt_r[i - 1], aaa[i])

cnt_l = [cnt_r[-1]] + cnt_l
cnt_r = [cnt_l[-1]] + cnt_r
cnt_r.reverse()

ans = 1
for i in range(n - 1):
    tmp = gcd(cnt_l[i], cnt_r[i])
    ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

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

n = int(input())
aaa = list(map(int, input().split()))
cnt_l = [0] * (n - 1)
cnt_r = [0] * (n - 1)

cnt_l[0] = aaa[0]
for i in range(1, n - 1):
    cnt_l[i] = gcd(cnt_l[i - 1], aaa[i])

aaa.reverse()
cnt_r[0] = aaa[0]
for i in range(1, n - 1):
    cnt_r[i] = gcd(cnt_r[i - 1], aaa[i])

cnt_l = [cnt_r[-1]] + cnt_l
cnt_r = [cnt_l[-1]] + cnt_r
cnt_r.reverse()

ans = 0
for i in range(n - 1):
    tmp = gcd(cnt_l[i], cnt_r[i])
    ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
# 判定機にmathがインストールされていないため、
# gcd=最小公倍数、lcm=最少公約数(返り値整数)を実装
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    z = None
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        return z


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

# check
A.sort(reverse=True)
max_gcd = A[0]
change = False
for a in A:
    ans = gcd(max_gcd, a)
    if ans < max_gcd and change is False:
        change = True
        continue
    max_gcd = ans

print(max_gcd)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
min_2=num[1]
if num[0]!=num[1]:
    if any([x%num[1]!=0 for x in data[1::]])==True:
        min_2=int(num[1]/2)+1
else:
    count=0
    for i in data[2::]:
        if i%num[1]!=1:
            count+=1
    if 1<count:
        min_2=int(num[1]/2)+1
for i in range(min_2+1)[::-1]:
    is_i=0
    if all([x%i==0 for x in data]):
        print(i)
        break
    else:
        for j in range(len(data)):
            if data[j]%i!=0:
                is_i+=1
        if is_i==1:
            print(i)
            break

Submission status: Wrong Answer

Solution code:
import numpy as np
n=input()
data=list(map(int,input().split()))
is_i=0
num=sorted(data)
count=num[1]
if num[0]!=num[1]:
    if any([x%num[1]!=0 for x in data[1::]])==True:
        count=int(num[1]/2)+1
elif any([x%num[1]!=0 for x in data[1::]])==True:
    count=int(num[1]/2)+1
for i in range(count+1)[::-1]:
    is_i=0
    if all([x%i==0 for x in data]):
        print(i)
        break
    else:
        for j in range(len(data)):
            if data[j]%i!=0:
                is_i+=1
        if is_i==1:
            print(i)
            break