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:
# -*- coding: utf-8 -*-
from sys import stdin
import math

N = stdin.readline().rstrip()
A = stdin.readline().rstrip().split(' ')
A_int = [int(s) for s in A]

min_index = A_int.index(min(A_int))
max = max(A_int)
A_int[min_index] = max

# print(A_int)

cdiv = max
# print(cdiv)
while cdiv > 1:
    # print('cdiv: ',end='')
    # print(cdiv)
    flag = False
    for num in A_int:
        if num % cdiv > 0:
            flag = True
            break
    if not flag:
        print(cdiv)
        break
    cdiv = math.ceil(cdiv / 2)

Submission status: Wrong Answer

Solution code:
### C

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

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

tmp = []
for i in range(1, N):
    tmp.append(gcd(A[0], A[i]))
    if i+1 < N:
        tmp.append(gcd(A[1], A[i+1]))

print(max(tmp))

Submission status: Wrong Answer

Solution code:
import fractions
import sys
from functools import reduce
maxn = 0

def f_gcd(aa,bb):
    global maxn
    chk = fractions.gcd(aa,bb)
    if maxn == 1 or maxn < chk:
        maxn = chk
    return maxn

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

for z in range(N-1):
    i = A[z]
    h = A[z+1]
    f_gcd(i,h)
print(maxn)

Submission status: Wrong Answer

Solution code:
import numpy as np

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義
#print(gcd(10, 20)) #出力値：10
def y(x):
    ans = -1
    for i in range(1,x+1):
        if a%i==0 or b%i==0:
            if len(A[A%i != 0])<2:
                ans = i
    return ans

N = int(input())
#A = np.array(list(map(lambda x: int(x),input().split())))
A = list(map(lambda x: int(x),input().split()))
A.sort()
A = np.array(A)
#ans = -1
#print(A)

if N==2:
    ans = max(A)
else:
    a = gcd(A[0],A[1])
    b = gcd(A[0],A[2])
    ans = y(max(a,b))


print(ans)

Submission status: Wrong Answer

Solution code:
import fractions as f

def calc_odd(n):
    if(n % 2 != 0):
        return True
    else:
        return False

N = int(input())
A = [int(i) for i in input().split()]
index_min = A.index(min(A))
index_max = A.index(max(A))
check_odd = list(map(calc_odd,A))
answer = 0

if(check_odd.count(True) == 1):
    index_odd = check_odd.index(True)
    del A[index_odd]
    answer = A[0]
    for i in range(1, N-1):
        answer = f.gcd(answer, A[i])
else:
    A[index_min] = A[index_max]
    answer = A[0]
    for i in range(1, N-1):
        answer = f.gcd(answer, A[i])
print(answer)

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

def gcd(a,b):
	if ( b==0 ):
		return a
	else:
		return (gcd(b, a%b))
		
def gcd_list(numbers):
	return reduce(gcd, numbers)
	
if N == 2:
	print(gcd(As[0],As[1]))
	exit()
	
gcds = []	
for i in range(0,N-1):
	gcds.append(gcd(As[i],As[i+1]))
	

i = gcds.index(min(gcds))
#print(gcds,i)

ans = -1
if i == len(gcds)-1:
	ans = N-1
elif gcds[i] == gcds[i+1]:
	ans = i+1
else:
	ans = 0
	
As.pop(ans)
#print(As)

print(gcd_list(As))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
 
n = int(input())
an = list(map(int, input().split()))
cpn = an
i = 0
j = 0
ans = 1
tmp = 0
 
 
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
 
 
for j in range(n):
    i = 0
    for i in range(n):
        if gcd_list(cpn) > ans:
            ans = gcd_list(cpn)
        tmp = cpn[i]
        cpn[i] = cpn[i] - (j + 1)
        if gcd_list(cpn) > ans:
            ans = gcd_list(cpn)
        cpn[i] = tmp
 
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
D=A[::]
E=A[::]
def gcd(GCD1,GCD2):
    x = min(GCD1,GCD2)
    y = max(GCD1,GCD2)
    if y%x == 0:
        return x
    else:
        return gcd(x,y%x)
def gcdlist(xlist):
    xlen=len(xlist)
    GCD=0
    for i in range(xlen-1):
        GCD=gcd(xlist[i],xlist[i+1])
        xlist[i+1]=GCD
    return GCD
if N == 2:
    a=max(A)
    b=gcd(A[0],A[1])
    print(max(a,b))
else:
    rem=[0,0]
    ans=0
    for i in range(N-1):
        if i == 0:
            if A[0] == 1:
                ans=gcdlist(A)
                break
            else:
                kari=gcd(A[0],A[1])
                if kari == 1:
                    B=A[::]
                    C=A[::]
                    del B[i]
                    del C[i+1]
                    ans=max(gcdlist(B),gcdlist(C))
                    break
                else:
                    A[1]=kari
        else:
            kari=gcd(A[i],A[i+1])
            if kari < A[i]:
                if kari != 1:
                    rem=[kari,i+1]
                else:
                    B=A[::]
                    C=A[::]
                    del B[i]
                    del C[i+1]
                    ans=max(gcdlist(B),gcdlist(C))
                    break
            else:
                A[i+1]=kari
    del D[1]
    ans2=gcdlist(D)
    if ans == 0:
        if rem[1] != 0:
            del E[rem[1]]
            ans=gcdlist(E)
        else:
            ans=gcdlist(E)
    print(max(ans,ans2))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
am = min(a)
for i in range(0,N):
        a[i] = a[i] % am
if (max(a)==0):
        print(am)
else:
        print(max(a))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from itertools import combinations
from functools import reduce
import random


N = int(input())
a_set = set(map(int, input().split()))

origina_gcd = reduce(gcd, a_set)

n_1_combis = combinations(a_set, len(a_set))

max_gcd = origina_gcd
for combi in n_1_combis:
    tmp_gcd = reduce(gcd, combi)
    max_gcd = max(max_gcd, tmp_gcd)
print(max_gcd)

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int, input().split()))
a.sort()
a.append(a[0])
temp = a[0]
for i in range(n):
    temp = gcd(temp, a[i]*a[i+1])
temp_ = a[1]
for i in range(2,n):
    temp_ = gcd(temp_, a[i])
if temp < temp_:
    ans = temp_
else:
    ans = temp
print(temp)

Submission status: Wrong Answer

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

n = int(input())
a = [int(i) for i in input().split()]
if len(a) == 2:
    print(gcd(a[0],a[1]))
else:
    minval = min(a)
    maxgcd = max(gcd(a[0],a[1]),gcd(a[1],a[2]),gcd(a[0],a[2]))
    maxgcd2 = maxgcd
    for index, value in enumerate(a):
        if value == minval:
            continue
        temp = gcd(minval, value)
        if temp <= maxgcd:
            maxgcd2 = maxgcd
            maxgcd = temp
    minval2 = float('inf')
    counter = 0
    if maxgcd2 == minval:
        for index, value in enumerate(a):
            if value == minval:
                counter += 1
                if counter == 2:
                    minval2 = maxgcd2
            if minval2 > value > minval:
                minval2 = value
        print(minval2)
    else:
    	print(maxgcd2)

Submission status: Wrong Answer

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


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


num = [A[i] for i in range(len(A))]

while(True):
    n = []
    for i in range(len(num)):
        a, b = num[i], num[(i + 1) % N]
        if b > a:
            a, b = b, a
        n.append(gcd(a, b))

    c = 0
    n.sort(reverse=True)
    t = n[0]
    for i in range(1, len(n)):
        if t != n[i]:
            c += 1

    if c <= 2:
        print(n[0])
        break

    num = [n[i] for i in range(len(n))]

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
lis.sort(reverse=True)
answer = 0
i = lis[1]
kake = 1
for i in range(n):
  kake *= lis[i]
for i in range(lis[i],0,-1):
  if kake % (i**(n-1)) == 0:
    answer = i
    break
print(answer)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
from copy import copy
def gcd_list(numbers):
    return reduce(gcd, numbers)
N = int(input())
A = [int(n) for n in input().split()]
B = copy(A)
B.remove(max(A))
ans = gcd_list(B)
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
div = make_divisors(max(A))
for d in div:
    for i in range(N):
        if A[i] % d != 0:
            A.pop(i)
            break
    else:
        continue
    break
    
print((max(gcd_list(A),ans)))

Submission status: Wrong Answer

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

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

x = 0
for i in range(1, N-1):
    if gcd(x, A[i]) <= gcd(x, A[i+1]):
        y = i
    else:
        y = i + 1

    if gcd(A[i], A[i+1]) <= gcd(A[x], A[y]):
        x = y

w = A[1 if x == 0 else 0]
for i in range(N):
    if i != x:
        w = gcd(w, A[i])

print(w)

Submission status: Wrong Answer

Solution code:
import functools
import fractions

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
    A = list(set(A))
    N = len(A) + 1
  else:
    # N = 3
    # A = [7,6,8]
    # N = 3
    # A = [12,15,18]
    N = 2
    A = [1000000000,1000000000]

  x = 0
  for i in range(N-1):
    if N == 1 : 
      tmp = 1000000000
    elif N == 2 :
      tmp = functools.reduce(fractions.gcd, A)
    else:
      tmp = functools.reduce(fractions.gcd, A[0:i]+A[i+1:])
    if tmp > x:
      x = tmp
  
  print(x)
  
main()

Submission status: Wrong Answer

Solution code:
import math
from sys import stdin
import numpy as np

n = int(stdin.readline().rstrip())
nums = np.sort(np.array(list(map(lambda x: int(x), stdin.readline().rstrip().split()))))

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

if len(nums) == 2:
    print(max(nums))
else:
    diff = min(np.diff(nums))
    n1, n2, n3 = np.sort(np.array([gcd(nums[-1],nums[-2]), gcd(nums[-2],nums[-3]), gcd(nums[-1],nums[-3])]))
    p = nums[3:]/n3
    p2 = list(map(lambda x: x.is_integer(), p))
    if False in p2:
        print(n1)
    else:
        print(n3)

Submission status: Wrong Answer

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

def spaceinput():
    return list(map(int,input().split(" ")))


N=int(input())
a=sorted(spaceinput())
#,reverse=True)


notrewrite=[-1]*N
rewrite=[-1]*N
best=[-1]*N

notrewrite[0]=rewrite[0]=best[0]=a[0]
for i in range(1,N):
    notrewrite[i]=gcd(notrewrite[i-1],a[i])
    rewrite[i]=notrewrite[i-1]
    best[i]=max([rewrite[i],gcd(a[i],best[i-1])])
    #print([notrewrite[i],rewrite[i]])


if N==2:
    print(max(a))
else:
    print(best[N-1])

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a % b)
N = int(input())
A = list(map(int, input().split()))
s = set()
m = []
for i in range(1,N):
  for j in range(i,N):
    m.append(gcd(A[i-1], A[j]))
print(max(m))

Submission status: Wrong Answer

Solution code:

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

n = int(input())
a = list(set(map(int, input().split())))
a.sort()
for i in range(len(a)):
    if a[i] % a[0] != 0:
        a.pop(i)
        break
ans = -1
for x in a:
    if ans == -1:
        ans = x
        continue
    ans = gcd(ans, x)
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

n = int(input())
a = [ int(x) for x in input().split() ]
_gcd = reduce(gcd, a)

b = [ int(x)//_gcd for x in a ]

t = b[0]
tt = b[0]
cnt = 0
for i in b[1:]:
    tt = min(tt, gcd(t, i))

for i in b[1:]:
    if (gcd(t, i) == tt):
        if cnt == 0:
            cnt += 1
        else:
            t = 1
    else:
        t = gcd(t, i)

ans = (_gcd * t)

t = b[1]
cnt = 0
tt = b[1]
for i in [b[0]] + b[2:]:
    tt = min(tt, gcd(t, i))

for i in [b[0]] + b[2:]:
    if (gcd(t, i) == tt):
        if cnt == 0:
            cnt += 1
        else:
            t = 1
    else:
        t = gcd(t, i)

ans = (_gcd * t)
ans = max(ans, (_gcd * t))

t = b[-1]
cnt = 0
tt = b[-1]
for i in  b[:-1]:
    tt = min(tt, gcd(t, i))

for i in b[:-1]:
    if (gcd(t, i) == tt):
        if cnt == 0:
            cnt += 1
        else:
            t = 1
    else:
        t = gcd(t, i)

ans = max(ans, (_gcd * t))

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)


if N == 2:
    print(max(A[0], A[1]))
    quit()
if N == 3:
    print(max(gcd(A[0], A[1]), gcd(A[0], A[2]), gcd(A[1], A[2])))
    quit()

ans_list = []
for i in range(N):
    ans = float('inf')
    for j in range(N-1):
        if i != j and i != j+1:
            ans = min(gcd(A[j], A[j+1]), ans)
    ans_list.append(ans)
    
print(max(ans_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
divisors = []
for j in range(2):
    for i in range(1, int(a[j]**0.5)+1):
        if a[j] % i == 0:
            divisors.append(i)
            if i != a[j] // i:
                divisors.append(a[j]//i)
divisors = list(set(divisors))
divisors.sort(reverse=True)
if n == 2:
    print(max(divisors))
else:
    judge = False
    for i in divisors:
        for j in range(n):
            if judge == True and a[j] % i !=0:
                judge = False
                break
            elif a[j] % i != 0:
                judge = True
        if judge == True:
            print(i)
            break

Submission status: Wrong Answer

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


def getNum(a, b):
    while(True):
        if a == b:
            return a
        a, b = max(a, b), min(a, b)
        a -= b

ans = max(AList)
AList = sorted(list(set(AList)))
if len(AList) >= 3:
    ansA = getNum(AList[0], AList[1])
    ansB = getNum(AList[1], AList[2])
    ansC = getNum(AList[2], AList[0])
    ansD, ansE = AList[0], AList[2]
    aFlag, bFlag, cFlag, dFlag, eFlag = True, True, True, True, True
    for num in AList:
        if num % ansA != 0:
            if not aFlag:
                ansA = 1
            aFlag = False
        if num % ansB != 0:
            if not bFlag:
                ansB = 1
            bFlag = False
        if num % ansC != 0:
            if not cFlag:
                ansC = 1
            cFlag = False
        if num % ansD != 0:
            if not dFlag:
                ansD = 1
            dFlag = False
        if num % ansE != 0:
            if not eFlag:
                ansE = 1
            eFlag = False
    ans = max(ansA, ansB, ansC, ansD, ansE)

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import copy

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

valueList = [a[0]]
maxList = []

for i in range(n):
  if i != 0:
    g = a[0]
  else:
    g = a[1]
  for j in range(i):
    g = gcd(g,a[j])
  valueList.append(g)
  g = valueList[i]
  for k in range(i+1, n):
    g = gcd(g, a[k])
  maxList.append(g)
    
print(max(maxList))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
err = 8
ma1 = [1]
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) 
for i in range(1,N):
    if a[0] > a[i]:
        f = gcd(a[0],a[i])
    else:
        f = gcd(a[i],a[0])
    for j in range(1,N):
        if a[j]%f != 0:
            err = err + 1
        if err == 10:
            break
    if err < 10:
        ma1.append(f)
arr = 8
ma2 = [1]

tmp = a[N-1]
a[N-1]=a[0]
a[0]=tmp


for i in range(1,N):
    if a[0] > a[i]:
        f = gcd(a[0],a[i])
    else:
        f = gcd(a[i],a[0])
    for j in range(1,N):
        if a[j]%f != 0:
            arr = arr + 1
        if arr == 10:
            break
    if arr < 10:
        ma2.append(f)



if max(ma2) > max(ma1):
    print(max(ma2))
else:
    print(max(ma1))

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()))

result = 1000000000
# a[0] = a[0]

for i in range(n):
    for j in range(i+1,n):
        if(a[i]>result):
            a[i]=result
        if(a[i] >= a[j]):
            result = gcd(a[i], a[j])
        elif(a[i] < a[j]):
           result = gcd(a[j], a[i])
        if (result == 1):
            break

print(result)

Submission status: Wrong Answer

Solution code:
import fractions
import math
from functools import reduce


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


def using_sqrt(limit):
    n = 0
    for k in range(2, limit+1):
        factor = 0

        # 2以外の偶数は素数ではないので無視する
        if k % 2 == 0 and k != 2:
            continue

        # 繰り返しの上限を対象の平方根にする
        for divisor in range(2, math.floor(math.sqrt(k))+1):
            if k % divisor == 0:
                factor += 1

        if factor == 0:
            n += 1

    return n


n = int(input())
li_input = list(map(int, input().split()))
li = list(set(li_input))
    
count = 0
max_gcd = 0

if len(li) == 1:
    max_gcd = li[0]
if len(li) == 2:
    max_gcd = max(li)
else:
    for i in range(len(li)):
        if count > 1:
            ret = 1
            break

        if li[i] <= max_gcd:
            continue
        a = using_sqrt(li[i])
        if using_sqrt(li[i] != 0):
            count += 1

        tmp = li[i]
        del li[i]
        tmp_gcd = gcd(*li)
        if max_gcd < tmp_gcd:
            max_gcd = tmp_gcd
        li.insert(0, tmp)

print(max_gcd)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
def main():
	N = int(input())
	A = input().split()
	A = [int(s) for s in A]

	base = -1
	for i, val in enumerate(A):
		if i == 0:
			base == val
			continue
		base = gcd(val, base)

	ans = base
	for i, val in enumerate(A):
		tmp = -1
		if ans >= val or ans % val != 0:
			break
		for j, vol in enumerate(A):
			if i == j:
				continue
 
			if tmp == -1:
				tmp = vol
				continue
 
			tmp = gcd(vol, tmp)
			if tmp <= ans:
				break
 
		if tmp > ans:
			ans = tmp
 
	print(ans)
 
 
 
def gcd(a, b):
	if a > b:
		a, b = b, a
		
	while a > 0:
		a, b = b % a, a
	return b
	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

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

r = 0
if N==1:
    print(A[0])
    exit()
else:
    r = gcd(A[0], A[1])
    if N==2:
        print(r)
        exit()
    else:
        for i in range(2, N):
            r = gcd(r,A[i])
B=[]
for i in A:
    B.append(i//r)
#print(B)
D={}
for i in range(N):
    p = B.pop(i)
    rr = gcd(B[0],B[1])
    if len(B)>2:
        for j in range(2,N-1):
            rr = gcd(rr,B[j])
    if rr not in D:
        D[rr]=1
    else:
        D[rr]+=1
    B.insert(i,p)
#print (D)
for i in D:
    if i ==N-1:
        print(r*i)
        exit()
print(r)

Submission status: Wrong Answer

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

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

r=[]
l=[]
resr = ai[0]
resl = ai[n-1]
r.append(ai[0])
l.append(ai[n-1])
for i in range(1,n):
	r.append(gcd(resr,ai[i]))
	l.append(gcd(resl,ai[n-1-i]))

#print(r)
#print(l)

resmax = 1
for i in range(n):
	if i == 0:
		res = l[n-1-1]
	elif i == n-1:
		res = r[n-1-1]
	else:
		res = gcd(r[i-1], l[n-1-i-1])
	#print(res)
	if res > resmax:
		resmax = res

print(int(resmax))

Submission status: Wrong Answer

Solution code:
from functools import reduce


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


N = int(input())
a_list = list(map(int, input().split()))
gcd_list = [a_list[-1]]
for idx in range(N - 2, 0, -1):
    gcd_list.append(gcd(gcd_list[N - 2 - idx], a_list[idx]))
max_gcd_a = gcd_list[-1]
gcd_list.append(1)
gcd_list.reverse()

for idx in range(1, N):
    if idx != 1:
        left_gcd = gcd(left_gcd, a_list[idx])
    else:
        left_gcd = a_list[0]
    if idx < N - 1:
        right_gcd = gcd_list[idx + 1]
    else:
        right_gcd = left_gcd

    gcd_a = gcd(left_gcd, right_gcd)
    if max_gcd_a < gcd_a:
        max_gcd_a = gcd_a

print(max_gcd_a)

# どれか１つを除いた時の最大公約数で最大のもの

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
A.sort()
nums = []
for i in range(1, N):
    nums.append(gcd(A[0], A[i]))
nums.sort()
if len(nums) > 1:
  print(nums[1])
else:
    print(nums[0])

Submission status: Wrong Answer

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

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
  
y = []
for i in range(n):
  y += (make_divisors(a[i]))

dub = set([x for x in y if y.count(x) > 1])
#print(y)
print(max(dub))

Submission status: Wrong Answer

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


N = int(input())
A = list(map(int, input().split()))
R = [0 for i in range(N - 1)]
L = [0 for i in range(N - 1)]
R[0] = A[0]
L[0] = A[-1]
for i in range(1, N - 1):
    R[i] = gcd(R[i-1], A[i])
for j in range(1, N - 1):
    L[j] = gcd(L[j-1], A[-1-i])
t = 0
for i in range(N - 2):
    t = max(t, gcd(R[i], L[i]))
print(max(t, R[N-2], L[N-2]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
N = int(input())
A = list(map(int, input().split()))
A.sort()

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(reverse=True)
    return divisors

if N == 2:
    print(max(A))
else:
    min = A[0]
    div = make_divisors(min)
    c = 0
    g = 1
    for n in div:
        for a in A:
            if a % n == 0:
                c += 1
        if c == N-1 or c == N:
            g = n
            break
        c = 0

    min2 = A[1]
    div2 = make_divisors(min2)
    c2 = 0
    g2 = 1
    for n in div:
        for a in A[2:]:
            if a % n == 0:
                c2 += 1
        if c2 == N-2:
            g2 = n
            break
    print(max(g, g2))

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


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


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v

def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N = int(input())
    A = sorted(li_input(), reverse=True)

    ans = 10**100
    ans_i = -1

    for i in range(len(A)-1):
        g = gcd(A[-1], A[i])

        if g < ans:
            ans = g
            ans_i = i

    print(max(
        -1,
        gcd_list(A[:ans_i] + A[ans_i+1:])
    ))


main()

Submission status: Wrong Answer

Solution code:
import fractions as f

def calc_odd(n):
    if(n % 2 != 0):
        return True
    else:
        return False

N = int(input())
A = [int(i) for i in input().split()]
index_min = A.index(min(A))
index_max = A.index(max(A))
check_odd = list(map(calc_odd,A))
answer = 0

if(check_odd.count(True) == 1):
    index_odd = check_odd.index(True)
    del A[index_odd]
    answer = A[0]
    for i in range(1, N-1):
        answer = f.gcd(answer, A[i])
else:
    del A[index_min]
    answer = A[0]
    for i in range(1, N-1):
        answer = f.gcd(answer, A[i])
print(answer)

Submission status: Wrong Answer

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

n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()
result = 0
for i in range(n):
    r = a_list[0]
    for j in range(n):
        if i == j: continue
        r = gcd(a_list[j], r)
    if r > result: result  = r
print(result)

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
As = list(map(int, input().split()))
As.sort()
ans = 1
odd = 0
even = 0
for a in As:
    if a%2 == 0:
        even += 1
    else:
        odd += 1
if even >= 2 and odd >= 2:
    ans = 1
elif even == 1:
    c = 0
    for b in As:
        if b % 2 == 1:
            c = b
            break
    for a in As:
        if a % 2 == 1:
            c = fractions.gcd(c, a)
    ans = c
elif odd == 1:
    c = 0
    for b in As:
        if b % 2 == 0:
            c = b
            break
    for a in As:
        if a % 2 == 0:
            c = fractions.gcd(c, a)
    ans = c
    
else:
    
    for i in range(N):
        flag = True
        if i == 0:
            a = As[1]
        else:
            a = As[0]
        for j in range(N):
            if j != i:
                a = fractions.gcd(a, As[j])
                if a <= ans:
                    flag = False
                    break
        if flag:  
            ans = a
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
import itertools
n = int(input())
x = list(map(int,input().split()))
p = list(itertools.combinations(x,2))
ar = 0
for n in range(0,len(p)):
    ar=max(fractions.gcd(p[n][0],p[n][1]),ar)
#print(len(p))
print((ar))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
#def gcd(numbers):return reduce(gcd_, numbers)
I=lambda:list(map(int,input().split()))

N=int(input())
A=I()

g={gcd(A[0],A[1]),A[1],A[0]}
for i in range(2,N):
  g={gcd(k,A[i]) for k in g}
print(max(g))

Submission status: Wrong Answer

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

def gcd_list(a, n):
    b = np.array([1]*(n-1))
    for i in range(n-1):
        b[i] = fractions.gcd(a[n-1], a[i])
    b[b.argmin()] = b[b.argmax()]
    return reduce(fractions.gcd, b)

n = int(input())
a = [int(i) for i in input().split()]
print(gcd_list(a, n))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
A=list(set(A))
maxi=10**9
allyp=[]
for i in range(len(A)):
    divesor=[]
    a=A[i]**0.5+1
    for j in range(1,int(a)+1):
        if A[i]%j==0:
            divesor.append(j)
            divesor.append(int(A[i]/j))
    A[i]=divesor
    allyp+=A[i]
    if maxi>int(max(A[i])):
        maxi=int(max(A[i]))
allyp=list(set(allyp))
allyp.sort(reverse=True)
for i in allyp:
    flag=1
    for j in range(len(A)):
        if i not in A[j]:
            flag-=1
    if flag >=0:
        print(int(i))
        break

Submission status: Wrong Answer

Solution code:
def c():
    ans = 0
    N = long(raw_input())
    A = raw_input().split()
    A.sort(key=long, reverse=True)
    for i in range(N):
        for j in range(i+1, N):
            C = long(A[i])
            D = long(A[j])
            #prlong "C:{}, D:{}".format(C,D)
            if C == D:
                g = C
            elif C > D:
                g = gcd(C, D)
            else:
                g = gcd(D, C)
            if g > ans:
                ans = g
    print ans

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

def main():
    c()
	
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 27 20:01:24 2019
ABC125C
@author: maezawa
"""

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

n = int(input())
a = list(map(int, input().split()))
a.sort()
a0 = a[0]
mingcd = a0
min0 = 0
for i in range(1,n):
    gcdi = gcd(a0, a[i])
    if gcdi < mingcd:
        mingcd = gcdi
        min0 = i
 
a1 = a[-1]
mingcd1 = a1
min1 = n-1
for i in range(n-1):
    gcdi = gcd(a1, a[i])
    if gcdi < mingcd1:
        mingcd1 = gcdi
        min1 = i
        
a2 = a[n//2]
mingcd2 = a2
min2 = n//2
for i in range(n-1):
    gcdi = gcd(a2, a[i])
    if gcdi < mingcd2:
        mingcd2 = gcdi
        min2 = i

nend = n-1

if mingcd < mingcd1 and mingcd < mingcd2:
    a.pop(min0)
elif mingcd1 < mingcd and mingcd1 < mingcd2:
    a.pop(min1)
elif mingcd2 < mingcd and mingcd2 < mingcd1:
    a.pop(min2)

elif min0 == min1:
    a.pop(min0)
elif min0 == min2:
    a.pop(min0)
elif min1 == min2:
    a.pop(min1)
else:
    nend = n


a0 = a[0]
maxgcd = a0
for i in range(1,nend):
    gcdi = gcd(a0,a[i])
    if gcdi < maxgcd:
        maxgcd = gcdi
print(maxgcd)