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:
N=int(input())
A=[int(i) for i in input().split()]
def GCD(x,y):
	if x>y:
		a=x
		b=y
	else:
		a=y
		b=x
	while(True):
		c=a%b
		if c==0:
			return b
		else:
			a,b=b,c
 

if N==2:
	print(max(A))
else:
	B=[]
	a0=A[0]
	for aa in A[1:]:
		B.append(GCD(aa,a0))
	gomikamo=B.index(min(B))+1
	g0=A[1]
	for i in range(1,N):
		g0=GCD(A[i],g0)
	del A[gomikamo]
	g1=A[0]
	for i in range(N-1):
		g1=GCD(A[i],g1)
	print(max(g0,g1))

Submission status: Wrong Answer

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

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

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

p1 = gcd(a[0],a[1])
p2 = gcd(a[1],a[2])
p3 = gcd(a[0],a[2])

p = [p1,p2,p3]

f = 0
tmp = a[0]
res1,res2,res3 = p1,p2,p3

for i in range(n):
    if gcd(tmp,a[i])==1:
        f += 1
    else:
        tmp = gcd(tmp,a[i])

    if i>=3:
        res1 = gcd(res1,a[i])
        res2 = gcd(res2,a[i])
        res3 = gcd(res3,a[i])

    if f > 1:
        print(tmp)
        break
else:
    if res1==res2:
        print(res1)
    elif res2==res3:
        print(res2)
    else:
        print(res3)
    #print(max(tmp,res1,res2,res3))

Submission status: Wrong Answer

Solution code:
# coding=utf-8


def solve_gcd_from_list(number_list):
    if len(number_list) == 1:
        return number_list[0]

    if len(number_list) == 2:
        return solve_gcd(number_list[0], number_list[1])
    mid = len(number_list) // 2
    return solve_gcd(solve_gcd_from_list(number_list[:mid]), solve_gcd_from_list(number_list[mid:]))


def solve_gcd(number1, number2):
    if number1 == number2:
        return number1

    if number1 < number2:
        number1, number2 = number2, number1

    if number1 % number2 == 0:
        return number2

    return solve_gcd(number2, number1 % number2)


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    A.sort()
    num = A.pop(0)
    gcd_list = [solve_gcd(num, n) for n in A]
    rest_gcd = solve_gcd_from_list(A)

    if all([gcd_list[0] == n for n in gcd_list]):
        num2 = gcd_list[0]
        print(max(num2, rest_gcd))

    else:
        gcd_list.sort()
        print(max(gcd_list[1], rest_gcd))

Submission status: Wrong Answer

Solution code:
import copy

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


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


lo, hi = 1, 10 ** 9 + 1
while abs(hi - lo) > 1:
    X = copy.deepcopy(A)
    m = (hi + lo) // 2

    skipped = False
    while len(X) > 1:
        a, b = X.pop(), X.pop()
        GCD = gcd(a, b)
        if GCD < m:
            if skipped is False:
                skipped = True
                X.append(a)
                continue
            else:
                hi = m
                break
        X.append(GCD)
    else:
        if X[0] >= m:
            lo = m
        else:
            hi = m

print(lo)

Submission status: Wrong Answer

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

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

cm = np.prod(A)
max_gcd = 0
for i in range(len(A)):
    Am = A.copy()
    Am[i] = cm
    gcd = reduce(fractions.gcd, Am)
    if gcd > max_gcd:
        max_gcd = gcd
print(max_gcd)

Submission status: Wrong Answer

Solution code:
def make_divisors(arg):
    divisors = set()
    for i in range(1, int(arg**0.5)+1):
        if arg % i == 0:
            divisors.add(i)
            divisors.add(arg//i)

    return divisors


n = int(input())
a = list(map(int, input().split()))
a.sort()
a0y = make_divisors(a[0])
a1y = make_divisors(a[1])
common = a0y & a1y
one = a0y ^ a1y
last = 0
lastdev = set()
tmp = set()
for e in a[2:]:
    if e == last:
        tmp = lastdev
    else:
        tmp = make_divisors(e)
    common = tmp & common
    one = (one & tmp) | (common - tmp)
    last = e
    lastdev = tmp

print(max(common.union(one)))

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

ls = [[gcd(A[i], A[j]) for j in range(N)] for i in range(N)]
ls = [sorted(row) for row in ls]
result = 0

for l in ls:
    if l[N-2] > result:
        result = l[N-2]

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
A.sort()
def find(inte):
    re = []
    for i in range(1,int(inte**0.5)+1):
        if inte%i==0:
            re.append(i)
            if i != inte/i:
                re.append(int(inte/i))
    return set(re)
if n==2:
    intersection = find(A[0]) & find(A[1]) 
    print(max(intersection))
else:
    a1 = find(A[0])
    a2 = find(A[1])
    a3 = find(A[2])
    max1 = max(a1&a2)
    max2 = max(a1&a3)
    max3 = max(a2&a3)
    print(max(max1,max2,max3))

Submission status: Wrong Answer

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


def calc_gcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def get_custum(xlist):
    prev = None
    gcm_list = []
    for a in xlist:
        if prev is None:
            gcm_list.append(a)
            prev = a
            continue
        ret = calc_gcm(a, prev)
        gcm_list.append(ret)
        prev = ret

    for boundary, gcm in enumerate(gcm_list):
        if gcm == gcm_list[-1]:
            break

    gcm_1 = None
    for i, a in enumerate(xlist):
        if i == boundary - 1:
            continue
        if gcm_1 is None:
            gcm_1 = a
            continue
        gcm_1 = calc_gcm(a, gcm_1)

    gcm_2 = None
    for i, a in enumerate(xlist):
        if i == boundary:
            continue
        if gcm_2 is None:
            gcm_2 = a
            continue
        gcm_2 = calc_gcm(a, gcm_2)

    return max(gcm_1, gcm_2)

ret1 = get_custum(alist)
alist.reverse()
ret2 = get_custum(alist)

print(max(ret1, ret2))

Submission status: Wrong Answer

Solution code:
import math
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
list = [gcd_list(A)]
A = sorted(A)

G = len([i for i in A if i % 2 == 0])
K = len([i for i in A if i % 2 == 1])
GG = [i for i in A if i % 2 == 0]
KK = [i for i in A if i % 2 == 1]
if abs(G - K) > 0 and G > 0 and K > 0:
  temp = A[:]
  temp.remove(max(KK))
  temp.append(max(GG))
  list.append(gcd_list(temp))

  temp = A[:]
  temp.remove(max(GG))
  temp.append(max(KK))
  list.append(gcd_list(temp))

else:
  temp = A[:]
  temp[0] = temp[N - 1]
  list.append(gcd_list(temp))
  
  temp = A[:]
  temp[N - 1 - 1] = temp[N - 1]
  list.append(gcd_list(temp))


#print(list)
print(max(list))

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

    G = []

    for i in range(N):
        A_ = A[:i] + A[i+1:]
        G.append(gcd_list(A_))

        if len(set(G)) == 3:
            print(sorted(list(G))[1])
            return
    
    G = list(G)

    if len(G) == 1:
        print(G[0])
    else:
        print(max(G))


main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import sys
sys.setrecursionlimit(1000000)
ans=0

def gcd(x,y):
    x,y=max(abs(x),abs(y)),min(abs(x),abs(y))
    if x%y==0:
        return y
    while x%y!=0:
        x,y=y,x%y
    return y

n=int(input())

g=[]

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


pre=a[0]
for i in range(1,n):
    x,y=pre,a[i]
    g.append(gcd(x,y))
    pre=y
g.append(gcd(y,a[0]))
#print(g)
g.sort(reverse=True)

g.pop()
g.pop()
if len(g)==1:
    g1=g[0]



for i in range(1,n-2):
    if i==1:
        pre=g[0]
    x,y=pre,g[i]
    g1=gcd(x,y)
    pre=y
if len(a)==2:
    g1=gcd(a[0],a[1])
print(g1)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

gcd_num = a_list[0]
for a in a_list[1:]:
    gcd_num = gcd(gcd_num, a)

b_list = []

for a in a_list:
    b_list.append(a // gcd_num)

first = False
gcd_b = b_list[0]
for b in b_list[1:]:
    tmp = gcd(gcd_b, b)
    if tmp == 1:
        if not first:
            first = True
            gcd_b = gcd_b
        else:
            gcd_b = 1
            break
    else:
        gcd_b = tmp

gcd_b2 = b_list[-1]
first = False
for b in list(reversed(b_list))[1:]:
    tmp = gcd(gcd_b2, b)
    if tmp == 1:
        if not first:
            first = True
            gcd_b2 = gcd_b2
        else:
            gcd_b2 = 1
            break
    else:
        gcd_b2 = tmp

first = False
gcd_b3 = b_list[1]
b_list.append(b_list[0])

for i, b in enumerate(b_list[1:]):
    tmp = gcd(gcd_b3, b)
    if tmp == 1:
        if not first:
            first = True
            gcd_b3 = gcd_b3
        else:
            gcd_b3 = 1
            break
    else:
        gcd_b3 = tmp

print(gcd_num * max(gcd_b, gcd_b2, gcd_b3))

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

ans0 = A[0]
ans1 = A[-1]
for i in range(N//2-1):
    ans0 = min(gcd(A[i], A[i+1]), ans0)
for i in range(N//2, N-1):
    ans1 = min(gcd(A[i], A[i+1]), ans1)
if ans0 < ans1:
    cur = 1
    for i in range(N//2-1):
        cur *= A[i]
    A = [cur] + A[N//2:]
elif ans0 > ans1:
    cur = 1
    for i in range(N // 2, N):
        cur *= A[i]
    A = [cur] + A[:N // 2]
elif ans0 == ans1:
    print(ans0)
    quit()

ans = float('inf')
for i in range(len(A)-1):
    ans = min(ans, gcd(A[i], A[i+1]))

print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(s):
    a=0
    b=0
    temp=100000000000
    for i in range(len(s)):
        if i==0:
            a=s[i]
            b=s[i+1]
        else:
            b=s[i]
        if a<b:
            temp=a
            a=b
            b=temp
        while temp!=0:
            temp=a%b
            a=b
            b=temp
    return(a)

n=int(input())

v=[]
line=input().split()

for i in range(n):
    v.append(int(line[i]))

gcd_list=[0]*n

for i in range(n):
    s=[]
    for j in range(n):
        x=v[j]
        s.append(x)
    if i!=n-1:
        x=v[i+1]
        s.pop(i)
        s.append(x)
        gcd_list.append(gcd(s))
    else:
        x=v[i-1]
        s.pop(i)
        s.append(x)
        gcd_list.append(gcd(s))

print(max(gcd_list))

Submission status: Wrong Answer

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

n = int(input())
if n==1:
  a = int(input())
  print(a)
  sys.exit()
  
a = list(map(int, input().split()))

sort_a = sorted(a)
max_a = sort_a.pop()

if max_a==0:
  print(0)

else:
  max_gcd=0
  for k in range(n-1):
    for i in sort_a:
      temp = gcd(max_a, i)
      if temp>max_gcd:
        max_gcd = temp
    max_a = sort_a.pop()
  
  print(max_gcd)

Submission status: Wrong Answer

Solution code:
def a():
    N = raw_input().split(" ")
    A = int(N[0])
    B = int(N[1])
    T = int(N[2])

    print T / A * B

def b():
    sum = 0
    N = int(raw_input())
    V = raw_input().split()
    C = raw_input().split()
    for i in range(N):
        value = int(V[i]) - int(C[i])
        if value > 0:
            sum = sum + value
    print sum

def c():
    ans = 0
    N = int(raw_input())
    A = raw_input().split()
    for i in range(N):
        for j in range(i+1, N):
            C = int(A[i])
            D = int(A[j])
            #print "C:{}, D:{}".format(C,D)
            if 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:
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,a,b=int(input()),list(map(int,input().split())),[]
if n==2:print(gcd(a[0],a[1]))
elif n==3:print(max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])))
else:
  no,mi=a[0],a[0]
  for i in range(1,n):
    s=gcd(no,a[i])
    if s!=no:
      no=max(s,mi)
      mi=gcd(s,mi)
  on,im=a[-1],a[-1]
  for i in range(1,n):
    s=gcd(on,a[n-i])
    if s!=on:
      on=max(s,im)
      im=gcd(s,im)
  print(max(no,on))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
s=[[0]for _ in range(n)]
#print(s)
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

l.sort()
ans=1

b=l[1]
bl=make_divisors(b)
for i in bl:
    check=True
    for j in range(n):
        if l[j]%i!=0:
            check=False
            break
    if check:
        ans=max(ans,i)
        break
a=min(l)
al=make_divisors(a)
#print(al)
for i in al:
    cnt=0
    for j in range(n):
        if l[j]%i!=0:
            cnt+=1
        if cnt>1:
            break
    if cnt==0 or cnt==1:
        ans=max(ans,i)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

n = int(input())
a_l =[int(i) for i in input().split()]
a_l.append(a_l[n-2])
max_gcd=reduce(fractions.gcd, a_l)
for i in range(n):
    tmp = a_l[i]
    a_l[i] = a_l[i+1]
    max_gcd=max(max_gcd,reduce(fractions.gcd, a_l))
    a_l[i] = tmp
print(max_gcd)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

lowest = 1
g1 = As[0]
for i in range(1, N):
    new_g = gcd(As[i], g1)
    if new_g != g1:
        lowest = i
    g1 = new_g

g2 = As[0]
for i in range(1, N):
    if i == lowest:
        continue
    g2 = gcd(As[i], g2)

g3 = As[1]
for i in range(2, N):
    g3 = gcd(As[i], g3)

print(max(g2, g3))

Submission status: Wrong Answer

Solution code:

n = int(input())

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


from functools import lru_cache
import sys
if n == 2:
    print(max(a))
    sys.exit()


@lru_cache(maxsize=100000)
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


def gcd_list(li):
    if len(li) == 1:
        return li[0]
    g = gcd(li[0], li[1])
    for i in range(2, len(li)):
        g = gcd(g, li[i])
    return g


def gcd_list_2(li):
    g = gcd(li[0], li[1])
    if g == 1:
        return max(gcd_list([li[0]] + li[2:]), gcd_list(li[1:]))
    for i in range(2, n):
        if gcd(g, li[i]) == 1:
            return gcd_list(li[:i] + li[i + 1:])
        else:
            g = gcd(g, li[i])
    return g


def max_gcd(a):
    g = gcd_list(a)
    a = [a[i]//g for i in range(n)]
    m = gcd_list_2(a)
    print(g * m)


max_gcd(a)

Submission status: Wrong Answer

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

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
    
tmp = []
tmp.append(a[0])
if n==1:
    print(a[0])
    exit(0)
else:
    element = gcd(a[0], a[1])
    tmp.append(element)
    if n==2:
        print(element)
        exit(0)
    else:
        for i in range(2,n):
            element=gcd(element,a[i])
            print(element)
            tmp.append(element)
GCD = 0
ans = 0
gcd_tmptmp=a[n-1]
for i in range(n):
    ans = tmp[n-i-2]
    x=n-i-3
    if(x<0):
        gcd_tmp = gcd_tmptmp
    else:
        gcd_tmp=gcd(tmp[n-i-3],gcd_tmptmp)

    if(gcd_tmp > GCD):
        GCD = gcd_tmp
    gcd_tmptmp = gcd(gcd_tmptmp,a[n-i-2])
print(GCD)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
GA=[a[0]]
GB=[a[n-1]]
G=gcd(a[0],a[1])
GA.append(G)
for i in range(2,n-1):
  G=gcd(G,a[i])
  GA.append(G)
G=gcd(a[n-1],a[n-2])
GB.append(G)
for j in range(n-3,0,-1):
  G=gcd(G,a[j])
  GB.append(G)
GB.reverse()
ans=[]
for i in range(len(GA)-1):
  ans.append(gcd(GA[i],GB[i+1]))
ans.append(GA[len(GA)-1])
ans.append(GB[0])
print(max(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())

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


a=sorted(a)

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



l=1
r=10**9
a.sort()
ans=[a[0],a[1]]
k=-1
nexts=0
stock=0


ans=gcd(a[0],a[1])
for j in range(2,len(a)):
    s=gcd(ans,a[j])
    if(s<ans and stock==0):
        stock+=1
        nexts=s
    elif(s<ans and stock==1):
        if(s==nexts):
            stock-=1
            ans=s
        else:
            stock+=1
            ans=max(s,nexts)
ans1=ans

ans=a[0]
for j in range(2,len(a)):
    ans=gcd(ans,a[j])
ans2=ans
ans=a[1]
for j in range(2,len(a)):
    ans=gcd(ans,a[j])

ans3=ans

    

print(max([ans1,ans2,ans3]))

Submission status: Wrong Answer

Solution code:
n = int(input())

a = [int(s) for s in input().split()]


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

    return y


max_ans = 1
f_gcd = a[0]
for i in range(1, n-1):
    f_gcd = gcd(f_gcd, a[i-1])
    b_gcd = a[i+1]
    for j in a[i+1:]:
        b_gcd = gcd(b_gcd, j)

    ans = gcd(f_gcd, b_gcd)

    if ans > max_ans:
        max_ans = ans

print(max_ans)

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8:
import fractions
from functools import reduce


def main():
    N = int(input())
    A = [int(ele) for ele in input().split()]

    # ans = tle_solver(A)
    ans = ac_solver(A)
    print(ans)


def ac_solver(A):
    a_min = min(A)
    a_min_divisors = sorted(make_divisors(a_min), reverse=True)
    kouho = []
    for d in a_min_divisors:
        ct = 0
        for a in A:
            if a % d != 0:
                ct += 1

            if 2 < ct:
                break

        if ct == 1 or ct == 0:
            kouho.append(d)

    return max(kouho)


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


def tle_solver(A):
    gcds = [-1] * len(A)
    for idx in range(len(A)):
        tmp = A[:idx] + A[idx+1:]
        gcds[idx] = gcd(*tmp)

    return max(gcds)


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

N = input()
A = np.array([int(x) for x in input().split(" ")])

div_dict = {}

for num in np.sort(A)[:2]:
  for div in range(1, num//2+2):
    if num%div == 0:
      if div in div_dict:
        div_dict[div] = 1
      else:
        div_dict[div] = 0

for num in np.sort(A)[2:]:
  dels = []
  for div, f in div_dict.items():
    if num%div > 0:
      if f == 0:
        dels.append(div)
      else:
        div_dict[f] = 0
  for k in dels:
	  del div_dict[k]

ans = []
for k in div_dict.keys():
  ans.append(k)

print(np.array(ans).max())

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce



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

N = int(input())
A = [int(x) for x in input().split()]
list = []
max = 1

for x in range(N):

    for y in range(N):
        if x != y:
            list.append(A[y])

    gcd = gcd_list(list)
    if gcd > max:
        max = gcd

print(max)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
w=sorted(a)
ans=1
end=False

flag=False
for h in range(n):
    if a[h]%w[0]!=0 and flag==True:
       break
    if a[h]%w[0]!=0:
        flag=True
    if h==n-1:
        ans=w[0]
        end=True

y=1000000001
for i in range(n):
    y=min(y,-(-a[i]//2))
    



for i in reversed(range(2,y+1)):
    flag=False
    if end==True:
        break
    for h in range(n):
        if a[h]%i!=0 and flag==True:
            break
        if a[h]%i!=0:
            flag=True
        if h==n-1:
            ans=i
            end=True
            break


print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
m=0
for i in range(max(A),0,-2):
    count=0
    for a in A:
        if a%i==0:count+=1
        if count==2:
            print(i)
            exit()

Submission status: Wrong Answer

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

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

if N == 2:
  print(max(A))
else:
  G = gcd(A[0], A[1])
  H = gcd(A[1], A[2])
  I = gcd(A[2], A[0])

  print(max(G, H, I))

Submission status: Wrong Answer

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


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


def expect(a, b):
    return gcd(a, b)


if A.count(0) >= 2:
    print(0)
    sys.exit()
if N == 2:
    print(max(A))
    sys.exit()

new_A = []
ans_box = []

temp = gcd(A[0], A[1])
for j in range(N):
    temp = gcd(temp, A[j])

for j in range(1, N+1):
    if j == N:
        temp = gcd(A[0], A[1])
        for k in range(N-1):
            temp = gcd(temp, A[k])
        ans = temp
        break
    if gcd(A[j], A[j-1]) == temp and gcd(A[j], A[j+1]) == temp:
        A[j] = A[j+1]
        temp = gcd(A[0], A[1])
        for k in range(N):
            temp = gcd(temp, A[k])
        ans = temp
        break
    if gcd(A[j], A[j-1]) == temp and gcd(A[j], A[j+1]) != temp:
        temp = gcd(A[1], A[2])
        for k in range(1, N):
            temp = gcd(temp, A[k])
        ans = temp
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input()) 
def gcd(m, n):
  a = max(m,n)
  b = min(m,n)
  if a%b==0:
    return b
  while not a % b == 0:
      a, b = b, a % b
  return b

arr = [int(item) for item in input().split()]
if N==2:
  print(max(arr))
else:
  ans = gcd(arr[1], arr[2])
  base = arr[0]
  for i in range(2, N):
    ans = max(ans, gcd(base, arr[i]))
    base = gcd(base, arr[i-1])
  print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions
 
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
 
INF = 10 ** 9
res = []
if N == 1:
    print(INF)
    exit()
else:
    for i in range(N):
        B = A[:]
        del B[i]
        B.sort()

        if len(B) != 1:
            gcd_num = fractions.gcd(B[0], B[1])
        else:
            gcd_num = B[0]

        res.append(gcd_num)

print(max(res))

Submission status: Wrong Answer

Solution code:
import fractions
import itertools
import numpy as np

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

gcds=[]

for x, y in itertools.combinations(A,2):
  gcds.append(fractions.gcd(x,y))
  
max_gcd=1
A=np.array(A)
gcds=sorted(gcds)
for gcd in gcds:
  tmp=A%gcd
  if len(tmp[tmp!=0])<2:
    max_gcd=gcd
    
print(gcd)

Submission status: Wrong Answer

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

def gcd(a, b):

    c = min(a, b)
    d = max(a, b)
    r = 0    
    while True:
        r = d % c
        if r == 0:
            break
        d = c
        c = r

    return c

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]


    n = int(lines[0])
    a = [int(e) for e in lines[1].split(" ")]

    return (n, a)


def solve(n, a):


    result = 1

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



    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
num_list = list(map(int, input().split()))
num_list.sort()
num_list.reverse()
answer_list = []
max_num = 0
flag = False
for i in range(num_list[-1], 0, -1):
    if flag and count < 2:
        break
    else:
        flag = True
        count = 0
        max_num = i

    for num in num_list:
        if num / max_num < 1 or num % max_num != 0:
            count += 1
            if count > 1:
                break
print(max_num)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
  
n = int(input())
arr = list(map(int,input().split(" ")))
list.sort(arr)

memoa = [None for i in range(n)]
memoa[0] = arr[0]
memob = [None for i in range(n)]
memob[0] = arr[-1]
for i in range(1,n):
  memoa[i] = gcd(memoa[i-1],arr[i])
  memob[i] = gcd(memob[i-1],arr[i])

m = 0
for i in range(len(arr)):
  if i is 0:
    ans = memob[n-2]
  elif i is n-1:
    ans = memoa[n-2]
  else:
    ans = gcd(memoa[i-1],memob[n-i-2])
      
  m = max(m, ans)
print(m)

Submission status: Wrong Answer

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

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

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

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

A.sort()
B=A+[A[0]]
min1,min2=float('inf'),float('inf')
min1_idx,min2_idx=0,1
for i in range(n):
    g=gcd(B[i],B[i+1])
    if g<min1:
        min2=min1
        min2_idx=min1_idx
        min1=g
        min1_idx=i
    elif g<min2:
        min2=g
        min2_idx=i
    #print(g,min1,min2)
    #print(i,min1_idx,min2_idx)
#print(min1_idx,min2_idx)
if abs(min1_idx-min2_idx)==1:
    idx=max(min1_idx,min2_idx)
else:
    idx=0
#print(idx)
del A[idx]
#print(A)
ans=gcd(A[0],A[1])
for i in range(2,n-2):
    ans=gcd(ans,A[i])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import fractions
from functools import reduce
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
n = ni()
a = nl()
minn = 10 ** 9 + 1
idx = -1
for i in range(n - 1):
    if minn >= fractions.gcd(a[i], a[i + 1]):
        minn = fractions.gcd(a[i], a[i + 1])
        idx = i
if idx == 0:
    if n != 2:
        print(max(gcd_list(a[1:]), gcd_list(a[:1] + a[2:])))
    else:
        print(max(a[0], a[1]))
elif idx == n - 2:
    print(max(gcd_list(a[:n - 1]), gcd_list(a[:n - 2] + a[n - 1:])))
else:
    print(max(gcd_list(a[:idx] + a[idx + 1:]), gcd_list(a[:idx + 1] + a[idx + 2:])))

Submission status: Wrong Answer

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

from fractions import gcd

num_list = [0] * n

for i in range(n - 1):
    for j in range(i+1, n):
        num_list[i] = max(num_list[i], gcd(a[i], a[j]))
        num_list[j] = max(num_list[j], gcd(a[i], a[j]))

print(max(num_list))

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()))
a.sort()

g_left = [a[0]]
g_right = [a[N - 1]]

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

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

g_right.reverse()

# print(a)
# print(g_left)
# print(g_right)

g = 1
for i in range(1, N - 1):
    # print(g_left[i], g_right[i + 2])
    g = max(g, gcd(g_left[i], g_right[i + 2]))
g = max(g, g_left[N - 1])
g = max(g, g_right[1])

print(g)

Submission status: Wrong Answer

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

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



if N == 2:
    print(max(a))
else:

    small = 1
    x = a[0]
    x2 = a[1]
    big = N - 2
    y = a[-1]
    i, j, k = gcd(x, x2), gcd(x, y), gcd(x2, y)
    if i <= k and j <= k:
        x = a[1]
        a[1], a[0] = a[0], a[1]
    elif k <= i and j <= i:
        y = a[1]
        a[1], a[-1] = a[-1], a[1]
    while small < big:
        if gcd(a[small], x) < gcd(a[big], y):
            y = gcd(a[big], y)
            big -= 1
        else:
            x = gcd(a[big], x)
            small += 1

    print(gcd(x, y))