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:
import fractions
import functools
import copy

N = int(input())
A = list(map(int, input().split()))
gcd_lst = [0]*len(A)
for i in range(0, len(A)):
    if i == 0:
        gcd_lst[i] = functools.reduce(fractions.gcd, A[1:])
        continue
    elif i == len(A)-1:
        gcd_lst[i] = functools.reduce(fractions.gcd, A[:i])
        continue

    lstL = A[:i]
    lstR = A[i+1::]
    if len(lstL) > 2:
        gcdL = functools.reduce(fractions.gcd, lstL)
    else:
        gcdL = lstL[0]
    if len(lstR) > 2:
        gcdR = functools.reduce(fractions.gcd, lstR)
    else:
        gcdR = lstR[0]
    gcd_lst[i] = fractions.gcd(gcdL, gcdR)

print(max(gcd_lst))

Submission status: Wrong Answer

Solution code:
import fractions
import functools
import copy

N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(0, len(A)):
    if i == 0:
        ans = max(ans, functools.reduce(fractions.gcd, A[1:]))
        continue
    elif i == len(A)-1:
        ans = max(ans, functools.reduce(fractions.gcd, A[:i]))
        continue

    lstL = A[:i]
    lstR = A[i+1::]
    if len(lstL) > 2:
        gcdL = functools.reduce(fractions.gcd, lstL)
    else:
        gcdL = lstL[0]
    if len(lstR) > 2:
        gcdR = functools.reduce(fractions.gcd, lstR)
    else:
        gcdR = lstR[0]
    ans = max(ans, fractions.gcd(gcdL, gcdR))

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
import functools
import copy

N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(0, len(A)):
    if i == 0:
        ans = max(ans, functools.reduce(fractions.gcd, A[1:]))
        continue
    elif i == len(A)-1:
        ans = max(ans, functools.reduce(fractions.gcd, A[:i]))
        continue

    lstL = A[:i]
    lstR = A[i+1::]
    if len(lstL) > 2:
        gcdL = functools.reduce(fractions.gcd, lstL)
    else:
        gcdL = lstL[0]
    if len(lstR) > 2:
        gcdR = functools.reduce(fractions.gcd, lstR)
    else:
        gcdR = lstR[0]

    ans = max(ans, fractions.gcd(gcdL, gcdR))

print(ans)

Submission status: Wrong Answer

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

L = [0]
R = [0]
for i in range(N):
    L.append(fractions.gcd(L[i], lst[i]))
    R.insert(1, fractions.gcd(R[0], lst[N-1-i]))
ans = 0
for i in range(N):
    ans = max(ans, fractions.gcd(L[i], R[i+1]))
print(ans)

Submission status: Wrong Answer

Solution code:
def MAP(): return map(int,input().split())
def gcd(a, b):
    while b:
        a %= b
        a, b = b, a
    return a

n = int(input())
*a, = MAP()

mx = max(a)
a = sorted(a,key=lambda x:gcd(mx,x))
print(gcd(a[1],mx))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC125 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def gcd(n,m):
    if m == 0:
        return n
    else:
        return gcd(m,n%m)

n = I()
a = LI()
l,r = [0]*n,[0]*n
l[0] = a[0]
r[-1] = a[-1]
for i in range(1,n):
    l[i] = gcd(l[i-1],a[i])
for i in range(n-1)[::-1]:
    r[i] = gcd(r[i+1],a[i])
ans = 0
l = [0] + l + [0]
r = [0] + r + [0]
for i in range(n):
    ans = max(ans,gcd(l[i-1],r[i+1]))
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC125 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def gcd(n,m):
    if m == 0:
        return n
    else:
        return gcd(m,n%m)

n = I()
a = LI()
l,r = [0]*n,[0]*n
l[0] = a[0]
r[-1] = a[-1]
for i in range(1,n):
    l[i] = gcd(l[i-1],a[i])
for i in range(n-1)[::-1]:
    r[i] = gcd(r[i+1],a[i])
ans = 0
l = [0] + l + [0]
r = [0] + r + [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 fractions
n = int(input())
a = list(map(int, input().split()))
b = [0] * (n + 1)
c = [0] * (n + 1)
for i in range(len(a)):
    if i == 0:
        b[i+1] = a[i]
        c[-i-2] = a[-i-1]
    else:
        b[i+1] = fractions.gcd(a[i], b[i])
        c[-i-2] = fractions.gcd(a[-i-1], c[-i-1])
m_gcd = 0
for i in range(len(b)-2):
    m_gcd = max(fractions.gcd(c[i+1], b[i]), m_gcd)
print(m_gcd)

Submission status: Wrong Answer

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

L=[0]
R=[0]
for i in range(n-1):
    L.append(gcd(L[i],a[i]))
    R.insert(0,gcd(R[-1-i],a[-1-i]))
#print(L2)
#print(R2)
ans = 0
for i in range(n-1):
  ans = max(ans,gcd(L[i],R[i]))
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import copy
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, = map(int, input().split())
data = getInputListInt()

gcdNormal = np.zeros(n)
gcdReverse = np.zeros(n)

ans = 0

for i in range(1, n):
    if i==1:
        ans = fractions.gcd(data[i-1], data[i])
        gcdNormal[i] = ans
        gcdNormal[0] = data[0]
    else:
        gcdans = fractions.gcd(ans, data[i])
        ans = max(ans, gcdans)
        gcdNormal[i] = ans

ans = 0

for i in range(n-2, -1, -1):
    if i==n-2:
        ans = fractions.gcd(data[i], data[i+1])
        gcdReverse[i] = ans
        gcdReverse[i+1] = data[i+1]
    else:
        gcdans = fractions.gcd(ans, data[i])
        ans = max(ans, gcdans)
        gcdReverse[i] = ans

ans= 0
for i in range(n):
    if i ==0:
        ans = max(ans, gcdReverse[0])
    elif i == n-1:
        ans = max(ans, gcdNormal[n-1])
    else:
        ans = max(ans, fractions.gcd(gcdNormal[i-1], gcdReverse[i+1]))

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
import copy
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, = map(int, input().split())
data = getInputListInt()

gcdNormal = np.zeros(n)
gcdReverse = np.zeros(n)

ans = 0

for i in range(1, n):
    if i==1:
        ans = fractions.gcd(data[i-1], data[i])
        gcdNormal[i] = ans
        gcdNormal[0] = data[0]
    else:
        gcdans = fractions.gcd(ans, data[i])
        ans = max(ans, gcdans)
        gcdNormal[i] = ans

ans = 0

for i in range(n-2, -1, -1):
    if i==n-2:
        ans = fractions.gcd(data[i], data[i+1])
        gcdReverse[i] = ans
        gcdReverse[i+1] = data[i+1]
    else:
        gcdans = fractions.gcd(ans, data[i])
        ans = max(ans, gcdans)
        gcdReverse[i] = ans

ans= 0
for i in range(n):
    if i ==0:
        ans = max(ans, gcdReverse[1])
    elif i == n-1:
        ans = max(ans, gcdNormal[n-2])
    else:
        ans = max(ans, fractions.gcd(gcdNormal[i-1], gcdReverse[i+1]))

print(int(ans))

Submission status: Wrong Answer

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

result = min(A)
while True:
    counter = 0
    for e in A:
        if e % result != 0:
            counter += 1
    if counter <= 1:  # 1つは書き換えられる
        break
    else:
        result -= 1

print(result)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

_max=1
if N==2:
    print(gcd(A[0], A[1]))
else:
    for i in range(N):
        list_A = A[0:i]+A[i+1:N]
        for g in range(1,N-1):
            _max = max(gcd(list_A[0], list_A[g]), _max)
            if _max==1:
                break
    print(_max)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from fractions import gcd
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    tmp = 1
    tmp2 = 0
    B = A[0]
    if N == 2:
        print(max(A))
    else:
        D = A[0]
        E = A[1]
        for i in range(2,N):
            D = gcd(D,A[i])
            E = gcd(E,A[i])
        for i in range(1,N):
            if B/gcd(B,A[i]) > tmp2:
                tmp = i
                tmp2 = B/gcd(B,A[i])
            B = gcd(B,A[i])
        C = A[0]
        for i in range(1,tmp):
            C = gcd(C,A[i])
        for i in range(tmp+1,N):
            C = gcd(C,A[i])
        print(max(C,D,E))
    
    
main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from fractions import gcd
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    tmp = 1
    B = A[0]
    if N == 2:
        print(max(A))
    else:
        D = A[0]
        E = A[1]
        for i in range(2,N):
            D = gcd(D,A[i])
            E = gcd(E,A[i])
        for i in range(1,N):
            if B > gcd(B,A[i]):
                tmp = i
            B = gcd(B,A[i])
        C = A[0]
        for i in range(1,tmp):
            C = gcd(C,A[i])
        for i in range(tmp+1,N):
            C = gcd(C,A[i])
        print(max(C,D,E))
    
    
main()

Submission status: Wrong Answer

Solution code:
import fractions

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

if len(list(set(A))) > 2:
    A = list(set(A))
elif len(list(set(A))) == 2:
    C = list(set(A))
    if A.count(C[0])==1 and A.count(C[1])==1:
        print(max(C))
    elif A.count(C[0])==1:
        print(C[1])
    elif A.count(C[1])==1:
        print(C[0])
    else:
        print(fractions.gcd(C[0],C[1]))
    exit()
else:
    print(A[0])
    exit()
for j in range(len(A)):
    B = A[:]
    B.pop(j)
    tmp = max(B)
    for i in B:
        tmp = fractions.gcd(tmp, i)
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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

for j in range(len(A)):
    if len(A)==1:
        A.append(A[0])
    B = A[:]
    B.pop(j)
    tmp = max(B)
    for i in B:
        tmp = fractions.gcd(tmp, i)
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

N = int(input())
A = list(map(int,input().split()))
tmp = A[0]
before = A[0]
i = 0
ans = 0

for j in range(N):
    tmp = fractions.gcd(tmp, A[j])
    if tmp < before:
        before = tmp
        i = j
A.pop(i)
ans = A[0]
for k in A:
    ans = fractions.gcd(ans, k)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

N = int(input())
A = list(map(int,input().split()))
tmp = max(A)
before = max(A)
i = 0
ans = 0

for j in range(N):
    tmp = fractions.gcd(tmp, A[j])
    if tmp < before:
        before = tmp
        i = j
A.pop(i)
ans = max(A)
for k in A:
    ans = fractions.gcd(ans, k)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = dict()
a = [ int(i) for i in input().split() ]
import sys
if n == 2:
    print(max(a))
    sys.exit()

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

nums = set()
for i in range(1,n):
    nums.add(gcd(a[0],a[i]))
nums.add(gcd(a[1],a[2]))

ans = 0
for i in nums:
    found = True
    cnt = 0
    for j in a:
        if j % i != 0:
            cnt += 1
            if cnt >= 2:
                found = False
                break
    if found:
        ans = max(ans, i)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(n):
  b=a[:i]+a[i+1:]
  ans[i] = b[0]
  for j in range(1, n-1):
    ans[i] = fractions.gcd(ans[i], b[j])
  print(b,ans[i])
print(max(ans))

Submission status: Wrong Answer

Solution code:
import fractions 
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for j in range(1,n):
  ans=fractions.gcd(ans,a[j])
b=[]
for i in range(n):
  b.append(a[i]//ans)
b.sort()
if b[0]==b[1]:
  print(ans)
else:
  print(ans*b[1])

Submission status: Wrong Answer

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

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

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

    # divisors.sort()
    return divisors
cd = []
tmp = []
for i,b in enumerate(a):
  gcd_list = make_divisors(b)
  for j in gcd_list:
    cd.append(j)
  if i <= 1:
    for k in gcd_list:
      tmp.append(k)
gcd_list.sort()
max_ = 0

for i in gcd_list:
  if cd.count(i) == n-1:
    max_ = max(max_,i)
print(max_)

Submission status: Wrong Answer

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

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

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

    # divisors.sort()
    return divisors
cd = []
tmp = []
for i,b in enumerate(a):
  gcd_list = make_divisors(b)
  for j in gcd_list:
    cd.append(j)
  if i <= 1:
    for k in gcd_list:
      tmp.append(k)
gcd_list.sort()
max_ = 0

for i in gcd_list:
  if cd.count(i) == n-1:
    print('flag')
    max_ = max(max_,i)
print(max_)

Submission status: Wrong Answer

Solution code:
# 左右それぞれの累積GCD
n = int(input())
arr = list(map(int, input().split()))
lgcd, rgcd = list(range(n - 1)), list(range(n - 1))


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


lgcd[0] = gcd(arr[0], arr[1])
rgcd[-1] = gcd(arr[-1], arr[-2])

for i in range(1, n - 1):
    lgcd[i] = max(1, (gcd(lgcd[i - 1], arr[i + 1])))
    rgcd[-i - 1] = max(1, (gcd(rgcd[-i], arr[n - 2 - i])))

if len(set(arr)) == 1:
    print(arr[0])
else:
    ans = 0
    for i in range(n - 1):
        ans = max(ans, lgcd[i] + rgcd[i])
    print(ans)

Submission status: Wrong Answer

Solution code:
import functools
import fractions
n = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(n-1):
    b = a.pop(i)
    gcd = functools.reduce(fractions.gcd, a)
    c = max(c,gcd)
    a.insert(i, b)
print(c)

Submission status: Wrong Answer

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

def gcd(x,y):
    if x < y:
        _ = x
        x = y
        y = _
    return gcd_(x,y)

N = int(input())
AList = list(map(int,input().split()))
Lgcd = [0] * N 
Rgcd = [0] * N

for i in range(N):
    if i == 0:
        Lgcd[i] = AList[i]
    else:
        Lgcd[i] = gcd(Lgcd[i-1],AList[i])
        
for i in range(N):
    j = N-1-i
    if i == 0:
        Rgcd[j] = AList[j]
    else:
        Rgcd[j] = gcd(Rgcd[j+1],AList[j])

max1 = 0
for i in range(N):
    if i == 0:
        gcd1 = Rgcd[1]
    elif i == N-1:
        gcd1 = Lgcd[N-1]
    else:
        gcd1 = gcd(Lgcd[i-1], Rgcd[i+1])
    if max1 < gcd1:
        max1 = gcd1

print(max1)

Submission status: Wrong Answer

Solution code:
# Atcoder forces me to use fractions.gcd instead of math.gec because the contest accepts only python 3.4

import fractions
from functools import reduce


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


N = int(input())
A = list(map(int, input().split()))
A_set = list(set(A))
A_lib = {}
for a in A:
    if a in A_lib:
        A_lib[a] += 1
    else:
        A_lib[a] = 1

if len(A_set) == 1:
    ans = A_set[0]
else:
    ans = 1
    for i in range(len(A_set)):
        if A_lib[A_set[i]] == 1:
            ans = max(ans, gcd_list(A_set[:i] + A_set[i + 1:]))

print(ans)

Submission status: Wrong Answer

Solution code:
# Atcoder forces me to use fractions.gcd instead of math.gec because the contest accepts only python 3.4

import fractions
from functools import reduce


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


N = int(input())
A = list(map(int, input().split()))
A_set = list(set(A))
A_lib = {}
for a in A:
    if a in A_lib:
        A_lib[a] += 1
    else:
        A_lib[a] = 1

if len(A) == 1:
    ans = A_set[0]
else:
    ans = 1
    for i in range(len(A_set)):
        if A_lib[A_set[i]] == 1:
            ans = max(ans, gcd_list(A_set[:i] + A_set[i + 1:]))

print(ans)

Submission status: Wrong Answer

Solution code:
# Atcoder uses python 3.4. So I use fractions.gcd instead of math.gcd in this code.

import fractions
from functools import reduce


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


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

if len(A) == 1:
    ans = A[0]
else:
    ans = 0
    for i in range(len(A)):
        ans = max(ans, gcd_list(A[:i] + A[i + 1:]))

print(ans)

Submission status: Wrong Answer

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

import fractions
import copy
from functools import reduce

#最大公約数を求める関数
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

l = []
sorted_A = sorted(A)
ind = 0
for i in range(1, len(A)):
    if gcd_list([sorted_A[0], sorted_A[i]]) == 1:
        ind = i
        break
for i in [0,ind]:
    sorted_A = sorted(A)
    del sorted_A[i]
    l.append(gcd_list(sorted_A))

print(max(l))

Submission status: Wrong Answer

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

import fractions
import copy
from functools import reduce

#最大公約数を求める関数
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

l = []
for i in range(2):
    sorted_A = sorted(A)
    del sorted_A[i]
    l.append(gcd_list(sorted_A))

print(max(l))

Submission status: Wrong Answer

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

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

gcd_list = []
if n == 2:
    print(max(a[0],a[1]))
    exit()
else:
    for i in range(n):
        for j in range(i+1,n):
            gcd_list.append(gcd(a[i],a[j]))

print(max(gcd_list))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import itertools

n = int(input())
alis = list(map(int,input().split()))
x =[]
for v in itertools.permutations(alis, 2):
	x.append(gcd(list(v)[0],list(v)[1]))

print(max(x))

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
  while y!=0:
    x, y = y, x%y
  return x

n = int(input())
A = list(map(int,input().split()))
min_v = min(A)

AA = A[:]
AA.remove(min(A))

for i in range(n):
  if A[i]%2==1:
    if min_v==A[i]:
      min_v = min(AA)
    A[i] = min_v
    break
print(gcd(min(A), max(A)))

Submission status: Wrong Answer

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

def divisor(x, m):
    ret = []
    for i in range(1, int(x**0.5)+1):
        if i >= m:
            return ret
            
        if x % i == 0:
            ret.append(i)
            compl = x//i
            if i*i != x and compl < m:
                ret.append(compl)
    return ret

divisor_dict = {}
m = 10 ** 10
for i in range(len(A)):
    if i==3:
        m = 0
        for key, val in divisor_dict.items():
            if val >= 2 and key > m:
                m = key
    
    div = divisor(A[i], m)
    for j in div:
        if j in divisor_dict:
            divisor_dict[j] += 1
        else:
            divisor_dict[j] = 1
        
max_val = 0
for key, val in divisor_dict.items():
    if val >= N-1 and key > max_val:
        max_val = key

print(max_val)

Submission status: Wrong Answer

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

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

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

m = []
for i in range(n-1):
    m.append(gcd(m_r[i], m_l[-i-1]))
print(max(m))

Submission status: Wrong Answer

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

def gcd(a, b):
    if a < b:
      a,b = b,a
    if b == 0:
        return a
    return gcd(b, a % b)
x = [0 for _ in range(n)]
y = [0 for _ in range(n)]
for i in range(1,n):
  x[i] = gcd(x[i-1],A[i-1])
for i in range(1,n):
  y[i] = gcd(y[i-1],A[i-1])
z = [gcd(x[i],y[i]) for i in range(n)]
print(max(z))

Submission status: Wrong Answer

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

num =A[0]
f = 0

for i in range(num,0,-1):
    f = 0
    for j in range(N):
        if A[j]%i !=0:
            f +=1
    if f<=1:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import functools
# from math import gcd
from fractions import gcd
 
def solve(N: int, A: "List[int]"):
    L = [0] * (N)
    R = [0] * (N)
 
    L[0] = A[0]
    for i in range(1, N):
        L[i] = gcd(L[i-1], A[i-1])
 
    R[N-1] = A[N-1]
    for i in reversed(range(0,N-1)):
        R[i] = gcd(R[i+1], A[i+1])
 
    # print(L)
    # print(R)
 
    ans = 0
    for i in range(N):
        ans = max(ans, gcd(L[i], R[i]))
 
    print(ans)
 
    return
 
 
# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import functools
from fractions import gcd


def solve(N: int, A: "List[int]"):
    L = [0] * (N+2)
    R = [0] * (N+2)

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

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


    print(L)
    print(R)

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

    print(ans)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

else:
        l=[a[0]]
        r=[a[n-1]]
        for i in range(1,n):
                l.append(fractions.gcd(l[-1],a[i-1]))
        for i in range(n-1,0,-1):
                        r.append(fractions.gcd(r[-1],a[i]))
        l[0]=1
        r=r[::-1]
        r[n-1]=1
        ans=0
        for k in range(n):
                g=fractions.gcd(l[k],r[k])
                if g>=ans:
                        ans=g
        print(l,r)
        print(ans)

Submission status: Wrong Answer

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

l=[a[0]]
r=[a[n-1]]

for i in range(1,n):
        l.append(fractions.gcd(l[-1],a[i-1]))
for i in range(n-1,0,-1):
        r.append(fractions.gcd(r[-1],a[i]))
l[0]=1
r=r[::-1]
r[n-1]=1
ans=0
for k in range(n):
        g=fractions.gcd(l[k],r[k])
        if g>=ans:
                ans=g

print(ans)

Submission status: Wrong Answer

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

for i in range(1,len(a)):
    if i>=2:
        s=max(fractions.gcd(a[i],t),fractions.gcd(a[i],s))
        t=s
    else:
        t=a[0]
        s=a[1]


print(s)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import functools
from fractions import gcd


def solve(N: int, A: "List[int]"):
    L = [0] * (N+2)
    R = [0] * (N+2)

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

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

    # print(L)
    # print(R)

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

    print(ans)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

b=1
if n==2:
        print(max(a[0],a[1]))
else:
        for i in range(len(a)):
                c=a[:i]+a[i+1:]
                for k in range(1,len(c)):
                        d=fractions.gcd(c[k-1],c[k])
                        if b<d:
                                b=d
        print(b)

Submission status: Wrong Answer

Solution code:
import fractions
import copy
from functools import reduce
N=int(input())
A=list(map(int,input().split()))
B=[]
c=0
def gcd(*n):
  return reduce(fractions.gcd, n)
for i in range(N):
  c=copy.deepcopy(A[i])
  A.pop(0)
  B.append(gcd(*A))
  A.insert(-1,c)
  c=0
print(max(B))

Submission status: Wrong Answer

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

def gcd(ls):
    ls = [i for i in ls if i > 0]
    while True:
        _min = min(ls)
        ls = [i % _min for i in ls if i % _min != 0]
        if len(ls) == 0:
            return _min

l_ls = []
r_ls = []
l_ls.append(0)
r_ls.append(0)
for i in range(N):
    l_ls.append(gcd([l_ls[i], a_ls[i]]))
    r_ls.append(gcd([r_ls[i], a_ls[-i-1]]))
r_ls = r_ls[::-1]
sum_ls = [gcd([l_ls[i], r_ls[i+1]]) for i in range(N)]
print(max(sum_ls))

Submission status: Wrong Answer

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

def gcd(ls):
    while True:
        _min = min(ls)
        ls = [i % _min for i in ls if i % _min != 0]
        if len(ls) == 0:
            return _min

if __name__ == "__main__":
    res = 1
    for i in range(N):
        if i == 0:
            res = max(res, gcd(a_ls[1:]))
        elif i == N - 1:
            res = max(res, gcd(a_ls[:-1]))
        else:
            res = max(res, gcd(a_ls[:i] + a_ls[i+1:]))
    print(res)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
top = [0]*(N+1)
bot = [0]*(N+1)
for i in range(N):
    top[i+1] = gcd(top[i],A[i])
    bot[-i-1]= gcd(bot[-i],A[-i])
# print(top,bot)
ans = bot[0]
for i in range(N-1):
    ans = max(ans,gcd(top[i],bot[i+1]))
print(ans)