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(x) for x in input().split()]


def max_GCD(m_list):
  m_list.sort()
  a = m_list.pop()
  result = a
  while m_list:
    b = m_list.pop()
    a = GCD(a, b)
    if a < result:
      result = a
    if result == 1:
      return result
  return result

def GCD(m, n):
  a = max(m, n)
  b = min(m, n)
  while b > 0:
    r = a % b
    if r == 0:
      return b
    a = b
    b = r  

A.sort(reverse=True)

if len(A) == 2:
  print(max(A))
else:
  print(max(GCD(A[0], A[1]), GCD(A[1], A[2]), GCD(A[0], A[2])))

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b!=0:
        a, b = b, a%b
    return a
 
 
N = int(input())
A = [int(_) for _ in input().split()]
A = sorted(A)

if N == 2:
    print(A[1])
else:
    tmp1 = A[1]
    for i in range(2, N):
        tmp1 = gcd(tmp1, A[i])
    
    GCD = []
    for i in range(1, N):
        GCD.append(gcd(A[0], A[i]))
    
    GCD = sorted(GCD)
    tmp2 = GCD[1]
    
    print(max(tmp1, tmp2))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
seki = 1
Max = max(A)

for x in range(2,int(Max**0.5)+1):
    count = 0

    for y in range(N):
        if A[y] % x != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = x

for i in range(N):
    count = 0
    if A[i] < 1000000000**0.5+1:
        break
    for j in range(N):
        if A[i] % A[j] != 0:
            count += 1
        if count >= 2:
            break
    else:
        seki = A[i]

print(seki)

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:]/n1
    p2 = list(map(lambda x: x.is_integer(), p))
    if False in p2:
        print(p)
    else:
        print(p2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
B = []
C = []

#print(A)

def NEXTSTEP(N,A,B):
    MAX=A[0]
    for i in range(N):
        if A[i] % MAX != 0:
            B.append(A[i] % MAX)
    
    B.append(MAX)
    B = sorted(B)
    N = len(B)
    return(B,N)


def loop(N,A):
    B = []
    A,N = NEXTSTEP(N,A,B)
    if N != 1:
        loop(N,A)       
    
    return(A[0]) 

for i in range(N):
    B = [i for i in A]
    B.pop(i)
    MAX = loop(N-1,B)
    C.append(MAX)

C = sorted(C,reverse=True)
print(C[0])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
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 = int(input())
a = map(int, input().split())

cnt_div = dict()
for i, _a in enumerate(a):
    if i < 3:
        for d in make_divisors(_a):
            if d in cnt_div:
                cnt_div[d] += 1
            else:
                cnt_div[d] = 1
    else:
        tmp = {}
        for d, c in cnt_div.items():
            if _a % d == 0:
                tmp[d] = c + 1
        cnt_div = tmp


max_div = 1
for r, c in cnt_div.items():
    if c >= n - 1:
        max_div = max(max_div, r)

print(max_div)

Submission status: Wrong Answer

Solution code:
import functools
import copy

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

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x % y ==0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        else:
            return z


def gcd_list(numbers):
    if len(numbers) == 1:
        return numbers[0]
    else:
        return functools.reduce(gcd, numbers)

n_gcd = gcd_list(A)

ccc = []
for i in A:
    ccc.append(i / n_gcd)

for i in range(1,N):

    ddd = ccc[0]
    ddd = gcd(ddd, ccc[i])
    if ddd == 1:
        break


B = copy.copy(A)
B.pop(i)

print(gcd_list(B))

Submission status: Wrong Answer

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

n=int(input())
a=sorted([int(i) for i in input().split()])
gcd1=[0]*n
gcd2=[0]*n
for i in range(n):
    if i!=0:
        gcd1[i]=gcd(a[0],a[i])
    if i!=1:
        gcd2[i]=gcd(a[1],a[i])
m=sorted([max(gcd1),max(gcd2)])
cnt1=0
cnt2=0
for i in range(n):
    if a[i]%m[0]!=0:
        cnt1+=1
    if a[i]%m[1]!=0:
        cnt2+=1
if n==2:
    print(max(a))
elif cnt2<=1:
    print(m[1])
elif cnt1<=1:
    print(m[0])
else:
    print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
a = sorted(A,reverse=True)
bef = a[0]


flag =0
ans_list = []

for x in a[2:]:
    if bef %x == 1:
        if flag == 0:
            flag = 1
            continue

    bef %= x
print(bef)

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)

s_idx = 0
max_element = 1

for i in range(N):
    element = gcd(A[i], A[(i + 1) % N])

    if N == 2:
        print(max(A))
        exit()
    else:
        for j in range(2,N-1):
            element=gcd(element,A[(j + 1) % N])
            if element < max_element:
                break
        
        if element > max_element:
            max_element = element
print(max_element)
exit()

Submission status: Wrong Answer

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

from functools import reduce
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def gcds(*numbers):
    return reduce(gcd, numbers)

# ans = 0
# for i in range(len(a)):
#     aa = a.copy()
#     aa.pop(i)
#     g = gcds(*aa)
#     ans = g if g > ans else ans
# print(ans)

def factorize(n):
    fct = list()
    base, exp = 2, 0
    while base * base <= n:
        while n % base == 0:
            n = n // base
            exp = exp + 1

        if exp > 0:
            fct.append(base)

        base, exp = base + 1, 0
    if n > 1:
        fct.append(n)
    return set(fct)

from collections import defaultdict
s = factorize(a[0])
fs = [s.copy()]
flag = True
for i in range(1, len(a)):
    f = factorize(a[i])
    fs.append(f)
    s |= f
    if s != f and flag == True:
        flag = False
if flag:
    aa = a.copy()
    aa.remove(min(aa))
    print(gcds(*aa))
    exit()
mi = max(s)
for i in range(len(a)):
    f = fs[i]
    tar = a[i]
    for j in f:
        if j == mi:
            aa = a.copy()
            aa.pop(i)
            print(gcds(*aa))
            exit()

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()
ans = 1

for i in range(N):
    B = A[:]
    B.pop(i)
    tmp = B[0];
    for j in B:
        if (ans > j):
            break
        tmp = gcd(tmp, j)
        ans = max(ans, tmp)

    

print(ans)

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[0], AList[1])
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:
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 a == 2:
            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:
import fractions
from functools import reduce

def calc_gcd(*n):
  return reduce(fractions.gcd, n)

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

b = A[0]
gcd = min(A)
for i in range(N):
  ret = fractions.gcd(gcd, A[i])
  if gcd != ret:
    gcd = ret
    b = A[i]

A.remove(b)
print(calc_gcd(*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, N - 1)

max_gcd = 1
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:
# C
import functools
def gcd(a,b):
    if a<b:a,b=b,a
    if a%b==0:return b
    return gcd(b,a%b)

n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
pre_a = -1
pre_gcd = a[0]

if n > 1000:
    for i in range(n):
        if pre_a != a[i]:
            if i >= 1:
                pre_gcd = functools.reduce(gcd, [pre_gcd, a[i-1]])
            values = a[i+1:]
            values.append(pre_gcd)

            res = functools.reduce(gcd, values)
            ans = max(ans, res)
        pre_a = a[i]
else:
    for i in range(n):
        if pre_a != a[i]:
            values = a[:i] + a[i+1:]
            res = functools.reduce(gcd, values)
            ans = max(ans, res)
        pre_a = a[i]

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc125_a
import fractions, functools, itertools

# input
n = int(input())
A = [int(s) for s in input().split()]
# get ans
b0 = [fractions.gcd(A[0], a) for a in A]
b1 = [fractions.gcd(A[1], a) for a in A]
b0.sort()
b1.sort()
ans = max(b0[1], b1[1])
# output
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

N = int( input() )
A = list( map( int ,input().split()) )
Al = []
if len(A) >= 3:
    for lop in range(2,len(A),3):
        A1 = fractions.gcd(A[lop-2],A[lop-1])
        A2 = fractions.gcd(A[lop-2],A[lop])
        A3 = fractions.gcd(A[lop-1],A[lop])
        Al.append(max(A1,A2,A3))
    if len(A) % 3 > 0:
        A1 = fractions.gcd(A[len(A)-3],A[len(A)-2])
        A2 = fractions.gcd(A[len(A)-3],A[len(A)-1])
        A3 = fractions.gcd(A[len(A)-2],A[len(A)-1])
        Al.append(max(A1,A2,A3))
    print(min(Al))
else:
    print(max(A))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
lsta = list(map(int,input().split()))
nplsta = np.array(lsta)
npsolsta = np.sort(nplsta)
lst = [n]
for i in range(1,npsolsta[1]):
  lst.append(len(npsolsta[npsolsta%i==0]))
nplst = np.array(lst)
lst2 = np.where(nplst>=(n-1))
print(max(lst2[0]))

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce
import copy


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


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

ans = 1
for i in range(N):
    a = copy.deepcopy(A)
    print(a)
    a.pop(i)
    g = gcd_list(a)
    if g > ans:
        ans = g
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools

num = int(input())
int_list = np.array(list(map(int, input().split())))

# 任意のN-1個の組み合わせの最大公約数を求めればいい
combination = list(itertools.combinations(int_list,num - 1))
output = 0
for c_list in combination:
    _c_list = sorted(list(c_list))

    min_ai = min(_c_list)
    max_ai = max(_c_list)

    g_common_divisor = 1
    if min_ai == max_ai:
        output = max_ai
        break

    for i in reversed(range(1, int(min_ai / 2) + 1)):
        flag = 0
        for num in _c_list:
            if num % i != 0:  # iで割り切れなければiは公約数じゃない
                flag = 1
                continue
        if flag == 0:
            g_common_divisor = i
            break
        # print(c_list, i, flag, g_common_divisor)
    if output < g_common_divisor:
        output = g_common_divisor
print(output)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""

import numpy as np
import sys
""""
import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect
"""

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default
# 約数を高速で列挙するコード
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, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

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


def main():
    A.sort()
    CNT = dict()
    non_kouho = []
    
    for i,a in enumerate(A):
        ads = make_divisors(a)
        if i == 0 or i ==1:
            ads2 = ads
        else:
            ads2 =(set(non_kouho) ^ set(ads)) & set(ads)

        for ad in ads2:
            if ad in CNT:
                CNT[ad]+=1
            else:
                if i == 0 or i==1:
                    CNT[ad]=1
                if i>1:
                    non_kouho.append(ad)
        if i==2:
            de_list=[]
            for key in CNT.keys():
                if CNT[key] == 1:
                    de_list.append(key)
                    non_kouho.append(key)
            for key in de_list:
                CNT.pop(key)
    l_kouho = list(CNT.keys())
    print(max(l_kouho))

    
            
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import fractions
n=int(input())
a=list(map(int,input().split()))
if n==2:
    print(max(a[0],a[-1]))
    exit()
#mae
r1=a[0]
flag1=0
for i in range(1,n):
    x=fractions.gcd(r1,a[i])
    if x<r1 and flag1==0:
        if i!=1:
            flag1=1
        else:
            r1=x
    elif x<r1:
        r1=x
#usiro
r2=a[n-1]
flag2=0
for k in range(1,n):
    y=fractions.gcd(r2,a[n-k-1])
    if y<r2 and flag2==0 :
        if k!=1:
            flag2=1
        else:
            r2=y
    elif y<r2:
        r2=y
p=a[0]
a[0]=a[1]
a[1]=p
q=a[n-1]
a[n-1]=a[n-2]
a[n-2]=q
#mae
r3=a[0]
flag3=0
for v in range(1,n):
    x=fractions.gcd(r3,a[v])
    if x<r3 and flag3==0:
        if v!=1:
            flag3=1
        else:
            r3=x
    elif x<r3:
        r3=x
#usiro
r4=a[n-1]
flag4=0
for w in range(1,n-1):
    y=fractions.gcd(r4,a[n-w-1])
    if y<r4 and flag4==0:
        if w!=1:
            flag4=1
        else:
            r4=y
    elif y<r4:
        r4=y
print(max(r1,r2,r3,r4))

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))
    
    number_prime=list_koyaku11.count(1)
    
    if number_prime>1:
        ans=1
    else:
        ans=max(list_koyaku11)

print(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(1, N):
    if i != x:
        w = gcd(w, A[i])

print(w)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
maxi=10**9
allyp=[]
for i in range(len(A)):
    divesor=[]
    a=A[i]**0.5
    for j in range(1,int(a)+1):
        if A[i]%j==0:
            divesor.append(j)
            divesor.append(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(i)
        break

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]
while i >= 1:
  if kake % (i**(n-1)) == 0:
    answer = i
    break
  i -= 1
print(answer)

Submission status: Wrong Answer

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




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,mem)
    max = res if res >= max else max
    A = list(a2)


print(max)

Submission status: Wrong Answer

Solution code:
import math

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



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


g = [0]*(n-1)
m = 1
max = -1
for i in range(n-1):
    for k in range(m,n):
        f = gcd(a[i],a[k])
        if max < f:
            max = f
    g[i] = max
    m += 1
    
print(g)

#g = list(set(g))

if len(g) > 2:
    print(1)
else:
    g = sorted(g)
    print(g[len(g)-1])

Submission status: Wrong Answer

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

from fractions import gcd

b = [0] * n
m = 0

if n == 2:
    print(gcd(a[0], a[1]))
else:
    for k in range(n):
        for i in range(n-1):
            if k != i:
                if i+1 != k:
                    if b[k] == 0:
                        b[k] = gcd(a[i], a[i+1])
                    else:
                        b[k] = gcd(b[k], a[i+1])
                else:
                    if i+2 < n:
                        if b[k] == 0:
                            b[k] = gcd(a[i], a[i+2])
                        else:
                            b[k] = gcd(b[k], a[i+2])
        m = max(m, b[k])
    print(m)

Submission status: Wrong Answer

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

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

t = sum(s)

p = gcd(s[0],t-s[-1])

for i in range(n-1):
    p = max(p,gcd(s[i+1],t-s[i]))
    
print(p)

Submission status: Wrong Answer

Solution code:
import sys
N = input()

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


if len(A) < 3:
    print(max(A))
    sys.exit()



min_0 = A[0]
min_1 = A[1]
min_2 = A[2]


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]





def kouyaku(x, y):
    min_num = min(x, y)
    max_num = max(x, y)
    if max_num % min_num == 0:
        return min_num

    for i in reversed(range(min_num // 2 + 1)):
        if x % i == 0 and y % i == 0:
            return i

def check(n):
    fail_count = 0
    for a in A:
        if a % n != 0:
            fail_count +=1
            if fail_count == 2:
                return False
    return True




kouyaku_01 = kouyaku(min_0, min_1)
kouyaku_12 = kouyaku(min_1, min_2)
kouyaku_02 = kouyaku(min_0, min_2)


ans = 1
if check(kouyaku_01):
    ans = max(ans, kouyaku_01)

if check(kouyaku_12):
    ans = max(ans, kouyaku_12)


if check(kouyaku_02):
    ans = max(ans, kouyaku_02)


print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
import functools
N=int(input())
A=list(map(int, input().split()))
Z=0
ans=0
for i in range(N):
    if i==0:
        B=A.copy()
        B[0]=B[1]
        ans=functools.reduce(fractions.gcd, B)


    else :
        B=A.copy()
        B[i]=B[0]
        Z =functools.reduce(fractions.gcd, B)


    if ans >Z:
        ans=ans
    else:
        ans=Z

    if  functools.reduce(fractions.gcd, A) == 1:
        if ans>1 :
            break
        else :
            continue              

print(ans)

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)
flag =True
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])
    t1 = a1 & a2
    t2 = a3 & a2
    t3 = a1 & a3
    cond = t1|t2|t3
    maxi= 0
    for ans in cond:
        count =0
        flag = True
        for a in A:
            if a%ans != 0:
                count += 1
            if count >= 2:
                flag = False
                break
        if flag and maxi < ans:
            maxi = ans
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
def mygcd(gA, gB):
    #print(gA,gB)
    while True:
        gR = gA % gB
        if gR == 0:
            #exit()
            return gB
        gA = gB
        gB = gR
        #print(gB)

if False:
    N=int(input())
    A=np.unique(list(map(int,input().split())))
else:
    A=np.asarray(range(10**5)[10**4:])
#C=np.asarray(list(map(int,input().split())))

mina = np.min(A)

for i in range(A.size)[1:]:
    A[i] = mygcd(mina,A[i])
    #print(A[i])
uA=np.unique(A)
uA = np.append(uA,-1)
#print(uA)
max = 0
for a in uA:
    if A[A==a].size > 1:
        continue
    tmpgcd = uA[uA!=a][0]
    for ta in uA[uA!=a][1::]:
        tmpgcd = mygcd(tmpgcd,ta)
    #print(tmpgcd,max)
    if max < tmpgcd: max = tmpgcd

print(max)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

def calc_gcd(*n):
  return reduce(fractions.gcd, n)

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

b = A[0]
gcd = max(A)
for i in range(N):
  ret = fractions.gcd(gcd, A[i])
  if gcd != ret:
    gcd = ret
    b = A[i]

A.remove(b)
print(calc_gcd(*A))

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

# which one should be changed


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

print(max(tmp))

Submission status: Wrong Answer

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

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    A = il()
    ans = 0
    for i, n in enumerate(combinations(A, N - 1)):
        tmp = max(ans, reduce(gcd, n))
        if ans == tmp:
            return ans
        ans = tmp
    return ans


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

def parse(inp):
    n=int(next(inp))
    a=list(map(int,next(inp).split()))
    return n,a
  
def soinsu(inp):
    n=inp
    l=[]
    for i in range(2,int(np.sqrt(inp))+1):
        if(n%i==0):
            while(n%i==0): n = int(n/i)
            l.append(i)
#    if(len(l)==0): l.append(inp)
    return l
  
def main(inp):
    n,a=inp
    maxlen=31162
    
    insulist=[0] * maxlen
    for i in range(n):
        iinsu = soinsu(a[i])
        for j in range(len(iinsu)):
            insulist[iinsu[j]] += 1
    flag=0
    ans =1
    for i in range(len(insulist)-1,1,-1):
        if(insulist[i]==n): ans *= i
        elif(insulist[i]==n-1 and flag==0): 
            ans *= i
            flag = 1
    return ans
  
print(main(parse(sys.stdin)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A_min = min(A)
D = []


def find_gcd(x, y):
    while(y):
        x, y = y, x % y
    return x


for i in range(N):
    D.append(A[i]-A_min)

D.remove(0)
D_min = min(D)
D.remove(D_min)
D.append(A_min)
gcd = find_gcd(A_min, D[0])

if len(D) >= 1:
    for i in range(1, len(D)):
        gcd = find_gcd(gcd, D[i])

print(gcd)

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) > 2:
  print(nums[1])
else:
    print(nums[0])

Submission status: Wrong Answer

Solution code:
import fractions

n = int(input())
a = list(map(int, input().split()))
gcd_0 = fractions.gcd(a[0],a[1])
gcd_1 = min(a[0], a[1])
for i in range(2,n):
    gcd_0 = fractions.gcd(gcd_0, a[i])
    gcd_1 = max(gcd_0, fractions.gcd(gcd_1, a[i]))
gcd_0 = fractions.gcd(a[0],a[1])
gcd_2 = max(a[0], a[1])
for i in range(2,n):
    gcd_0 = fractions.gcd(gcd_0, a[i])
    gcd_2 = max(gcd_0, fractions.gcd(gcd_2, a[i]))
print(max(gcd_2,gcd_1))

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

n = int(stdin.readline().rstrip())
an = list(map(int, input().split()))

left = []
right = []

before = -1
for i in range(n):
  if(i==0):
    before = an[i]
  else:
    before = gcd(before, an[i])
  left.append(before)

before = -1
for i in range(n):
  if(i==0):
    before = an[n-1-i]
  else:
    before = gcd(before, an[n-1-i])
  right.append(before)


max = 0
for i in range(n):
  if(i==0):
    before = right[1];
  elif(i==(n-1)):
    before = left[n-2];
  else:
    before = gcd(left[i-1],right[n-2-i])
  if(max < before ):
    max = before

print(max)

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

for i in range(1):
    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)