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 math import gcd
import sys
input = sys.stdin.readline
n = int(input())
As = list(map(int, input().split()))

"""
7 6 8 
1個除いた最大公約数
A1~A(i-1), Ai+1~ANの最大公約数がわかれば良い
"""
def gcd(n, m):
    # 最大公約数
    a = max(n,m)
    b = min(n,m)
    while b:
        a, b = b, a % b
    return a

class segmented_tree:
    X_unit = 1 << 30
    X_f = lambda self, a, b: gcd(a,b)
    # X_f = gcd
    def __init__(self, N):
        self.N = N
        self.X = [self.X_unit] * (2*N)
        
    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x 
        # 後ろから入れていく
        for i in range(self.N-1, 0, -1):
            self.X[i] = self.X_f(self.X[i<<1], self.X[i<<1|1])

    # 1点更新
    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i<<1],self.X[i<<1|1])
    
    # 区間取得
    def fold(self, l, r):
        l += self.N
        r += self.N
        vl = self.X[l]
        vr = self.X[r-1]
        # 外から決めていく
        while l < r:
            # print(l,r)
            if l & 1:
                vl = self.X_f(self.X[l], self.X[l])
                l += 1
            if r & 1:
                r -= 1
                vr = self.X_f(self.X[r], self.X[r])
            l >>= 1
            r >>= 1
        return self.X_f(vl,vr)
  
st = segmented_tree(n)
st.build(As)
mx = 0
for i in range(n):
    a = st.fold(0,i)
        
    if i+1 < n:
        b = st.fold(i+1,n)
    else:
        b = a
    if i == 0:
        a = b
    # print("a",a,b)
    mx = max(mx,gcd(a,b))
print(mx)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce


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

a=int(input())
b=list(map(int,input().split()))
c=[]
for i in range(a):
    for j in range(a):
        if i!=j:
            c.append(gcd(b[i],b[j]))
print(max(set(c)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

n = int(input())
a = list(map(int, input().split()))
gl=[0]
gr=[0]
for i in range(n):
  gl.append(gcd(a[i], gl[-1]))
  gr.insert(0,gcd(a[n-i-1], gr[0]))
ans = 0
for i in range(n-1):
  ans = max(ans, gcd(gl[i],gr[i+1]))
  
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split()))
if n <= 2:
    print(max(a))
else:
    gcd_left = [a[0]]
    gcd_right = [a[-1]]
    for i in range(1, n):
        gcd_left.append(fractions.gcd(a[i], gcd_left[-1]))
        gcd_right.append(fractions.gcd(a[n-i-1], gcd_right[-1]))
    gcd_right = gcd_right[::-1]
    print(gcd_left, gcd_right)
    ans = max(gcd_left[-2], gcd_right[1])
    for i in range(n-2):
        ans = max(ans, fractions.gcd(gcd_right[i+2], gcd_left[i]))
    print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import*;from fractions import*;g=gcd;u=accumulate;_,a=open(0);*a,=map(int,a.split());print(max(g(s,t)for s,t in zip(list(u([0]+a,g)),list(u(a[::-1],g))[-2::-1])))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
L = [A[0]]
R = [A[-1]]

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

print(ans)

Submission status: Wrong Answer

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


def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return ass #sortされていない


li = divisor(max_a)
li.sort(reverse=True)
#print(li)
ans = 0
for i in li:
    gcd = []
    for j in range(n):
        gcd.append(fractions.gcd(i, a[j]))
    if gcd.count(i) >= n-1 and ans < i:
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

n = int(input())
a = list(map(int, input().split()))
g1 = 10**9
gi1 = -1
g2 = 10**9
gi2 = -1

if n == 2:
    print(max(a))
    exit()

for i in range(n - 1):
    b = fractions.gcd(a[i], a[i + 1])
    if b < g1:
        g1 = b
        gi1 = i

for i in range(n - 2):
    b = fractions.gcd(a[i], a[i + 2])
    if b < g2:
        g2 = b
        gi2 = i

if g1 == g2:
    if gi1 == gi2:
        a[gi1] = a[gi1 + 1]
elif gi1 == gi2 + 2:
    a[gi1] = a[gi1 - 1]
elif gi1 == gi2 + 1:
    a[gi1 + 1] = a[gi1]
elif g1 + 1 == g2:
    a[gi1 + 1] = a[gi1]
elif g1 < g2:
    a[gi1 + 1] = a[gi1]

g1 = 10**9

for i in range(n - 1):
    b = fractions.gcd(a[i], a[i + 1])
    if b < g1:
        g1 = b
        gi1 = i

print(g1)

Submission status: Wrong Answer

Solution code:
import fractions

n = int(input())
a = list(map(int, input().split()))
g1 = 10**9
gi1 = -1
g2 = 10**9
gi2 = -1

if n == 2:
    print(max(a))
    exit()

for i in range(n - 1):
    b = fractions.gcd(a[i], a[i + 1])
    if b < g1:
        g1 = b
        gi1 = i

for i in range(n - 2):
    b = fractions.gcd(a[i], a[i + 2])
    if b < g2:
        g2 = b
        gi2 = i

if g1 == g2:
    if gi1 == gi2:
        a[gi1] = a[gi1 + 1]
elif gi1 == gi2 + 2:
    a[gi1] = a[gi1 - 1]
elif g1 < g2:
    a[gi1 + 1] = a[gi1]

g1 = 10**9

for i in range(n - 1):
    b = fractions.gcd(a[i], a[i + 1])
    if b < g1:
        g1 = b
        gi1 = i

print(g1)

Submission status: Wrong Answer

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

ma = 0
for i in range(len(a)):
  for j in range(len(a)):
    if i < j:
      if ma < fractions.gcd(a[i], a[j]):
        ma = fractions.gcd(a[i], a[j])

print(ma)

Submission status: Wrong Answer

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

from fractions import gcd
left = [A[0]]
right = [A[-1]]

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

ans = 1
for i in range(N):
    if i == 0:
        tmp = right[1]
    elif i == N-1:
        tmp = left[-2]
    else:
        tmp = gcd(left[i-1], right[i-1])
    ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

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

if n==2:
    print(max(a))
    exit()

from fractions import gcd

minpoint=None
maxi=max(a)
a0=a[0]
for i in range(n-1):
    a1=a[i+1]
    a0=gcd(a0,a1)
    if maxi>a0:
        maxi=a0
        minpoint=i
        if a0==1:
            break

if minpoint==None:
    print(a0)
    exit()

cand0=a[minpoint-1]
cand1=a[minpoint]
for i in range(n):
    if i!=minpoint:
        cand0=gcd(a[i],cand0)
    if i!=minpoint+1:
        cand1=gcd(a[i],cand1)

print(max(cand0,cand1))

Submission status: Wrong Answer

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

if n==2:
    print(max(a))
    exit()

from fractions import gcd

minpoint=None
maxi=max(a)
a0=a[0]
for i in range(n-1):
    a1=a[i+1]
    a0=gcd(a0,a1)
    if maxi>a0:
        maxi=a0
        minpoint=i
        if a0==1:
            break

if minpoint==None:
    print(a0)
    exit()

cand0=a[minpoint+1]
cand1=a[minpoint]
for i in range(n):
    if i!=minpoint:
        cand0=gcd(a[i],cand0)
    if i!=minpoint+1:
        cand1=gcd(a[i],cand1)

print(max(cand0,cand1))

Submission status: Wrong Answer

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

if n==2:
    print(max(a))
    exit()

from fractions import gcd

minpoint=None
maxi=max(a)
a0=a[0]
for i in range(n-1):
    a1=a[i+1]
    a0=gcd(a0,a1)
    if maxi>a0:
        maxi=a0
        minpoint=i
        if a0==1:
            break

if minpoint==None:
    print(a0)
    exit()

cand0=a[minpoint-1]
cand1=a[minpoint-1]
for i in range(n):
    if i!=minpoint:
        cand0=gcd(a[i],cand0)
    if i!=minpoint+1:
        cand1=gcd(a[i],cand1)

print(max(cand0,cand1))

Submission status: Wrong Answer

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

minpoint=None
maxi=max(a)
a0=a[0]
for i in range(n-1):
    a1=a[i+1]
    a0=gcd(a0,a1)
    if maxi>a0:
        maxi=a0
        minpoint=i
if minpoint==None:
    print(a0)
    exit()

cand0=a[minpoint-2]
cand1=a[minpoint-2]
for i in range(n):
    if i!=minpoint:
        cand0=gcd(a[i],cand0)
    if i!=minpoint+1:
        cand1=gcd(a[i],cand1)

print(max(cand0,cand1))

Submission status: Wrong Answer

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

minpoint=None
maxi=max(a)
a0=a[0]
for i in range(n-1):
    a1=a[i+1]
    a0=gcd(a0,a1)
    if maxi>a0:
        maxi=a0
        minpoint=i

if minpoint==None:
    print(a0)
    exit()

cand0=max(a)
cand1=max(a)
for i in range(n):
    if i!=minpoint:
        cand0=gcd(a[i],cand0)
    if i!=minpoint+1:
        cand1=gcd(a[i],cand1)

print(max(cand0,cand1))

Submission status: Wrong Answer

Solution code:
from fractions import *
n,*a=map(int,open(0).read().split())
l=[0]+[a[0]]*(n-1)
r=[a[-1]]*(n-1)+[0]
ans=0
for i in range(2,n):
  l[i]=gcd(l[i-1],a[i])
for i in range(n-3,-1,-1):
  r[i]=gcd(r[i+1],a[i+1])
for i in range(n):
  ans=max([0,l[i],r[i],gcd(l[i],r[i])][(l[i]>0)+2*(r[i]>0)],ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import *
n,*a=map(int,open(0).read().split())
l=[0]+[a[0]]*(n-1)
r=[a[-1]]*(n-1)+[0]
ans=0
for i in range(2,n):
  l[i]=gcd(l[i-1],a[i])
for i in range(n-3,-1,-1):
  print(r[i+1],a[i+1])
  r[i]=gcd(r[i+1],a[i+1])
for i in range(n):
  ans=max([0,l[i],r[i],gcd(l[i],r[i])][(l[i]>0)+2*(r[i]>0)],ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
N=int(input())
A=list(map(int,input().split()))
A.append(A[0])
ans=0
l=[]
if N==2:
    print(max(A))
    exit()
for i in range(N):
    val=fractions.gcd(A[i],A[i+1])
    l.append(val)
l.sort()
print(l)

lst=[]
for i in range(len(l)):
    if l[i]==l[0]:
        continue
    lst.append(l[i])

x=dict()
for i in range(len(lst)):
    val=lst[i]
    if val in x:
        x[val]+=1
    else:
        x[val]=1

cnt=0
for idx in x:
    cnt+=1
if cnt==0:
    print(l[0])
    exit()
if cnt==1:
    print(lst[0])
else:
    print(l[0])
    exit()

Submission status: Wrong Answer

Solution code:
import fractions
N=int(input())
A=list(map(int,input().split()))
A.append(A[0])
ans=0
l=[]
if N==2:
    print(max(A))
    exit()
for i in range(N):
    val=fractions.gcd(A[i],A[i+1])
    l.append(val)
l.sort()
print(l[2])

Submission status: Wrong Answer

Solution code:
import fractions
N=int(input())
A=list(map(int,input().split()))
A.append(A[0])
ans=0
l=[]
if N==2:
    print(max(A))
    exit()
for i in range(N):
    val=fractions.gcd(A[i],A[i+1])
    l.append(val)

print(l[2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# C - GCD on Blackboard
from collections import defaultdict

n = int(input())
a = list(int(x) for x in input().split())
a.sort()

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

if n==2:
    print(max(a))
else:
    d = defaultdict(int)
    for i in range(n-1):
        d[gcd(a[i], a[i+1])] += 1
    for i in range(n-2):
        d[gcd(a[i], a[i+2])] += 1
    
    miKey, miVal = min(d.items(), key=lambda x: x[0])
    if miVal > 3:
        print(miKey)
    else:
        print((sorted(d)[1]))

Submission status: Wrong Answer

Solution code:
# C - GCD on Blackboard

n = int(input())
a = list(int(x) for x in input().split())
a.sort()

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

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

Submission status: Wrong Answer

Solution code:
# C - GCD on Blackboard

n = int(input())
a = list(int(x) for x in input().split())
a.sort()

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

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

Submission status: Wrong Answer

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

for n in range(1,N):
  L[n]=gcd(A[n],L[n-1])
  R[n]=gcd(A[N-n-1],R[n-1])
  
  ans=max(L[N-2],R[N-2])

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

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N = int(input())
As = list(map(int, input().split()))
re_As = As[::-1]
gcds = [0]*(N+1)
rgcds = [0]*(N+1)

for i in range(N):
    gcds[i] = gcd(As[i], As[i-1])
    rgcds[i] = gcd(re_As[i], re_As[i-1])

rgcds = rgcds[::-1]

ans = [0]*(N+1)

for i, (s, r) in enumerate(zip(gcds, rgcds)):
    ans[i] = gcd(s, r)
    
print(max(ans))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
N=int(input())
A=list(map(int,input().split()))
ans=1
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
for i in range(N-1):
    A_c = A.copy()
    del A_c[i]
    g = gcd_list(A_c)
    if ans<=g:
        ans=g
print(ans)

Submission status: Wrong Answer

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

first = A[0]
second = A[0]

for a in A:
  second = max(gcd(second, a) ,first)
  first = gcd(first,a)
print(max(first,second))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = 0
ans, mina = a[0], abs(a[0])
flag = False
for i in range(1, n):
    ans += abs(a[i])
    mina = min(mina, abs(a[i]))
    if a[i]<0: count += 1
if count%2 or a.count(0): print(ans-mina*2)
else: print(ans)

Submission status: Wrong Answer

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

left = [0]*n
right = [0]*n
from fractions import gcd
for i in range(1,n-1):
  left[i] = gcd(left[i-1],a[i-1])
  right[n-i-1] = gcd(right[n-i],a[n-i])

ans = 1
for i in range(n):
  g = gcd(left[i],right[i])
  ans = max(ans,g)
print(ans)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    from fractions import gcd
    ma = -1
    n = int(input())
    A = readInts()
    # N = 2の時に注意して
    A = sorted(A)
    if n == 2:
        print(max(A[0],A[1]))
    elif n == 3:
        print(max(gcd(A[0],A[1]),gcd(A[1],A[2]),gcd(A[0],A[2])))
    else:
        print(min(gcd(A[0],A[1]),gcd(A[1],A[2]),gcd(A[0],A[2])))

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    from fractions import gcd
    ma = -1
    n = int(input())
    A = readInts()
    # N = 2の時に注意して
    if n == 2:
        print(max(A[0],A[1]))
    else:# N >= 3
        print(max(gcd(A[0],A[1]),gcd(A[1],A[2]),gcd(A[0],A[2])))


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
for a in range(A[-1],int(A[-1]**0.5)-1,-1):
    cnt=0
    for i in range(N):
        if A[i]%a!=0:
            cnt+=1
        if cnt==2:
            break
    if cnt!=2:
        print(a)
        break

Submission status: Wrong Answer

Solution code:
import math
n = int(input())

xs = [int(x) for x in input().split()]

l = []
r = []
l.append(xs[0])
for x in xs:
    l.append(x)
    r.append(x)
r.append(xs[-1])


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


# print(gcd(6, 8))
# print(xs)
# for ind in range(len(xs)):
#     for x in range(len(xs)):
#         if x != ind:
#             v = gcd(xs[x], xs[x+1])
# xs = sorted(xs)
mx = 1
ok = False
# lets precompute l[i] and r[i]
for i in range(0, n):
    l[i] = gcd(l[i], l[i-1])
    # print(f'i: {i}, l[i]: {l[i]}')

for i in range(n-1, 0, -1):
    r[i] = gcd(r[i], r[i+1])
    # print(f'i: {i}, r[i]: {l[i]}')

for ind in range(len(xs)):
    v = gcd(l[ind], r[ind])
    # print(f'{ind}: v = {v}')
    if v > mx:
        mx = v
    # if ind == 0:
    #     v = xs[1]
    # else:
    #     v = xs[0]
    # for i in range(len(xs)):
    #     if i != ind:
    #         v = gcd(v, xs[i])
    # if ind == 0:
    #     if v == xs[1]:
    #         print(v)
    #         ok = True
    #         break
    # if ind == 1:
    #     if v == xs[0]:
    #         print(v)
    #         ok = True
    #         break
    # if v >= mx:
    #     mx = v
    # print(f'v for ind {ind}: {v}')
# print(mx)
if not ok:
    print(mx)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())

xs = [int(x) for x in input().split()]

l = []
r = []
l.append(xs[0])
for x in xs:
    l.append(x)
    r.append(x)
r.append(xs[-1])


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


# print(gcd(6, 8))
# print(xs)
# for ind in range(len(xs)):
#     for x in range(len(xs)):
#         if x != ind:
#             v = gcd(xs[x], xs[x+1])
# xs = sorted(xs)
mx = 1
ok = False
# lets precompute l[i] and r[i]
for i in range(1, n):
    l[i] = gcd(l[i], l[i-1])

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

for ind in range(len(xs)):
    v = gcd(l[ind-1], r[ind+1])
    if v > mx:
        mx = v
    # if ind == 0:
    #     v = xs[1]
    # else:
    #     v = xs[0]
    # for i in range(len(xs)):
    #     if i != ind:
    #         v = gcd(v, xs[i])
    # if ind == 0:
    #     if v == xs[1]:
    #         print(v)
    #         ok = True
    #         break
    # if ind == 1:
    #     if v == xs[0]:
    #         print(v)
    #         ok = True
    #         break
    # if v >= mx:
    #     mx = v
    # print(f'v for ind {ind}: {v}')
# print(mx)
if not ok:
    print(mx)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())

xs = [int(x) for x in input().split()]

l = [0]
r = [0]
for x in xs:
    l.append(x)
    r.append(x)


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


# print(gcd(6, 8))
# print(xs)
# for ind in range(len(xs)):
#     for x in range(len(xs)):
#         if x != ind:
#             v = gcd(xs[x], xs[x+1])
# xs = sorted(xs)
mx = 1
ok = False
# lets precompute l[i] and r[i]
for i in range(1, n):
    l[i] = gcd(l[i], l[i-1])

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

for ind in range(len(xs)):
    v = gcd(l[ind-1], r[ind+1])
    if v > mx:
        mx = v
    # if ind == 0:
    #     v = xs[1]
    # else:
    #     v = xs[0]
    # for i in range(len(xs)):
    #     if i != ind:
    #         v = gcd(v, xs[i])
    # if ind == 0:
    #     if v == xs[1]:
    #         print(v)
    #         ok = True
    #         break
    # if ind == 1:
    #     if v == xs[0]:
    #         print(v)
    #         ok = True
    #         break
    # if v >= mx:
    #     mx = v
    # print(f'v for ind {ind}: {v}')
# print(mx)
if not ok:
    print(mx)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
g = gcd(a[0], a[1])
l = []
l.append(a[0]//g)
l.append(a[1]//g)
for i in range(2, n):
    g = gcd(g, a[i])
    tmp = a[2]//g
    for i in range(len(l)):
        l[i] = gcd(tmp, l[i])
print(g*max(l))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n = int(input())
a = [int(i) for i in input().split()]

mx = 0
for i in range(n):
    l = 0
    r = 0
    for j in range(i-1): l = gcd(l, a[j])
    for j in range(i, n): r = gcd(r, a[j])
    mx = max(mx, gcd(l, r))

print(mx)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ar = a[::-1]
    lgcds = [1]*n
    rgcds = [1]*n
    lgcd, rgcd = a[0], ar[0]
    lgcds[0] = rgcd
    lgcds[1] = lgcd
    rgcds[n-1] = lgcd
    rgcds[n-2] = rgcd
    for i in range(2, n):
        lgcd = gcd(lgcd, a[i])
        rgcd = gcd(rgcd, ar[i])
        lgcds[i] = lgcd
        rgcds[n-1-i] = rgcd
    ans = 1
    for i in range(n):
        gi = gcd(lgcds[i], rgcds[i])
        if gi > ans:
            ans = gi
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# A[i]の左までのgcdと右以降のgcdを保持
N = ir()
A = lr()

def calc(arr):
    ret = [arr[0]]
    g = arr[0]
    for x in arr[1:]:
        result = gcd(g, x)
        ret.append(result)
    return ret

g_left = calc(A)
g_right = calc(A[::-1])[::-1]

answer = max(g_right[1], g_left[-2])
for i in range(1, N-1):
    temp = gcd(g_left[i-1], g_right[i+1])
    if temp > answer:
        answer = temp

print(answer)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
from fractions import gcd
from collections import defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def prime_factorize(n): # Nの素因数分解
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

# 約数が１つしかないものを探す
N = ir()
A = lr()
g = A[0]
dic = defaultdict(int)
for a in A:
    g = gcd(g, a)
    primes = prime_factorize(a)
    for p in primes:
        dic[p] += 1

cand = [1]
for k, v in dic.items():
    if v == 1:
        cand.append(k)

x = max(cand)
g = A[0] if A[0] % x != 0 else A[-1]
for a in A:
    if a%x == 0:
        continue
    g = gcd(g, a)

answer = g
print(answer)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd

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

ans = 1
for i in range(N):
    B = A[:i] + A[i+1:]
    ans = max(ans, reduce(gcd, B))
    print(B)

print(ans)

Submission status: Wrong Answer

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

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

dp1 = []
dp2 = []

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

for i in range(len(a_list)):
    if not dp1:
        dp1.append(a_list[0])
    else:
        dp1.append(gcd(dp1[-1], a_list[i]))
    if not dp2:
        dp2.append(a_list[-1])
    else:
        dp2.append(gcd(dp2[-1], a_list[-i-1]))

ret = 0

dp2.reverse()

for i in range(len(a_list)-2):
    val = gcd(dp1[i], dp2[-len(dp2)+2+i])
    ret = max(ret, val)

ret = max(ret, dp1[-2], dp2[-2])

print(ret)

Submission status: Wrong Answer

Solution code:
import copy
from fractions import gcd

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

Answer = 1
if N == 2:
    Answer = max(ListA[0],ListA[1])
else:
    for j in range(N):
        Lista = copy.deepcopy(ListA)
        Lista.pop(j)
        GCDa = gcd(Lista[0],Lista[1])
        for i in range(N-1):
            GCDa = gcd(Lista[i],GCDa)
            if GCDa == 1:
                continue
            Answer = max(GCDa,Answer)

print(Answer)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

n=int(input())
A=list(map(int,input().split()))
DP=[[0,0] for _ in range(n)]
DP[0][0]=A[0]
DP[-1][1]=A[-1]

for i in range(1,n-1):
    left,right=i,n-i-1
    DP[left][0]=gcd(DP[left-1][0],A[i])
    DP[right][1]=gcd(DP[right+1][1],A[i])

ans=max(DP[1][1],DP[-2][0])
for i in range(1,n-1):
    ans=max(ans,gcd(DP[i-1][0],DP[i+1][1]))
print(ans)

Submission status: Wrong Answer

Solution code:
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)
    return divisors


n=int(input())
A=sorted(list(map(int,input().split())))
B=[make_divisors(A[1]),make_divisors(A[0])]

ans=1
for i,j in enumerate(B):
    for k in j:
        cnt=0
        for m in range(n):
            if m==i:continue
            elif A[m]%k!=0:
                cnt +=1
        if cnt==0 or cnt==1:ans=max(ans,k)
print(ans)

Submission status: Wrong Answer

Solution code:
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)
    return divisors


n=int(input())
A=sorted(list(map(int,input().split())))
B=[make_divisors(A[1]),make_divisors(A[0])]

cnt=0
for i,j in enumerate(B):
    for k in j:
        flag=1
        for m in range(n):
            if m==i:continue
            elif A[m]%k!=0:
                flag=0
                break
        if flag==1:cnt=max(cnt,k)
print(cnt)

Submission status: Wrong Answer

Solution code:
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)
    return divisors


n=int(input())
A=sorted(list(map(int,input().split())))
B=[make_divisors(A[1]),make_divisors(A[0])]

cnt=0
for i,j in enumerate(B):
    for k in j:
        flag=1
        for m in range(n):
            if m==i:continue
            elif A[m]%k!=0:
                flag=0
                break
        if flag:cnt=max(cnt,k)
print(cnt)

Submission status: Wrong Answer

Solution code:
import copy
from fractions import gcd

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

Answer = 1
if N == 2:
    Answer = gcd(ListA[0],ListA[1])
else:
    for j in range(N):
        Lista = copy.deepcopy(ListA)
        Lista.pop(j)
        GCDa = gcd(Lista[0],Lista[1])
        for i in range(N-1):
            GCDa = gcd(Lista[i],GCDa)
            if GCDa == 1:
                continue
            Answer = max(GCDa,Answer)

print(Answer)

Submission status: Wrong Answer

Solution code:
import copy
def gcd(x,y):
  ListGCD = []
  ListGCD.append(x)
  ListGCD.append(y)
  ListGCD.sort(reverse = True)
  while ListGCD[-1] != 0:
      ListGCD.append(ListGCD[-2]%ListGCD[-1])
  return ListGCD[-2]
  
N = int(input())
ListA = list(map(int,input().split()))

Answer = 1
if N == 2:
    Answer = gcd(ListA[0],ListA[1])
else:
    for j in range(N):
        Lista = copy.deepcopy(ListA)
        Lista.pop(j)
        GCDa = gcd(Lista[0],Lista[1])
        proAnswer = GCDa
        for i in range(N-1):
            GCDa = gcd(Lista[i],GCDa)
            if GCDa == 1:
                break
            Answer = max(GCDa,proAnswer,Answer)

print(Answer)

Submission status: Wrong Answer

Solution code:
import sys

# import bisect
# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter

# import math

# from numba import jit

# from scipy import
# import numpy as np
# import networkx as nx

# import matplotlib.pyplot as plt

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


class SegmentTree:

    def __init__(self, array, operator, identity):
        self.identity = identity
        self.operator = operator

        self.array_size = len(array)
        tree_height = (self.array_size - 1).bit_length()
        self.tree_size = 2 ** (tree_height + 1)
        self.leaf_start_index = 2 ** tree_height
        self.tree = [identity] * self.tree_size

        for i in range(self.array_size):
            self.tree[self.leaf_start_index + i] = array[i]

        for i in range(self.array_size - 1, 0, -1):
            self.tree[i] = self.operator(self.tree[i << 1], self.tree[i << 1 | 1])

    def update(self, index, val):
        cur_node = self.leaf_start_index + index
        self.tree[cur_node] = val

        while cur_node > 1:
            self.tree[cur_node >> 1] = self.operator(self.tree[cur_node], self.tree[cur_node ^ 1])
            cur_node >>= 1

    def query(self, begin, end):
        res = self.identity

        if begin < 0:
            begin = 0
        elif begin > self.array_size:
            return self.identity

        if end > self.array_size:
            end = self.array_size
        elif end < 1:
            return self.identity

        left = begin + self.leaf_start_index
        right = end + self.leaf_start_index

        while left < right:
            if left & 1:
                res = self.operator(res, self.tree[left])
                left += 1

            if right & 1:
                right -= 1
                res = self.operator(res, self.tree[right])

            left >>= 1
            right >>= 1

        return res


def main():
    from fractions import gcd

    n = int(input())
    a = list(map(int, readline().split()))
    seg = SegmentTree(a, gcd, 0)
    ans = 0

    for i in range(n):
        temp1 = seg.query(0, i)
        temp2 = seg.query(i + 1, n)
        temp = gcd(temp1, temp2)
        ans = max(ans, temp)

    print(ans)


if __name__ == '__main__':
    main()