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()] 
 
import fractions
 
if N == 2:
    print(fractions.gcd(A[0],A[1]))
    exit()
    
ans = []
for i in range(N):
    a = A[:i] + A[i+1:]
    for j in range(1,N-1):
        if j == 1:
            g = fractions.gcd(a[0],a[j])
        else:
            g = fractions.gcd(g,a[j])
    ans.append(g)

print(max(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A = list(set(A))
def u(a, b):
        if b == 0:
                return a
        return u(b, a % b)

if len(A) <= 2:
        res = A[0]
else:
        res = -1
        for i in range(len(A)):
                tmp = list(A)
                tmp.pop(i)
                for k in range(len(tmp)-1):
                        tmp[k+1] = u(tmp[k], tmp[k+1])
                res = max(res, min(tmp))

print(res)

Submission status: Wrong Answer

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

num = sorted(A, reverse = True)[1]
i = 0
while num > 0:
    tmp = [x for x in A if x % num == 0]
    if len(tmp) > 1:
        print(num)
        break
    else:
        num -= 1

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
if N==2:
  print(max(A))
  exit()
def gcd(x,y):
  if y==0:
    return x
  if x<y:
    z = x
    x = y
    y = z
  return gcd(y,x%y)
ptn0 = A[1]
ptn1 = A[0]
for i in range(N):
  if i!=0:
    ptn0 = gcd(ptn0,A[i])
  if i!=1:
    ptn1 = gcd(ptn1,A[i])
print(max(ptn0,ptn1))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

import fractions
import copy
from functools import reduce

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

max_gcd = 0
for idx in range(N):
    
    if idx == 0:
        cleaned = copy.copy(A_list)
        del cleaned[idx]
        gcd_value = gcd(tuple(cleaned))
        if max_gcd < gcd_value:
            max_gcd = gcd_value
    else:
        former_target = A_list[idx-1]
        if former_target % max_gcd == 0:
            cleaned = copy.copy(A_list)
            del cleaned[idx]
            gcd_value = gcd(tuple(cleaned))
            if max_gcd < gcd_value:
                max_gcd = gcd_value
        else:
            continue
        
print(max_gcd)

Submission status: Wrong Answer

Solution code:
import math

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

def gcd_list(arr):

    ans = arr[0]
    for c in arr[1::]:
        ans = gcd(ans , c)
    return ans

N = int(input())

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

g = gcd_list(A)

for i in range(N):
    tmp = A.pop(0)
    if g < gcd_list(A):
        g = gcd_list(A)
        break
    A.append(tmp)

print(g)

Submission status: Wrong Answer

Solution code:
from fractions import gcd


def mygcd(enum):
    if len(enum) == 1:
        return enum[0]
    ret = 0
    for i in range(len(enum)-1):
        if i == 0:
            ret = gcd(enum[0], enum[1])
        else:
            ret = gcd(ret, enum[i])
    return ret


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

ans = 0
for i in range(n):
    li = a[0:i] + a[i+1:]
    po = mygcd(li)
    if ans < po:
        ans = po

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
alist = [int(_) for _ in 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

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


result = 0
for i in range(n-1):
  for j in range(1,n-1):
    gcdvalue = gcd(alist[i],alist[j+1]) # 最初のエントリは固定。後半は変えていく
    if gcd(alist[i],alist[j+1]) > result:
      result = gcd(alist[i],alist[j+1])

print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A.copy(), reverse=True)

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

ansans = 1
for b in B:
    divs = make_divisors(b)

    ans = False
    for d in divs:
        count = 0
        for a in A:
            if a % d != 0:
                count += 1
                if count >= 2:
                    break
        if count < 2:
            ans = d
            break
    if ans:
        ansans = ans
        break

print(ansans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
minimum=10**9
for a in A:
    if a<minimum:
        minimum=a
devisors=[]
for i in range(1,minimum+1):
    if minimum%i==0:
        devisors.append(i)
devisors.reverse()
for d in devisors:
    count=0
    for a in A:
        if a%d!=0:
            count+=1
    if count<=1:
        break
print(d)

Submission status: Wrong Answer

Solution code:
def gcd(num_list):
  for i in range(min(num_list),1,-1):
    D = [o%i for o in num_list]
    if sum(D) == 0:
      return i
    elif D.count(0) == len(D)-1:
      return i
  return 1

N = input()
A = input().split()
A = [int(a) for a in A]
print(gcd(A))

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)
A[N - 1 - 1] = A[0]
#print(A)
list.append(gcd_list(A))

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

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

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)
        for j in range(len(A_list) - 1):
            current_max = max(current_max, gcd(A_list[j], A_list[j+1]))
        
        A_list.insert(i, removed)

    print(current_max)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
minus = 1
ma = min(A)
# if sum([a%2!=0 for a in A])>1:
#     minus = 2
#     if ma%2==0:
#         ma -= 1
for i in range(ma):
    tof = [a%ma==0 for a in A]
    if sum(tof)>=N-1:
        break
    ma = int((ma+1)//2)
if ma <= 0:
    print(1)
else:
    print(ma)

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[i-1], 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=min(ans1, gcd(B[i-1], B[i]))
B=A[:]
B.pop(idx-1)
ans2=B[0]
for i in range(1, N-1):
    ans2=min(ans2, gcd(B[i-1], B[i]))
print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import fractions
from functools import reduce

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

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

ans = 1
A.sort()
gcd1 = gcd(A)
for i in range(N):
    A[i] //= gcd1

ans *= gcd1
cnt = 0
for i in range(N-1):
    if A[i+1] - A[i] == 1:
        a = copy.deepcopy(A)
        a.remove(A[i])
        b = copy.deepcopy(A)
        b.remove(A[i+1])
        # print(a,b)
        ans *= max(gcd(a),gcd(b))
        break

print(ans)

Submission status: Wrong Answer

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

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

tmp = A[0]
for i in range(N):
    tmp = gcd(tmp, A[i])
    
    
for i in range(N):
    A[i] //= tmp
    
v1 = A[0]
for i in range(N):
    if i != 0:
        v1 = gcd(v1, A[i])
        
v2 = A[1]
for i in range(N):
    if i != 1:
        v2 = gcd(v2, A[i])
   

print(tmp * max(v1, v2))

Submission status: Wrong Answer

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

num = sorted(A)[1]
i = 0
while num > 0:
    tmp = [x for x in A if x % num == 0]
    if len(tmp) > 1:
        print(num)
        break
    else:
        num -= 1

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b,t = LI()
    k = t//a
    print(k*b)
    return

#B
def B():
    n = I()
    v = LI()
    c = LI()
    ans = 0
    for i in range(n):
        if v[i] > c[i]:
            ans += (v[i]-c[i])
    print(ans)
    return

#C
def C():
    def gcd(a,b):
        if a == 0:
            return b
        return gcd(b%a, a)
    n = I()
    a = LI()
    m = math.ceil(n**0.5)
    while len(a) < m**2:
        n += 1
        a.append(a[-1])
    f = [0 for i in range(m)]
    for i in range(m):
        b = a[m*i:m*(i+1)]
        g = b[0]
        for j in b[1:]:
            g = gcd(g,j)
        f[i] = g
    ans = 1
    for i in range(n):
        j = i//m
        c = f[:j]+f[j+1:]+a[m*j:i]+a[i+1:m*(j+1)]
        g = c[0]
        for k in c[1:]:
            g = gcd(g, k)
        ans = max(ans,g)
    print(ans)
    return

#D
def D():
    n = I()
    a = LI()
    k = 0
    for i in a:
        if i < 0:
            k += 1
    ans = 0
    m = float("inf")
    for i in a:
        ans += abs(i)
        m = min(m,abs(i))
    if k%2:
        ans -= 2*m
    print(ans)
    return


#Solve
if __name__ == "__main__":
    C()

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
fir = l[0]
sec = l[1]
lfir = []
for i in range(1,int(fir**.5)+2):
  if fir % i == 0:
    lfir.append(i)
    lfir.append(fir//i)
for i in range(1,int(sec**.5)+2):
  if sec % i == 0:
    lfir.append(i)
    lfir.append(fir//i)
ok = 1
lfir = sorted(list(set(lfir)))
for i in lfir:
  cnt = 0
  for j in l:
    if j%i:
      cnt += 1
  if cnt < 2:
    ok = i
print(ok)

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

print(gcd_num * max(gcd_b, gcd_b2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if N == 2:
    print(max(l))
    exit()
p = 0
ans = 1
flag = 0
element = gcd(l[0], l[1])
p = 1
element = max(gcd(l[0], l[2]),gcd(l[1], l[2]))
for i in range(2+p,N):
    tmp = gcd(element,l[i])
    if tmp == 1:
        if flag == 0:
            flag = 1
    else:
        element = tmp
print(element)

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

ans = []
n = ni()
li = na()
flag = 0
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    ans.append(fractions.gcd(li[0], li[1]))
    ans.append(fractions.gcd(li[1], li[2]))
    ans.append(fractions.gcd(li[2], li[0]))
    kouho = max(ans)
    for i in range(3,n):
        if li[i] % kouho == 0:
            continue
        else:
            kouho = min(ans)
            flag = 1
            break
    if flag == 0:
        print(kouho)
    else:
        for i in range(3,n):
            if li[i] % kouho == 0:
                continue
            else:
                print(1)
                break

Submission status: Wrong Answer

Solution code:
def hcf(x, y):
    if x > y:
        smaller = y
    else:
        smaller = x 
    for i in range(1,smaller + 1):
        if((x % i == 0) and (y % i == 0)):
            hcf = i
    return hcf

def blackbord(n,a):
    return hcf(max(a),min(a))
 
n = int(input())
a=list(map(int, input().split()))
print(blackbord(n,a))

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)
A[N - 1 - 1] = A[N-1]
#print(A)
list.append(gcd_list(A))

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
def divi(a, b):
    rem = b % a
    if rem == 0:
        return a
    else:
        return divi(rem, a)
A.sort()
all_d = A[0]
max_d = max(divi(A[0],A[1]), divi(A[0],A[2])) if N > 2 else A[1]
for i in range(1,N):
    all_d = divi(all_d, A[i])
    if max_d < all_d:
        max_d = all_d
print(max_d)

Submission status: Wrong Answer

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


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


if n <= 2:
    print(max(a))
else:
    a.sort()
    print(max(gcd(a[0], a[-1]), gcd(a[1], a[-1]), gcd(a[0], a[-2])))

Submission status: Wrong Answer

Solution code:
def check(ary, div):
    c = 0
    for i in range(len(ary)):
        if ary[i] % div == 0:
            c += 1
    if c >= len(ary) - 1:
        return True
    else:
        return False 

N = int(input())
data = list(map(int, input().split()))
ans = 1
for i in range(1, max(data) + 1):
    print(i)
    if check(data, i):
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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

def method(List):
    newList = []
    for x in range(0, len(List) // 2, 2):
        number = fractions.gcd(List[x],List[x+1])
        newList.append(number)
    if len(List) % 2 == 1:
        newList.append(List[-1])
    return newList

answer = 0
for x in range(N):
    newList = A.copy()
    newList.pop(x)
    while len(newList) > 1:
        newList = method(newList)
    answer = max(answer, newList[0])
    
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
vals = [int(x) for x in input().split(" ")]
vals.sort()
vals.reverse()

rewrite = False

minval = vals[0]
for b in vals[1:]:
    temp = minval
    a = minval
    
    rest = a % b
    while(rest):
        a = b
        b = rest
        rest = a % b
    minval = b
    if minval == 1:
        rewrite = True
        minval = temp
print(minval)

Submission status: Wrong Answer

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

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

if n>2:
  li=[0]*(n-1)
  
  cnt=0

  for i in range(n-1):
    li[i]=a[i]

  c=gcd(li[0],li[1])
  for i in range(n-2):
    ans=gcd(c,li[i])
  
  for i in range(n-1):
    for j in range(i):
      li[n-1-i]=a[n-i]
    c=gcd(li[0],li[1])
    for i in range(n-2):
      cnt=gcd(c,li[i])
      if cnt<ans:
        break
    if cnt>ans:
      ans=cnt
else:
  ans=max(a)

print(ans)

Submission status: Wrong Answer

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

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

tmp = A[0]
for i in range(N):
    tmp = gcd(tmp, A[i])
    
    
for i in range(N):
    A[i] //= tmp
   
a = A[0]
for i in range(N):
    if i != 0:
        v1 = gcd(a, A[i])
        
a = A[1]
for i in range(N):
    if i != 1:
        v2 = gcd(a, A[i])
   

print(tmp * max(v1, v2))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = sorted(A.copy(), reverse=True)

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

ansans = 0
for b in B:
    divs = make_divisors(b)

    ans = False
    for d in divs:
        count = 0
        for a in A:
            if a % d != 0:
                count += 1
                if count >= 2:
                    break
        if count < 2:
            ans = d
            break
    if ans:
        ansans = ans
        break

print(ansans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A = list(set(A))
def u(a, b):
        if b == 0:
                return a
        return u(b, a % b)

if len(A) <= 2:
        res = A[0]
else:
        res = -1
        for i in range(len(A)):
                tmp = list(A)
                tmp.pop(i)
                for k in range(len(tmp)-1):
                        tmp[k+1] = u(tmp[k], tmp[k+1])
                res = max(res, tmp[len(tmp)-1])
        if res == -1:
                res = tmp[0]

print(res)

Submission status: Wrong Answer

Solution code:
import fractions
# import math
from functools import reduce

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

n = int(input())
a = [int(value) for value in input().split(" ")]


a = sorted(a)

b = []
c = []

for value in a:
    if value % 2 != 0:
        b.append(value)
    else:
        c.append(value)

if len(b) == 0:
    a.remove(c[0])
    print(gcd_list(a))
else:
    a.remove(b[0])
    print(gcd_list(a))

Submission status: Wrong Answer

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


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


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


new_A = []
ans_box = []

for i in range(N):
    if i != N-1:
        new_A = A[:i] + A[i+1:]
    else:
        new_A = A[:i]


    if N == 2:
        ans_box.append(max(A[0], A[1]))
    else:
        temp = gcd(new_A[0], new_A[1])
        if len(new_A) == 2:
            ans_box.append(temp)
        else:
            for j in range(N-1):
                temp = gcd(temp, A[j])
            ans_box.append(temp)

print(max(ans_box))

Submission status: Wrong Answer

Solution code:
input();input();n=2;print(n)

Submission status: Wrong Answer

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

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

A.sort()
B = [int(2e9)] * int(1e5) 

check = int(2e9)
m = int(1e6)
for i in range(N):
    if i % 2== 0 and i + 1 < N:
        B[i] = gcd(A[i], A[i+1])
        if B[i] < m:
            check = i
            m = B[i]

check1 = int(2e9)

for i in range(N):
    if i == check:
        continue

    else:
        if check1 == int(2e9):
            check1 = A[i]
        else:
            check1 = gcd(check1, A[i])

check2 = int(2e9)
for i in range(N):
    if i == check+1:
        continue
    else:
        if check2 == int(2e9):
            check2 = A[i]
        else:
            check2 = gcd(check2, A[i])

print(max(check1, check2))

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
A = [int(_) for _ in input().split()]
gcd = lambda x, y: gcd(y, x % y) if x % y else y
g = list(itertools.accumulate(A, func=gcd))[-1]
ans = A[0]
for i in range(1, N):
    temp = gcd(ans, A[i])
    if temp == g:
        if i < N - 1:
            ans = gcd(ans, list(itertools.accumulate(A[i + 1:], func=gcd))[-1])
        break
    else:
        ans = temp
if ans == g:
    ans = list(itertools.accumulate(A[1:], func=gcd))[-1]
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

n = int(input())
A = [int(a) for a in input().split()]
A.sort()
ans = 1
for i in range(len(A)//2):
    B = A.copy()
    B.pop(i)
    _ = reduce(gcd, B)
    if _ > ans:
        ans = _
        
print(ans)

Submission status: Wrong Answer

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


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


if n <= 2:
    print(max(a))
else:
    a.sort()
    print(max(gcd(a[0], a[-1]), gcd(a[1], a[-1]), gcd(a[0], a[1])))

Submission status: Wrong Answer

Solution code:
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

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

N = I()
A = IL()

num = A[0]
for i in range(1,N):
    if A[i]%num == 0:
        continue
    else:
        num = gcd(num,A[i])

k = 1
while True:
    cnt = 0
    k += 1
    for i in range(N):
        if A[i]%(num*k) == 0:
            continue
        else:
            cnt += 1
        if cnt == 2:
            break
    else:
        continue
    k -= 1
    break

print(num*k)

Submission status: Wrong Answer

Solution code:
import copy

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

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


for i in range(N):
  B = copy.copy(A)
  tmp = gcd(B[0], B[1])
  B.pop(i)
  for i in range(N-2):
    tmp = gcd(B[i], B[i+1])
    B[i+1] = tmp
  ans = max(tmp, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
import  functools

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

N = int(input())
A = [int(x) for x in input().split()]
a2 = A.copy()
max = 0
for i,_ in enumerate(A):
    A.pop(i)
    temp = gcd(A)
    max = temp if temp >= max else max
    A = a2.copy()


print(max)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
if N == 2:
    print(max(A[0], A[1]))
    quit()


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


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


print(ans)

Submission status: Wrong Answer

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


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


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

    a, b = A[0], A[N-1]
    fa, fb = 1, 1
    for i in range(1, N):
        if gcd(a, A[i]) == tmp and fa:
            fa = 0
            continue
        else:
            a = gcd(a, A[i])

    for i in reversed(range(N-1)):
        if gcd(b, A[i]) == tmp and fb:
            fb = 0
            continue
        else:
            b = gcd(b, A[i])
    return max(a, b)


print(m())

Submission status: Wrong Answer

Solution code:
def div(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={int(i) for i in input().split()}
a=[int(i) for i in input().split()]
d={}
for i,j in enumerate(a):
    t=div(j)
    for k in t:
        if k in d and d[k]+1>=i:
            d[k]+=1
        elif i==0:
            d[k]=1
ans=1
for i in d:
    if d[i]+1>=n:
        ans=max(ans,i)
print(ans)

Submission status: Wrong Answer

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

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

if n>2:
  li=[0]*(n-1)
  
  cnt=0

  for i in range(n-1):
    li[i]=a[i]

  c=gcd(li[0],li[1])
  for i in range(n-2):
    ans=gcd(c,li[i])
  
  for i in range(n-1):
    for j in range(i):
      li[n-1-i]=a[n-i]
    c=gcd(li[0],li[1])
    for i in range(n-2):
      cnt=gcd(c,li[i])
    if cnt>ans:
      ans=cnt
else:
  ans=max(a)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A = list(set(A))
def u(a, b):
        if b == 0:
                return a
        return u(b, a % b)

if len(A) <= 2:
        res = A[0]
else:
        res = -1
        for i in range(len(A)):
                tmp = list(A)
                tmp.pop(i)
                for k in range(len(tmp)-1):
                        tmp[k+1] = u(tmp[k], tmp[k+1])
                res = max(res, tmp[len(tmp)-1])

print(res)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import fractions
from functools import reduce

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

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

ans = 1
A.sort()
gcd1 = gcd(A)
for i in range(N):
    A[i] //= gcd1

ans *= gcd1
cnt = 0
for i in range(N-2):
    if A[i+1] - A[i] == 1:
        cnt += 1
        if A[i+2]-A[i+1]==1:
            A.remove(A[i+1])
            # print(A)
            gcd2 = gcd(A)
            ans *= gcd2
            cnt = 2

    if cnt >= 2:
        break


print(ans)

Submission status: Wrong Answer

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

def lcm(a, b):
    return a*b//gcd(a,b)

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

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

Submission status: Wrong Answer

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

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

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

bad_id = 0
max_div = 1
for j in range(3):
    bid = bad_id
    init = False
    for i, item in enumerate(a):
        if i == bid:
            continue
        if not init:
            val = item
            div = val
            init = True
        else:
            val = gcd(div, item)
            if val != div:
                bad_id = i
                div = val
    max_div = max(div, max_div)
    
print(max_div)

Submission status: Wrong Answer

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

min=10000000000000000000
for i in range(N):
    if A[i] < min:
        min=A[i]

a = min
for i in range(min):
    cnt=0
    for i in range(N):
        if A[i] % a == 0:
            cnt+=1
        if cnt == len(A) or cnt == len(A)-1:
            print(a)
            quit()
    a -= 1

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)

element = gcd(A[0],A[1])

if N == 2:
    print(element)
else:
    for i in range(2,N):
        element + gcd(element,A[i])
    print(element)

Submission status: Wrong Answer

Solution code:
from functools import reduce
read = input
n = int(read())
A = list(map(int, read().split()))
def gcd(a, b):
#     print(a,b)
    if a > b:
        a,b = b,a
    return a if b %a ==0 else gcd(b%a, a)
def cal(ac, x):
    if len(ac) == 0:
        ac.append(x)
        return ac
    nxt = gcd(ac[-1], x)
    ac.append(nxt)
    return ac
A1 = list(reduce(cal, A, []))
A.reverse()
A2 = list(reduce(cal, A, []))
A2.reverse()
mx = 1
for i in range(n):
    if i == 0:
        mx =max(A2[ 1 ], mx)
        continue
    if i == n-1:
        mx = max(A1[ n-1 ], mx)
        continue
    nxt = gcd(A1[i-1], A2[i+1])
    mx = max(nxt, mx)
print(mx)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
minus = 1
ma = min(A)
if sum([a%2!=0 for a in A])>1:
    minus = 2
    if ma%2==0:
        ma -= 1
for i in range(ma):
    tof = [a%ma==0 for a in A]
    if sum(tof)>=N-1:
        print(ma)
        break
    ma -= minus
if ma <= 0:
    print(1)

Submission status: Wrong Answer

Solution code:
import functools
import fractions
N = int(input())
A = [int(x) for x in input().split()]
GCD = functools.reduce(fractions.gcd, A)
B = sorted([a // GCD for a in A], reverse=True)
gcd = B[0]
cancel = 1
for b in B[1:]:
  _gcd = fractions.gcd(gcd, b)
  if _gcd == 1 and cancel == 1:
    _gcd = gcd
    cancel = 0
  gcd = _gcd
print(GCD * gcd)