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:
def gcd(a,b):
    if b>a:
        a,b=b,a
    while b:
        a,b=b, a%b
    return a


def cul(n,a):
    l=len(a)
    b=[a[i] for i in range(l)]
    b.pop(n)
    tmp=b[0]
    for i in range(1,l-1):
        tmp=gcd(tmp,b[i])
    return tmp

import sys
import math
p=10
N=int(input())
a=list(map(int,input().split()))
if N<=p:
    ans=0
    
    for i in range(N):
        tmp=cul(i,a)        
        if tmp>ans: ans=tmp
    print(ans)
    sys.exit()
        
M=a[0]
for i in range(1,p):
    M=gcd(M,a[i])

ans=0
for i in range(1,math.ceil(M**0.5)+1 ):
    if M%i==0:
        cnt=0
        for j in range(p,N):
            if a[i]%i!=0:
                cnt+=1
                if cnt==2: break
            elif i==N-1 and i>ans: ans=i
        
        x=M//i
        cnt=0
        for j in range(p,N):
            if a[i]%x!=0:
                cnt+=1
                if cnt==2: break
            elif i==N-1 and x>ans: ans=i

r=a[N-1]
for i in range(N-1,p-1,-1):
    r=gcd(r,a[i])
if r>ans:
    for i in range(p):
        s=gcd(cul(i,a[:p]),r)
        if s>ans: ans=s

print(ans)

Submission status: Wrong Answer

Solution code:
# Contest Try #3 (math -> fractions)

from sys import stdin
from fractions import gcd



rs = lambda: stdin.readline().strip()
ri = lambda: int(rs())
rsl = lambda: stdin.readline().split()
rim = lambda: map(int, rsl())
ril = lambda: list(rim())


def lcm(a, b):
    return (a * b) / gcd(a, b)


def findGCD(lst):
    ret = 1
    for i in range(len(lst)-1):
        ret = max(ret, gcd(lst[i], lst[i+1]))
    return ret


def findLCM(lst):
    ret = max(lst)
    for i in range(len(lst)-1):
        ret = min(ret, lcm(lst[i], lst[i+1]))
        print(lcm(lst[i], lst[i+1]))
    return ret


N = ri()
integers = list(rim())
gc = findGCD(integers)
cnt = 0
for num in integers:
    if num % (gc*2) != 0:
        cnt += 1

if cnt > 1:
    print(gc)
else:
    print(gc*2)

Submission status: Wrong Answer

Solution code:
# Contest Try #2 with library change: math -> fractions

from sys import stdin
from fractions import gcd


rs = lambda: stdin.readline().strip()
ri = lambda: int(rs())
rsl = lambda: stdin.readline().split()
rim = lambda: map(int, rsl())
ril = lambda: list(rim())


N = ri()
integers = list(rim())

lowest = [float('-inf'), float('-inf')]
for i in range(len(integers)-1):
    for j in range(i+1, len(integers)):
        temp = gcd(integers[i], integers[j])
        if temp > min(lowest):
            lowest[lowest.index(min(lowest))] = temp

print(max(lowest))

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque, defaultdict as ddic
from itertools import combinations, permutations, product
import bisect
import heapq
from fractions import gcd
from operator import mul
import re


rs = lambda: stdin.readline().strip()
ri = lambda: int(rs())
rsl = lambda: stdin.readline().split()
rim = lambda: map(int, rsl())
ril = lambda: list(rim())


def findGCD(lst):
    ret = 1
    for i in range(len(lst)-1):
        ret = max(ret, gcd(lst[i], lst[i+1]))
    return ret


def findGCD2(lst, k):
    ret = 1
    for i in range(len(lst)-1):
        if i == k:
            continue
        ret = max(ret, gcd(lst[i], lst[i+1]))
    return ret



N = ri()
integers = list(rim())

lowest = [float('-inf'), float('-inf')]
for i in range(len(integers)-1):
    for j in range(i+1, len(integers)):
        temp = gcd(integers[i], integers[j])
        if temp > min(lowest):
            lowest[lowest.index(min(lowest))] = temp

print(max(lowest))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
B, C = [A[0]], [A[N - 1]]

for i in range(1, N):
    B.append(gcd(B[i - 1], A[i]))

AA = list(reversed(A))
for i in range(1, N):
    C.append(gcd(C[i - 1], AA[i]))
C.reverse()
# print(B, C)
ans = 0
for i in range(1, N - 1):
    ans = max(ans, gcd(B[i - 1], C[i + 1]))
ans = max(ans, B[N - 1], C[1])
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
B, C = [A[0]], [A[N - 1]]

for i in range(1, N):
    B.append(gcd(B[i - 1], A[i]))

AA = list(reversed(A))
for i in range(1, N):
    C.append(gcd(C[i - 1], AA[i]))
C.reverse()
ans = 0
for i in range(N):
    if i == 0:
        ans = max(ans, C[1])
    elif i == N - 1:
        ans = max(ans, B[N - 1])
    else:
        ans = max(ans, gcd(B[i - 1], C[i + 1]))
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
#import math
from functools import reduce

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

#累積GCD
left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
    #left.append(math.gcd(left[i],a[i]))
    left[i + 1] = (fractions.gcd(left[i],a[i]))
    #right.insert(0,math.gcd(right[0],a[n - 1 - i]))
    right[n - i - 1] = (fractions.gcd(right[n - i],a[n - 1 - i]))
#print(left)
#print(right)

ans = 0
for i in range(n - 1):
    ans = max(ans,fractions.gcd(left[i],right[i + 1]))
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

#累積GCD
left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
  #left.append(math.gcd(left[i],a[i]))
  left[i + 1] = (fractions.gcd(left[i],a[i]))
  #right.insert(0,math.gcd(right[0],a[n - 1 - i]))
  right[n - i - 1] = (fractions.gcd(right[n - i],a[n - 1 - i]))

  ans = 0
  for i in range(n - 1):
    ans = max(ans,fractions.gcd(left[i],right[i + 1]))
    print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from itertools import accumulate

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

# 先頭から連続する要素の最大公約数の列
L = list(accumulate([0] + A, gcd))
# 末尾から連続する要素の最大公約数
R = list(accumulate([0] + list(reversed(A)), gcd))

# Aの各要素について、それを使用しない場合の最大公約数の最大値をL, Rを用いて求める
ans = max(
    gcd(L[k], R[-(k + 2)])
    for k in range(N - 1)
)

# 出力
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    def gcd(a,b):
        if b == 0:
            return a
        else:
            return gcd(b,a%b)
    def query(p,q):
        if q<1 or p>n-1:
            return 0
        if q-p<=1:
            return a[p]
        p += num-1
        q += num-2
        res=0
        while p<q:
            if p&1 == 0:
                res = gcd(res,data[p])
            if q&1 == 1:
                res = gcd(res,data[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        return res

    n = int(input())
    a = tuple(map(int,input().split()))
    #num:n以上の最小の2のべき乗
    num =2**(n-1).bit_length()
    data=[0]*2*num

    for i in range(n):
        data[i+num-1]=a[i]    
    for i in range(num-2,-1,-1) :
        data[i]=gcd(data[2*i+1],data[2*i+2]) 

    ans = -1
    for i in range(n):
        ans = max(ans,gcd(query(0,i),query(i+1,n)))
    print(ans)
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    def gcd(a,b):
        if b == 0:
            return a
        else:
            return gcd(b,a%b)
    def query(p,q):
        if p>=n:
            return 0
        if q-p<=1:
            return a[p]
        p += num-1
        q += num-2
        res=0
        while p<q:
            if p&1 == 0:
                res = gcd(res,data[p])
            if q&1 == 1:
                res = gcd(res,data[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        return res

    n = int(input())
    a = tuple(map(int,input().split()))
    #num:n以上の最小の2のべき乗
    num =2**(n-1).bit_length()
    data=[0]*2*num

    for i in range(n):
        data[i+num-1]=a[i]    
    for i in range(num-2,-1,-1) :
        data[i]=gcd(data[2*i+1],data[2*i+2]) 

    ans = -1
    for i in range(n):
        ans = max(ans,gcd(query(0,i),query(i+1,n)))
    print(ans)
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import copy
from functools import reduce

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

Submission status: Wrong Answer

Solution code:
N=int(input())
li=list(map(int,input().split()))
lis=li
maxi=li

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

for x in range(N):
    e=gcd(max(li),max(li))
    lis=li
    for i in range(N):
        if x==i:
            continue
        else:
            e=gcd(e,lis[i])
    maxi[x]=e

maxer=max(maxi)
print(maxer)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

#累積GCD
left = [0]
right = [0]
for i in range(n):
    left.append(fractions.gcd(left[i],a[i]))
    right.insert(0,fractions.gcd(right[0],a[n - 1 - i]))

ans = 0
for i in range(n - 1):
    ans = max(ans,fractions.gcd(left[i],right[i + 1]))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
 
def gcd(a,b):
  if b==0:
    return a
  else:
  	return gcd(b, a%b)

def gcd_list(X):
  dmy=gcd(X[0],X[1])
  for i in range(len(X)):
    dmy=gcd(dmy,X[i])
  return dmy
 
if N==2:
  print(max(A))
if N==3:
  B=[0]*3
  B[0]=gcd(A[0],A[1])
  B[1]=gcd(A[1],A[2])
  B[2]=gcd(A[2],A[0])
  print(max(B))
else:
  Res=[0]*N
  for i in range(N):
    if len(A[:i])>1:
      L=gcd_list(A[:i])
    else:
      L=0
    if len(A[i+1:])>1:
      R=gcd_list(A[i+1:])
    else:
      R=0
    Res[i]=gcd(L,R)
 
  print(int(max(Res)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
 
def gcd(a,b):
  if b==0:
    return a
  else:
  	return gcd(b, a%b)

def gcd_list(X):
  dmy=gcd(X[0],X[1])
  for i in range(len(X)):
    dmy=gcd(dmy,X[i])
  return dmy
 
if N==2:
  print(max(A))
if N==3:
  B=[0]*3
  B[0]=gcd(A[0],A[1])
  B[1]=gcd(A[1],A[2])
  B[2]=gcd(A[2],A[0])
  print(max(B))
else:
  Res=[0]*N
  for i in range(N):
    if len(A[:i])>1:
      L=gcd_list(A[:i])
    else:
      L=0
    if len(A[i+1:])>1:
      R=gcd_list(A[i+1:])
    else:
      R=0
    print('i='+str(i)+' L='+str(L))
    print('i='+str(i)+' R='+str(R))
    Res[i]=gcd(L,R)
 
  print(int(max(Res)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
 
def gcd(a,b):
  if b==0:
    return a
  else:
  	return gcd(b, a%b)

def gcd_list(X):
  dmy=gcd(X[0],X[1])
  dmy=X[0]*X[1]
  for i in range(len(X)):
    dmy=gcd(dmy,X[i])
  return dmy
 
if N==2:
  print(max(A))
if N==3:
  B=[0]*3
  B[0]=gcd(A[0],A[1])
  B[1]=gcd(A[1],A[2])
  B[2]=gcd(A[2],A[0])
  print(max(B))
else:
  Res=[]
  for i in range(N):
    if len(A[:i])>1:
      L=gcd_list(A[:i])
    else:
      L=0
    if len(A[i+1:])>1:
      R=gcd_list(A[i+1:])
    else:
      R=0
    print('i='+str(i)+' L='+str(L))
    print('i='+str(i)+' R='+str(R))
    Res.append(gcd(L,R))
 
  print(int(max(Res)))

Submission status: Wrong Answer

Solution code:
#WA

def gcd(a,b):
    if b == 0:
        return a
    if a % b == 0:
        return b
    else:
        return gcd(b,a%b)
    
    
n = int(input())
a = list(map(int,input().split()))

R = [0]
L = [0]
ans = 0

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

L.reverse()
for i in range(1,len(R)+1):
    ans = max(ans,gcd(R[i-1],L[-i]))

ans = max(ans,R[-1],L[0])

print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if b == 0:
        return a
    if a % b == 0:
        return b
    else:
        return gcd(b,a%b)
    
    
n = int(input())
a = list(map(int,input().split()))

R = [0]
L = [0]
ans = 0

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

L.reverse()
for i in range(1,len(R)):
    ans = max(ans,gcd(R[i-1],L[-i]))

ans = max(ans,R[-1],L[0])

print(ans)

Submission status: Wrong Answer

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

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


def main():
    n = int(input())
    A = list(map(int, input().split()))
    gcdA = [0]*n
    gcdB = [0]*n
    gcdA[0] = A[0]
    gcdB[n-1] = A[n-1]
    for i in range(1, n):
        gcdA[i] = gcd(A[i], gcdA[i-1])
        gcdB[n-i-1] = gcd(A[n-i-1], gcdB[n-1])
    ans = max(gcdA[n-2], gcdB[1])
    for i in range(1, n-1):
        ans = max(ans, gcd(gcdA[i-1], gcdB[i+1]))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


def main():
    n = int(input())
    A = list(map(int, input().split()))
    gcdA = [0]*n
    gcdB = [0]*n
    gcdA[0] = A[0]
    gcdB[0] = A[n-1]
    for i in range(1, n):
        gcdA[i] = gcd(A[i], gcdA[i-1])
        gcdB[n-i-1] = gcd(A[n-i-1], gcdB[n-1])
    ans = max(gcdA[n-2], gcdB[1])
    for i in range(1, n-1):
        ans = max(ans, gcd(gcdA[i-1], gcdB[i+1]))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
from itertools import combinations

def gcd(x):
  gcds = x[0]
  for i in range(1, len(x)):
    gcds = math.gcd(gcds, x[i])
  return gcds

def main():
  N = int(input().strip())
  A = list(map(int, input().strip().split()))
  
  gcds = []
  for i in range(N):
    gcds.append(A[:i] + A[i+1:])
  
  print(max(gcds))
 
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
x = 0
for i in range(n-1):
    keep = a[0]
    a.pop(0)
    num = reduce(fractions.gcd, a)
    if num > x:
        x = num
    a.append(keep)
print(x)

Submission status: Wrong Answer

Solution code:
import fractions

n = int(input())
a = list(map(int, input().split()))
x = 0
for i in range(n-1):
    keep = a[0]
    a.pop(0)
    for j in range(n-2):
        num = fractions.gcd(a[j], a[j+1])
        if num > x:
            x = num
    a.append(keep)
print(x)

Submission status: Wrong Answer

Solution code:
import sys
# import bisect
# import math
# import itertools
# import numpy as np
# import collections
import fractions as fr

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

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


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e, p = range, enumerate, print
    ip = IP()
    id = Idea()
    mod = 10 ** 9 + 7

    """この下から書いてね"""
    n = ip.I()
    a = ip.IL()
    left = right = [0, 0]
    for x in a:
        left.append(fr.gcd(left[-1], x))

    for x in a[::-1]:
        right.append(fr.gcd(right[-1], x))

    p(max(fr.gcd(l, r)for l, r in zip(left, reversed(right))))


main()

Submission status: Wrong Answer

Solution code:
import sys
# import bisect
# import math
# import itertools
# import numpy as np
# import collections
import fractions as fr

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

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


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e, p = range, enumerate, print
    ip = IP()
    id = Idea()
    mod = 10 ** 9 + 7

    """この下から書いてね"""
    n = ip.I()
    a = ip.IL()
    left = right = [0, 0]
    for x in a:
        left.append(fr.gcd(left[-1], x))

    for x in a[::-1]:
        right.append(fr.gcd(right[-1], x))

    p(max(fr.gcd(l, r)for l, r in zip(left, right[::-1])))


main()

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd

N = int(input())

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


if len(A) < 3:
    print(max(A))
    sys.exit()


left_side = [0 for _ in range(N)]
left_side[0] = A[0]

right_side = [0 for _ in range(N)]
right_side[-1] = A[-1]



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

for i in range(1, N):
    right_side[-1* (i + 1)] = gcd(right_side[-1* i], A[ -1 *(i + 1)])


max_gcd = 1 
for i in range(1, N -1 ):
    left = left_side[i - 1]
    right = right_side[i + 1]
    max_gcd = max(max_gcd, gcd(left, right))




print(max_gcd)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())

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


if len(A) < 3:
    print(max(A))
    sys.exit()


left_side = [0 for _ in range(N)]
left_side[0] = A[0]

right_side = [0 for _ in range(N)]
right_side[-1] = A[-1]


def gcd(x, y):
    if x == y:
        return x

    min_num = min(x, y)
    max_num = max(x, y)
    dif = max_num % min_num
    if dif == 0:
        return min_num
    return gcd(min_num, dif)


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

for i in range(1, N):
    right_side[-1* (i + 1)] = gcd(right_side[-1* i], A[ -1 *(i + 1)])


max_gcd = 1 
for i in range(1, N -1 ):
    left = left_side[i - 1]
    right = right_side[i + 1]
    max_gcd = max(max_gcd, gcd(left, right))




print(max_gcd)

Submission status: Wrong Answer

Solution code:
N = int(input())
rawA = list(map(int, input().split()))
A = [rawA[0],] + rawA + [rawA[N-1],]
#要素数A+2。A[0]とA[N+1]はcumsum計算用

def gcd(a, b):
  if b > a: a,b = b,a
  #これでa >= bになったので、互除法適用可
  if a % b == 0: return b
  else: return gcd(b, a % b)
  
#cfl: cumsum from left
#[0]~[N-1] 
#A[0]は計算不要（gcdでなくgd(A0)でいいから）
cfl = []
for i in range(1, N):
#1~N-1について。Aの添字なので注意
  cfl.append(gcd(A[i-1], A[i]))
  
#cfr: cumsum from right
#[0]~[N-1] 右端は0, 左端はN-1で取り出す
cfr = []
for i in range(N, 1, -1):
#N~2について。やはりAの添字なので注意
  cfr.append(gcd(A[i+1], A[i]))


#maxをansにメモしながら取り除くべき箇所を探す
ans = max(cfl[-1], cfr[-1]) #端っこを取り除いた場合
for nowcfl, nowcfr in zip(cfl[0:-1],cfr[::-1][1:]):
#N=2(cfl, cfrの要素数1)のときは0と-1が一致する
#→よって実行されないので問題なし
  ans = max(ans, gcd(nowcfl, nowcfr))

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
input()
a=[int(i) for i in input().split()]
a.sort()
d=(fractions.gcd(a[0],a[1]),a[1])
ans=1
for i in d:
    x=0
    for j in a:
        if j%i: x+=1
    if x<2: ans=max(ans,i)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
input()
a=[int(i) for i in input().split()]
a.sort()
d=(fractions.gcd(a[0],a[1]),a[0])
ans=1
for i in d:
    x=0
    for j in a:
        if j%i: x+=1
    if x<2: ans=max(ans,i)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
curr1, curr2 = [0], [0]
for i in range(N):
  curr1 += [gcd(A[i],curr1[-1])]
  curr2 += [gcd(A[N-1-i],curr2[-1])]

if N ==2:
  print(max(A[0],A[1]))
else:
  ans = []
  for i in range(N):
    ans += [gcd(curr1[i],curr2[N-1-i])]

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
 
 
for i in range(max(A),1,-1):
    l = list(map(lambda x: x % i,A))
    if l.count(0) >= len(A)-1:
        print(i)
        break

Submission status: Wrong Answer

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

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


gcd = fractions.gcd


left = []
right = []
for i in range(N):
    if i == 0:
        left.append(A[0])
        right.append(A[-1])
        continue

    left.append(gcd(left[i-1], A[i]))
    right.insert(0, gcd(right[0], A[N-i-1]))

max_gcd = right[1]
for i in range(N):
    if i == 0:
        continue
    elif i == N - 1:
        if max_gcd < left[-1]:
            max_gcd = left[-1]
    else:
        target = gcd(left[i-1], right[i+1])
        if max_gcd < target:
            max_gcd = target

print(max_gcd)

Submission status: Wrong Answer

Solution code:
import fractions
N=int(input())
L=[]
A=list(map(int,input().split()))
for i in range(N-1):
  for l in range(i+1,N):
    X=fractions.gcd(A[i],A[l])
    L.append(X)
L.sort(reverse=True) 
for i in L :
  if L.count(i)>=(N-2):
    print(i)
    break

Submission status: Wrong Answer

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

def gcd(a, b):
  if b > a:
    a, b = b, a  
  red = a % b
  if red == 0:
    return b
  else:
    return gcd(red, b)

L = [A[0]]
for i in range(0, N):
  L.append(gcd(A[i], L[-1]))
  
R = [A[-1]]
for i in range(N-1, -1, -1):
  R.append(gcd(A[i], R[-1]))
R = list(reversed(R))
#print(L)
#print(R)

result = 0
for i in range(N-1):
  #print(L[i], R[i+2], i, i+2)
  g = gcd(L[i], R[i+2])
  #print(g)
  result = max([g, result])
  
print(result)

Submission status: Wrong Answer

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

def gcd(a, b):
  if b > a:
    a, b = b, a  
  red = a % b
  if red == 0:
    return b
  else:
    return gcd(red, b)

L = [A[0]]
for i in range(0, N):
  L.append(gcd(A[i], L[-1]))
  
R = [A[-1]]
for i in range(N-1, -1, -1):
  R.append(gcd(A[i], R[-1]))
R = list(reversed(R))
print(L)
print(R)

result = 0
for i in range(N-1):
  #print(L[i], R[i+2], i, i+2)
  g = gcd(L[i], R[i+2])
  print(g)
  result = max([g, result])
  
print(result)

Submission status: Wrong Answer

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

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


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


left = []
right = []
for i in range(N):
    if i == 0:
        left.append(A[0])
        right.append(A[-1])
        continue

    left.append(gcd(left[i-1], A[i]))
    right.insert(0, gcd(right[0], A[N-i-1]))

max_gcd = right[1]
for i in range(N):
    if i == 0:
        continue
    elif i == N - 1:
        if max_gcd < left[-1]:
            max_gcd = left[-1]
    else:
        target = gcd(left[i-1], right[i+1])
        if max_gcd < target:
            max_gcd = target

print(max_gcd)

Submission status: Wrong Answer

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

def gcd(a, b):
  if b > a:
    a, b = b, a  
  red = a % b
  if red == 0:
    return b
  else:
    return gcd(red, b)

L = [A[0]]
for i in range(1, N):
  L.append(gcd(A[i], L[-1]))
  
R = [A[-1], A[-1]]
for i in range(N-2, -1, -1):
  R.append(gcd(A[i], R[-1]))
R = list(reversed(R))
#print(L)
#print(R)

result = 0
for i in range(N-1):
  #print(L[i], R[i+2], i, i+2)
  g = gcd(L[i], R[i+2])
  result = max([g, result])
  
print(result)

Submission status: Wrong Answer

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

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


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


left = []
right = []
for i in range(N):
    if i == 0:
        left.append(A[0])
        right.append(A[-1])
        continue

    left.append(gcd(left[i-1], A[i]))
    right.insert(0, gcd(right[0], A[N-i-1]))

max_gcd = right[1]
for i in range(N):
    if i == 0:
        continue
    elif i == N - 1:
        if max_gcd < left[-1]:
            max_gcd = left[-1]
    else:
        target = gcd(left[i-1], right[i+1])
        if max_gcd < target:
            max_gcd = target

print(max_gcd)

Submission status: Wrong Answer

Solution code:
import fractions
import functools

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

ans = 1

for i in range(1,N):
    A_i = A[:i-1] + A[i:]
    ans = max(ans, functools.reduce(fractions.gcd, A_i))

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
import functools

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

ans = 1

for i in range(N):
    A_i = A[:i-1] + A[i:]
    ans = max(ans, functools.reduce(fractions.gcd, A_i))

print(ans)