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 = list(map(int, input().split()))

num = 1


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


for i in range(N):
    if A[i]%num == 0:
        continue
    B = A[:]
    B.pop(i)
    gcd1 = int(B[0])

    for j in range(1, N - 1):
        gcd1 = gcd(gcd1, B[j])

    if num < gcd1:
        num = gcd1

print(num)

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):
        b = a[:i] + a[i+1:] 
        for j in range(n-2):
            tmp = gcd(b[j], b[j+1])
            if tmp > result:
                result = tmp

    for j in range(n-1):
        tmp = gcd(a[j], a[j+1])
        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())
A = list(map(int, input().split()))

divs = []
def divisors(num):
  divisors = []
  # print(int(num**0.5))
  for i in range(1, int(num**0.5) + 1):
    if num % i == 0:
      divisors.append(i)
      if i != num // i:
          divisors.append(num//i)
  # print(divisors)
  return divisors

for a in A:
  divs.extend(divisors(a))

# print(set(divs))
# print(divs)
duplicate = sorted([x for x in set(divs) if divs.count(x) > 1])
if duplicate[-1] == 1:
  print(sorted(divs)[-1])
else:
  print(duplicate[-1])

Submission status: Wrong Answer

Solution code:
import heapq

def gcd(a,b):
  while a>0 and b>0:
    a=a%b
    if not a>0:
      break
    b=b%a

  if a>b:
    return a
  return b

N=int(input())
arr=list(map(int,input().split(" ")))
arr.append(arr[0])

r=[]
for i in range(len(arr)-1):
  heapq.heappush(r,gcd(arr[i],arr[i+1]))


ans0=heapq.heappop(r)
ans1=heapq.heappop(r)
if len(r)!=0:
  ans2=heapq.heappop(r)
  if ans0==ans1:
    ans1=ans2
  else:
    ans1=ans1

print(ans1)

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 = []
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:
import sys
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))

a = list(set(a))



if len(a) <= 2:
    print(max(a))
else:
    a.sort()
    ans = max(gcd(a[0], a[-1]), gcd(a[1], a[-1]), gcd(a[0], a[1]))
    e_cnt = 0
    for e in a:
        if e % ans != 0:
            if e_cnt == 1:
                print(1)
                sys.exit()
            e_cnt += 1
        else:
            continue
    print(ans)

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=max(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:
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[n-i-1])

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 random
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()]
random.shuffle(a)

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 n==2:
    g1=gcd(a[0],a[1])
print(g1)

Submission status: Wrong Answer

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

num = 1


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


for i in range(N):
    if A[i]%num == 0:
        break
    B = A[:]
    B.pop(i)
    gcd1 = int(B[0])

    for j in range(1, N - 1):
        gcd1 = gcd(gcd1, B[j])

    if num < gcd1:
        num = gcd1

print(num)

Submission status: Wrong Answer

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


def get(lists, index):
    base = lists[index]
    lists.pop(index)

    lists = filter(lambda x: x > 1, [gcd(base, i) for i in lists])
    if not lists:
        return None
    elif len(lists) == 1:
        return lists[0]
    return sorted(lists)[1]


raw_input()
al = [int(i) for i in raw_input().split()]
al = sorted(al)[:3]

print(max(*[get(list(al), i) for i in range(len(al))]))

Submission status: Wrong Answer

Solution code:
import sys
# gcd
import fractions
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
# from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
from functools import reduce


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


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


#
# input関係の定義
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N = ii()
A = lmi()
old_gcd = gcd_list(A)
for i in range(N):
    A[i] = A[i] // old_gcd
i = N // 2
prev = 0
while i != prev and i != N - 1:
    if gcd_list(A[i:N]) == 1:
        prev = i
        i = (i + N - 1) // 2
        continue
    else:
        i = (prev + i) // 2
        continue
A.pop(i)
print(old_gcd * gcd_list(A))
# print(A)
#
# num = N
# ans = []
# while num != 2:
#     ans = []
#     if num % 2 == 0:
#         num = -(-num // 2)
#         for i in range(num):
#             ans.append(math.gcd(A[2 * i], A[2 * i + 1]))
#     else:
#         num = -(-num // 2)
#         for i in range(num - 1):
#             ans.append(math.gcd(A[2 * i], A[2 * i + 1]))
#             ans.append(A[-1])
#     if ans.count(1) >= 2:
#         print(old_gcd)
#         break
# else:
#     print(max(ans))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
N = int(input())
A = list(map(int,input().split()))
ans = 0
A = sorted(A)
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
ans = 0
ans_ = 0
if N == 2:
  tmp = [A[0],A[1]]
elif N == 3:
  tmp = [A[0],A[1],A[N-1]]
else:
  tmp = [A[0],A[1],A[N-2],A[N-1]]
for i in range(len(tmp)):
  tmp_ = tmp[:]
  tmp_.pop(i)
  ans_ = gcd_list(tmp_)
  if ans < ans_:
    ans = ans_
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
j=0
f=0
v = [0] * N

def gcd(c,d):
        while d!=0:
            c,d=d,c%d
        return c

for i in range(N):
    j = i+1
    if i+1 > N-1:
        j=0

    c = a[i]
    d = a[j]
    
    v[i] = gcd(c,d)
    f = v[i]

for i in range(len(v)-1):
    if v[i+1]>v[i]:
        f=v[i+1]



print(f)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b > 0:
        str12 = "{}.{}".format(a,b)
        str11 = "{}.{}".format(b,a)
        if str12 in mem.keys():
             return mem[str12]
        elif str11 in mem.keys():
            return mem[str11]
        else:
            a, b = b, a % b
            mem[str12] = a

    return a




N = int(input())
A = [int(x) for x in input().split()]
a2 = list(A)
max = 0
mem = {}
for i,_ in enumerate(A):
    A.pop(i)
    res = A[0]
    for i in A[1:]:
        res = gcd(i,res)
    max = res if res >= max else max
    A = list(a2)


print(max)

Submission status: Wrong Answer

Solution code:
import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

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

n = ni()
li = na()
li2 = []
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    a = fractions.gcd(li[0], li[1])
    b = fractions.gcd(li[1], li[2])
    c = fractions.gcd(li[2], li[0])
    li2.append(a)
    li2.append(b)
    li2.append(c)
    li2.extend(make_divisors(a))
    li2.extend(make_divisors(b))
    li2.extend(make_divisors(c))
    kouho = list(set(li2))
    for i in range(3,n):
        if len(kouho) == 0:
            break
        for num in kouho:
            if li[i] % num != 0:
                kouho.remove(num)
    if len(kouho) == 0:
        print(1)
    else:
        print(max(kouho))

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int,input().split()))
a.append(0)
a.append(0)
a.sort(reverse=True)
ans1 = 0
ans2 = 0
ans3 = 0

result = make_divisors(a[0] - a[2])
for i in range(len(result)):
	next = 0
	for j in range(n):
		if(j != 1 & a[j] % result[i] != 0):
			next = 1
			break
	if(next == 0):
		ans1 = result[i]
		break

result = make_divisors(a[0] - a[1])
for i in range(len(result)):
	next = 0
	for j in range(n):
		if(j != 2 & a[j] % result[i] != 0):
			next = 1
			break
	if(next == 0):
		ans2 = result[i]
		break

result = make_divisors(a[1] - a[2])
for i in range(len(result)):
	next = 0
	for j in range(n):
		if(j != 0 & a[j] % result[i] != 0):
			next = 1
			break
	if(next == 0):
		ans3 = result[i]
		break
max = ans1
if(ans2 > max):
	max = ans2
if(ans3 > max):
	max = ans3
print(max)

Submission status: Wrong Answer

Solution code:
org_N = int(input())
org_a = list(map(int,input().split()))
set_a = set(org_a)
#l_set_a = len(set_a)
a = list(set_a)
N = len(a)
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)
                #print('i,inlist:',i , n//i)

    divisors.sort()
    return divisors

adic = {}
#kouho = []
g = 1
for a1 in a:
    diva = make_divisors(a1)
    for diva1 in diva:
        if diva1 in adic.keys():
            adic[diva1] += 1
            #l = adic[diva1] >= N-1: 
            #if adic[diva1] >= N-1:
                #kouho.append(diva1)
            #    g = max(g,diva1)
        else:
            adic[diva1] = 1
        if adic[diva1] >= N-1:
                #kouho.append(diva1)
                g = max(g,diva1)
#print(adic)
#print(kouho,max(kouho))
print(g)

Submission status: Wrong Answer

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

import sys
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=LIST()

a=A[0]
idx=1
for i in range(1, N):
    b=gcd(a, A[i])
    if b<a:
        a=b
        idx=i

B=A[:]
B.pop(idx)
ans1=B[0]
for i in range(1, N-1):
    ans1=gcd(ans1, B[i])
B=A[:]
B.pop(idx-1)
ans2=B[0]
for i in range(1, N-1):
    ans2=gcd(ans2, B[i])
print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
# from math import gcd

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


def f(a, l):
    ba = a
    ai = 0
    for i, v in enumerate(l):
        a_ = gcd(ba, v)
        if ba > a_:
            ba = a_
            ai = i
    return (ba, ai)

a = gcd(A[0], A[1])
if a == 1:
    ba1, _ = f(A[0], A[2:])
    ba2, _ = f(A[1], A[2:])
    print(max(ba1, ba2))
else:
    ba, ai = f(a, A[2:])
    if ai == 0:
        ba1, _ = f(A[0], A[2:])
        ba2, _ = f(A[1], A[2:])
        print(max(ba1, ba2))
    else:
        A[ai] = A[0]
        ba, _ = f(a, A[2:])
        print(ba)

Submission status: Wrong Answer

Solution code:
from functools import reduce

def gcd(m, n):
    # 入力を m, n (m ≧ n) とする。
    tmp = max(m,n)
    n = min(m,n)
    m = tmp
    # n = 0 なら、 m を出力してアルゴリズムを終了する。
    if n == 0:
        return m
    # m を n で割った余りを新たに n とし、更に 元のnを新たにm とし 2. に戻る。
    return gcd(n, m % n)

def gcda(arr, left, right):
    return reduce((lambda a,b:gcd(a,b)), arr[left:right+1], gcd(arr[left], arr[right]))

n = int(input())
nums = [ int(s) for s in input().split(" ")]

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

allgcd = gcda(nums, 0, n-1)

found = 0
mingcd= gcd(nums[0], nums[1])
delete_kouho = 1
for i in range(1,n):
    nowgcd = gcd(nums[0], nums[i])
    if mingcd > nowgcd:
        mingcd = nowgcd
        delete_kouho = i

    if nowgcd == allgcd:
        found += 1
        

if found >= 2:
    print(gcda(nums, 1, n-1))
    exit()
elif delete_kouho == n-1 :
    print(gcda(nums, 0, n-2))
    exit()
else:
    print(gcd(gcda(nums, 0, delete_kouho-1), gcda(nums, delete_kouho+1, n-1)))

Submission status: Wrong Answer

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

ctr = Counter(A)
solos = []
for k,v in ctr.items():
    if v > 1: continue
    solos.append(k)

if len(solos) == 0:
    g = A[0]
    for a in A:
        g = gcd(g,a)
    print(g)
    exit()

g1 = g2 = None
for k in ctr.keys():
    if k != solos[0]:
        if g1 is None:
            g1 = k
        else:
            g1 = gcd(g1,k)
    if len(solos) > 1 and k != solos[1]:
        if g2 is None:
            g2 = k
        else:
            g2 = gcd(g2,k)

if g2 is None: g2 = 0
print(max(g1,g2))

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,p2,p3 = gcd(a[0],a[1]),gcd(a[1],a[2]),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(min(tmp,res1,res2,res3))

Submission status: Wrong Answer

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

if N < 3 :
    print(max(A))
    exit()

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

divi = A[1]
flag = True
if len(A) >= 4 :
    for i in range(2, len(A)) :
        tmp = gcd(A[i], divi)
        if i >= 3 :
            if gcd(A[i], divi) != mindiv :
                flag = False
                break
        mindiv = tmp

    if flag :
        print(mindiv)
        exit()

divi = A[0]
divList = []

for i in range(1, len(A)) :
    divList.append(gcd(A[i], divi))

divList.sort()

if divList.count(divList[0]) == 1 :
    print(divList[1])
else :
    print(divList[0])

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

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

Submission status: Wrong Answer

Solution code:
import math
import functools

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

if max(v) % 2 ==0:
	b = True
else:
	b = False
		
v.sort()

for index,_ in enumerate(v):
	if _  % 2 ==0:
		if not b:
			v[index] = v[-1]
			break
			
	else:
		if b:
			v[index] = v[-1]
			break

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
memo = {}

def gcd(a, b):
    if (a,b) in memo:
        return memo[(a,b)]
    if b == 0:
        return a
    
    ans = gcd(b, a%b)
    memo[(a,b)] = ans
    return ans

# current_gcd = A_list[0]
# skip_candidate = 0
# for i in range(1, len(A_list)):
#     next_gcd = gcd(A_list[i], current_gcd)
#     print("index:{} next_gcd:{}".format(i, next_gcd))
#     if next_gcd < current_gcd:
#         if skip_candidate < next_gcd:
#             current_gcd = next_gcd
#         else:
#             current_gcd = skip_candidate
#             skip_candidate = next_gcd
            
# print(current_gcd)        


if len(A_list) == 2:
    print(gcd(A_list[0], A_list[1]))
else:
    loop = len(A_list)
    current_max = 0
    for i in range(loop):
        removed = A_list.pop(i)
        cur_gcd = 0
        for j in range(len(A_list)):
            cur_gcd = gcd(A_list[j], cur_gcd)
        
        current_max = max(cur_gcd, current_max)
        A_list.insert(i, removed)

    print(current_max)

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

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)
    print(a_min_divisors)
    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 sys


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


def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A)

    if N == 2:
        return A[1]

    g = A[0]

    B = []
    for a in A:
        g = gcd(a, g)
        B.append(g)

    i = B.index(g)
    A.pop(i)

    g = A[0]
    for a in A:
        g = gcd(g, a)

    return g


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
N = input()

A = map(int,raw_input().split())

B = []

for i in A:
    if i not in B:
        B.append(i)

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

ans = 0;
for i in range(len(B)):
    res = 0
    for j in range(len(B)):
        if i == j:
            continue
        res = gcd(res,B[j])
    ans = max(ans,res)
        

if len(B) == 1:
    print B[0]
else:
    print ans

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

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:
        A[j-1] = A[j]
        temp = gcd(A[0], A[1])
        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())
num_list = list(map(int, input().split()))
num_unique = list(set(num_list))
num_unique.sort()
num_unique.reverse()
answer_list = []
max_num = 0
flag = False
for i in range(num_unique[-1], 0, -1):
    if flag and count < 2:
        break
    else:
        flag = True
        count = 0
        max_num = i

    for num in num_unique:
        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:
N = int(input())
A = list(map(int, input().split()))
def gcd(a, b):
    P = max(a, b)
    Q = min(a, b)
    R = P%Q
    P = Q
    Q = R
    while R != 0:
        R = P%Q
        P = Q
        Q = R
    return P

candidate = [(gcd(A[0], A[1]), True), (A[0], False), (A[1], False)]
for i in range(2, N):
    nxt_cand = []
    for v, b in candidate:
        if(v == 1):
            continue
        if(b == True and gcd(v, A[i]) < v):
            nxt_cand.append((v, False))
        else:
            nxt_cand.append((gcd(v, A[i]), b))
    if(len(nxt_cand)==0):
        nxt_cand = [(1, False)]
    candidate = nxt_cand[::]

print(max(candidate)[0])

Submission status: Wrong Answer

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

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

gcds = [integers[0]]
for integer in integers[1:]:
    gcds.append(gcd(integer, gcds[-1]))
    
ans = [gcds[-2]]
for i in range(len(gcds) - 2):
    ans.append(gcd(gcds[i], integers[i + 2]))

temp = integers[1]
for integer in integers[2:]:
    temp = gcd(temp, integer)
ans.append(temp)
print(max(ans))

Submission status: Wrong Answer

Solution code:
import fractions, sys
from functools import reduce

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

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

div = gcd(A)
for i in range(N) :
  tmp = gcd(A[0:i] + A[i+1:N])
  if tmp != div :
    print(int(tmp))
    sys.exit()
print(div)

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

list_koyaku1=[]
list_koyaku11=[]       
         
if N==2:
    ans=max(A)

else:
    b=min(A)
    c=max(A)
    for a in A:
        list_koyaku1.append(gcd(a,b))

    for a in list_koyaku1:
        list_koyaku11.append(gcd(a,c))
    ans=max(list_koyaku11)

print(ans)

Submission status: Wrong Answer

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

for i in range(0,n):
	for j in range(i+1,n):
		num=fractions.gcd(array[i],array[j])
		# print(num)
		if max<num:
			max=num

print(max)

Submission status: Wrong Answer

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


def gcd(a, b):
    m, n = int(a/b), a%b
    if n == 0:
        return b
    return gcd(b, n)

def main():
    n = int(input())
    A = [int(e) for e in input().split(" ")]

    N = [0 for i in range(n+1)]

    max_n = 0
    for i in range(n):
        for j in range(i+1, n):
            current = gcd(A[i], A[j])
            if max_n < current:
                max_n = current

    print(max_n)

main()

Submission status: Wrong Answer

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

def gcd_list(numbers, maxv):
    gcdv = numbers[0]
    if len(numbers) == 1:
        return gcdv
    for n in range(1, len(numbers)):
        gcdv = gcd(gcdv, numbers[n])
        if maxv > gcdv:
            return maxv
        else:
            maxv = gcdv
    return maxv

def main():
    n = int(input())
    a = [int(a) for a in input().split()]

    maxv = 0
    for nn in range(n):
        maxv = gcd_list(a[:nn]+a[nn+1:], maxv)
    print(maxv)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

if A.count(1) > 1:
    print(1)
    exit()

dd = {}
for i in range(N):
    if A[i] not in dd.keys():
        dd[A[i]]= 0
    dd[A[i]] += 1
if len(dd.keys()) == 2:
    for key in dd.keys():
        if dd[key] == N - 1:
            print(max(A))
            exit()

import fractions
if min(A) == 1:
    mgcd = 0
    A.remove(1)
    for i in range(N-2):
        mgcd = max(mgcd , fractions.gcd(A[i],A[i+1]))
        print(mgcd)
        exit()

mina = min(A)
maxa = max(A)
d = {}
for i in range(N):
    k = fractions.gcd(mina , A[i])
    if k not in d.keys():
        d[k] = 0
    d[k] += 1
mind = min(d.keys())

if d[mind] == 1:
    j = sorted(d.keys())
    print(j[1])
else:
    print(mind)

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-1])
    if s!=on:
      on=max(s,im)
      im=gcd(s,im)
  print(max(no,on))

Submission status: Wrong Answer

Solution code:
n = input()
A = input().split(" ")

n = int(n)
A_tmp = []
for a in A:
    A_tmp.append(int(a))
A = A_tmp
def yakusu(m):
    tmp = []
    for i in range(1,m):
        if m % i == 0:
            tmp.append(i)
    return(tmp)
all_yakusu = []
for a in A:
    all_yakusu.extend(yakusu(a))
unique = list(set(all_yakusu))
biggest = 0
for i in range(len(unique)):
    a = all_yakusu.count(unique[i])
    if a >= (n-1):
        if unique[i] > biggest:
            biggest = unique[i]
print(biggest)

Submission status: Wrong Answer

Solution code:
import fractions

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

gcd =[]
for i in range(number-1):
    gcd.append(fractions.gcd(A[i], A[i+1]))

gcd.append(fractions.gcd(A[0], A[number-1]))

gcd.sort()

if gcd[0] == gcd[number-1]:
    print(gcd[0])

elif gcd[number-2] == gcd[number-1] and gcd[number-3] != gcd[number-2]:
    print(gcd[number-3])

else:
    print(gcd[number-1])

Submission status: Wrong Answer

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

n = int(input())
an = [int(i) for i in input().split(" ")]
an = sorted(an)
if len(an) <= 2:
    print(max(an))
else:
    sample = []
    for i in range(len(an)):
        a1 = an[i]
        for a2 in an[i+1:]:
            tmo = gcd(a1, a2)
            if a1 == a2:
                continue
            sample.append(tmo)

    sample = sorted(sample)
    print(sample[n-1])

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