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

a = list(set(a))


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


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[-2]))
    print(ans)

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 and i!=0:
        flag1=1
    elif x<r1:
        r1=x
#usiro
r2=a[n-1]
flag2=0
for k in range(n-1):
    y=fractions.gcd(r2,a[n-k-2])
    if y<r2 and flag2==0 and k!=0:
        flag2=1
    elif y<r2:
        r2=y
print(max(r1,r2))

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


heapq.heappop(r)
ans=heapq.heappop(r)
if len(r)!=0:
  ans=heapq.heappop(r)

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
A = sorted([int(i) for i in input().split()])
e = []
o = []
for i, a in enumerate(A):
    if a % 2 == 0:
        e.append((a,i))
    else:
        o.append((a,i))

if len(e) == N or len(o) == N:
    A[0] = A[-1]
else:
    v,i = o[0]
    A[i] = e[-1][0]


from functools import reduce
print(reduce(lambda a, b: gcd(a, b), A))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int( input())
a = list(map(int, input().split()))

def m_ds(n):
    ds = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ds.append(i)
            if i != n // i:
                ds.append(n//i)

    return ds

h={}
nn=min(n,3)
for i in range(0,nn):
  l = m_ds(a[i])
  for j in range(0,len(l)):
    if l[j] in h:
      h[l[j]]=h[l[j]]+1
    else:
      h[l[j]]=1
k=list(h.keys())
k.sort(reverse=True)
for v in k:
  if h[v]>=(nn-1):
    print(v)
    break

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
A = set(map(int, input().split()))
A = sorted(list(A))


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


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

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

print(lo)

Submission status: Wrong Answer

Solution code:
def make_divisors(n,m):
    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)
    for i in range(1, int(m**0.5)+1):
        if m % i == 0:
            divisors.append(i)
            if i != m // i:
                divisors.append(m//i)

    divisors.sort()
    return divisors

N=int(input())

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

if len(Auniq)==1:
  print(Auniq[0])
  exit()

div=(make_divisors(Auniq[0],Auniq[1]))
div=list(set(div))
div.sort(reverse=True)
if len(Auniq)<=2:
  print(div[0])
  exit()
for i in div:
  count=0
  for a in Auniq[2:]:
    if a%i!=0:
      count+=1
    if count==2:
      break
  if count==0 or (count==1 and Auniq[0]%i==0 and Auniq[1]%i==0):
    print(i)
    exit()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

if n == 2:
    print(max(a))
else:
    g1 = sorted([gcd(d, a[0]) for d in a[1:]])[1]
    g2 = sorted([gcd(d, a[-1]) for d in a[:-1]])[1]
    print(max([g1, g2]))

Submission status: Wrong Answer

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

if N > 2:
    a.sort()
    diff = []
    for i in range(N-1):
        diff.append(a[i+1]-a[i])
    index = diff.index(min(diff))
    diff_ = diff[:]
    if index > 0:
        plus = diff[index-1] + diff[index]
        diff_[index-1] = plus
        diff_[index] = plus
    GCD = diff_[0]

    for i in range(N-1):
        GCD = gcd(diff_[i], GCD)

    if index < N-1:
        plus = diff[index] + diff[index+1]
        diff[index] = plus
        diff[index+1] = plus
    GCD2 = diff[0]
    for i in range(N-1):
        GCD2 = gcd(diff[i], GCD2)
    print(max(GCD, GCD2))
else:
    print(max(a))

Submission status: Wrong Answer

Solution code:
import collections
import fractions
from functools import reduce

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

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

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

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

divs = []

for i in range(n):
    divs.extend(make_divisors(a[i]))

c = collections.Counter(divs)

c = list(c.items())
c.sort(key=lambda x: x[1], reverse=True)

# print(c)

ansgcd = []
for x in c:
    if x[1] == n:
        ansgcd.append(x[0])
    elif x[1] == n-1:
        ansgcd.append(x[0])
        break
    else:
        break

print(lcm_list(ansgcd))

Submission status: Wrong Answer

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

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

g = [None] * N
grev = [None] * N
g[0] = A[0]
grev[-1] = A[-1]
for i in range(1, N):
    g[i] = gcd(g[i-1], A[i])
    grev[-1-i] = gcd(grev[-1], A[-1-i])
maxgcd = max(grev[1], g[N-2])
for i in range(1, N-1):
    maxgcd = max(maxgcd, gcd(g[i-1], grev[-i]))
print(maxgcd)

Submission status: Wrong Answer

Solution code:
from fractions import gcd  # in math module python >= 3.5
from functools import reduce


def gcdall(numlist):
    return reduce(gcd, numlist)


def main():
    _ = int(input())
    a = list(map(int, input().split()))
    if len(a) < 3:
        print(max(a))
        return

    a = list(set(a))
    if len(a) < 3:
        print(max(a))
        return

    gcds = []
    for i in range(len(a)):
        excepted = [a[j] for j in range(len(a)) if j != i]
        b = 0
        while all([k % 2 == 0 for k in excepted]):
            b += 1
            excepted = [k // 2 for k in excepted]

        if b > 0:
            gcds.append(gcdall(excepted) * 2 * b)
        else:
            gcds.append(gcdall(excepted))
    print(max(gcds))


main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
mae = [a[0]]
for i in range(n-1):
    mae.append(gcd(mae[i],a[i+1]))
ushiro = [a[n-1]]
for i in range(n-1):
    ushiro.append(gcd(ushiro[i],a[n-i-1]))

ans = ushiro[n-1]
for i in range(n-1):
    if i != n-2:
        ans = max(ans,gcd(mae[i],ushiro[n-i-3]))
    else:
        ans = max(ans,mae[n-1])

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())
a=list(map(int, input().split()))
crt_gcd=a[0]
cng=-1
for i, ai in enumerate(a):
  gcdi = gcd(crt_gcd, ai)
  if gcdi<crt_gcd:
    cng=i-1
    crt_gcd=gcdi

crt_gcd=73513440
for i, ai in enumerate(a):
  if i!=cng and i!=cng+1:
    gcdi = gcd(crt_gcd, ai)
    if gcdi<crt_gcd:
      crt_gcd=gcdi

print(max(gcd(crt_gcd, a[cng]), gcd(crt_gcd, a[cng+1]), gcd(a[cng], a[cng+1])))

Submission status: Wrong Answer

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

def gcd_lis(l):
    res = 0
    for i in range(len(l)-1):
        if i == 0:
            res = gcd(l[i],l[i+1])
        else:
            res = gcd(res,l[i+1])
    return res

n = int(input())
lis = list(map(int,input().split()))
tup = tuple(lis)

reslis = []
for i in range(n):
    tmp = copy.deepcopy(lis)
    del tmp[i]
    reslis.append(gcd_lis(tmp))
print(max(reslis))

Submission status: Wrong Answer

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

def listGCD(listA):
    lenList = len(listA)
    ans = 0
    for i in range(lenList - 1):
        for j in range(i + 1, lenList):
            ans = max(ans, fractions.gcd(A[i], A[j]))
    return ans

if N == 2:
    print(max(A))
else:
    print(listGCD(A))

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
n = int(input())
a = list(map(int,input().split()))
li = []
li2 = []
for i in range(n-1):
    li.append(gcd(a[i],a[i+1]))
for i in range(n-2):
    li2.append(gcd(a[i],a[i+2]))
li = set(li)  | set(li2)
ans = max(li)
print(ans)

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 = list(map(int, input().split()))
ans = []
for i in range(N-1):
    b = gcd(a_list[i], a_list[i+1])
    ans.append(b)
if N > 2:
    b = gcd(a_list[0], a_list[N-1])
    ans.append(b)
if N == 2:
    print(max(a_list))
else:
    ans.sort()
    print(ans[2])

Submission status: Wrong Answer

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

N = int(input())
A = [int(i) for i in input().split()]
gc = gcd_list(A)
current = A[0]
for i in range(N):
    current = fractions.gcd(current,A[i])
    if(gc==current):
        break
A.pop(i)
print(gcd_list(A))

Submission status: Wrong Answer

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


def g():
  n = int(input())
  vs = list(map(int, input().split()))
  
  ss = 0
  tt = 0
  c = 0
  for i, v in enumerate(vs):
    if ss:
      s = gcd(ss, v)
      if tt > s:
        tt = s
        c = 1
      elif tt == s:
        c += 1
      else:
        ss = s
    else:
      ss = v
      tt = v
      mi = i
  from functools import reduce
  r = reduce(gcd, vs[1:])
  ss = tt if c > 1 else ss
  return max(r, ss)
  
print(g())

Submission status: Wrong Answer

Solution code:
import sys
# import bisect
# import math
# import itertools
# import numpy as np
# import collections
import functools
import fractions
"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

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


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e, p = range, enumerate, print
    ip = IP()
    id = Idea()
    mod = 10 ** 9 + 7

    """この下から書いてね"""
    n = ip.I()
    ans = 0
    a = ip.IL()
    for i in r(n-1):
        o = a
        o[i] = a[i+1]
        gcd = functools.reduce(fractions.gcd, o)
        ans = max(gcd, ans)
    p(ans)



main()

Submission status: Wrong Answer

Solution code:
import numpy as np

def wa(rist, num):
  R = []
  for j in range(len(rist)):
    R.append(rist[j] // (num + 1))
  c = [i for i in R if i == 0]
  if len(c) <= 1:
    return 0
  else:
    return 1
    

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

num = 0

for i in range(np.max(A)):
  me = wa(A, i)
  if me == 0:
    num = i
  else:
    pass
  
print(num)

Submission status: Wrong Answer

Solution code:
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

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

B = A.copy()
C = list()
cnt = 0

for n in range(N):
  del A[n]
  for j in range(N-2):
    if cnt < gcd(A[j], A[j+1]):
      cnt = gcd(A[j], A[j+1])
  C.append(cnt)
  A = B.copy()
  
ans = max(C)

print(ans)

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)
#  print(B)
  tmp = gcd(min(B), max(B)) 
#  for i in range(N-2):
#    tmp = gcd(B[i], B[i+1])
#    B[i+1] = tmp
#    print(tmp)
  ans = max(tmp, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
A = list(set(a))
ans = []

if len(A) == 1:
    print(A[0])
    exit()
for i in A:
    b = sorted(A)
    b.remove(i)
    ans.append(reduce(gcd, b))

print(max(ans))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

S = sum(A)
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
ans = []
tmp = 0
tmp_i = 0
for i, x in enumerate(A):
	if tmp < gcd(S, S-x):
		tmp = gcd(S, S-x)
		tmp_i = i
A.pop(tmp_i)
# print(A)
print(gcd(sum(A),min(A)))

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
  b = max(x, y)
  s = min(x, y)
  r = b % s
  while r != 0:
    b = s
    s = r
    r = b % s
  return s

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

ma = 0
L = [[]] * N
all = gcd(A[0], A[1])
L[1] = [A[0], A[1]]

for i in range(2, N):
  t = [all]
  k = gcd(all, A[i])
  if k not in t:
    t.append(k)
  for j in L[i - 1]:
    k = gcd(j, A[i])
    if k not in t:
      t.append(k)
  L[i] = t

Ans = max(L[-1])
print(Ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


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


def solve(n, a):
    if n == 2 and a[0] == a[1]:
        return a[0]
    n_dict = defaultdict(int)
    for i in range(len(a)):
        for j in range(len(list(a)) - i + 1):
            n_dict[gcv(a[i], a[j + i - 1])] += 1
    return sorted(n_dict.items(), key=lambda x: x[0])[1][0]


def input_from_console():
    n = int(input())
    a = list(map(int, input().split()))
    return n, a


def main():
    n, a_list = input_from_console()
    print(solve(n, a_list))


if __name__ == "__main__":
    main()

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)
    f = [0 for i in range(m)]
    for i in range(m):
        b = a[m*i:min(n,m*(i+1))]
        if b:
            g = b[0]
            for j in b[1:]:
                g = gcd(g,j)
        else:
            g = 1
        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:min(n,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:
from fractions import gcd

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

if n == 2:
  print(max(A))
else:
    min0, min1 = 10 ** 9 + 1, 10 ** 9 + 1
    for i in range(n):
        mm0, mm1 = 10 ** 9 + 1, 10 ** 9 + 1
        for j in range(n):
            if i == j:
                continue
            g = gcd(A[i], A[j])
            if g < mm0:
                mm0, mm1 = g, mm0
            elif g < mm1:
                mm1 = g
        if mm1 < min0:
            min0, min1 = mm1, min0
        elif mm1 < min1:
            min1 = mm1

    print(min1)

Submission status: Wrong Answer

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

rewrite = False

minindex = 0

minval = vals[0]
for b in vals[1:]:
    temp = b
    a = minval
    tempmin = minval
    
    rest = a % b
    while(rest):
        a = b
        b = rest
        rest = a % b
    minval = b
    if minval < tempmin:
        minindex = temp

minval = vals[0]
for b in vals[1:]:
    if b == minindex:
        continue
    a = minval
    
    rest = a % b
    while(rest):
        a = b
        b = rest
        rest = a % b
    minval = b

print(minval)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    a,b=sorted([a,b])
    while b%a!=0:
        a,b=b%a,a
    return a
n=int(input())
a=list(map(int, input().split()))
if(n==2):
    print(max(a))
    quit()
ans1=gcd(a[0],a[1])
ans2=gcd(a[1],a[2])
ans3=gcd(a[0],a[2])
for i in range(3,n):
    ans1=gcd(ans1,a[i])
    ans2=gcd(ans2,a[i])
    ans3=gcd(ans3,a[i])
print(max(ans1,ans2,ans3))

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
A_arr = list(map(int, input().split()))

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

gcd_list = []

if N == 2:
    print(max(A_arr))
    sys.exit()

for i in range(1, N):
    gcd_list.append(gcd(A_arr[0],A_arr[i]))


min_gcd = min(gcd_list)
gcd_list.remove(min_gcd)

if min_gcd in gcd_list:
    ans = 100000000000
    for i in range(2, N):
        ans = min(ans,gcd(A_arr[1],A_arr[i]))
else:
    ans = min(gcd_list)

print(ans)

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())),[]
#no,mi=a[0],a[0]
for i in range(1,n):
  b.append(gcd(a[i-1],a[i]))
b.sort()
if n==2:print(gcd(a[0],a[1]))
elif n==3:print(min(gcd(a[0],a[2]),b[1]))
else:print(b[2])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys

from collections import Counter
from collections import defaultdict

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


def factor(x):
    factors = Counter()
    while x % 2 == 0:
        factors[2] += 1
        x //= 2
    for i in range(3, x + 1, 2):
        while x % i == 0:
            factors[i] += 1
            x //= i
        if x == 1:
            break
    assert x == 1
    return factors


af = [factor(x) for x in a]
primes = {p for afi in af for p in afi.keys()}

gcd = 1
npr = defaultdict(lambda: 1)

for p in primes:
    minr = min(afi[p] for afi in af)
    gcd *= p ** minr
    indices = [i for i, afi in enumerate(af) if afi[p] == minr]
    if len(indices) != 1:
        continue
    index = indices[0]
    nminr = min(afi[p] for i, afi in enumerate(af) if i != index)
    npr[index] *= p ** nminr

if len(npr) != 0:
    print(gcd * max(npr.values()))
else:
    print(gcd)

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])
if ptn0!=ptn1:
  print(max(ptn0,ptn1))
else:
  ptn2 = gcd(A[0],A[1])
  ptn = []
  for i in range(1,int(pow(ptn2,0.5))+1):
    if ptn2%i==0:
      ptn.append(i)
  ptn.sort(reverse=True)
  for p in ptn:
    count = 0
    for a in A:
      if a%p!=0:
        count+=1
      if count>1:
        break
    if count==1:
      print(p)
      break

Submission status: Wrong Answer

Solution code:
from fractions import gcd  # in math module python >= 3.5
from functools import reduce


def gcdall(numlist):
    return reduce(gcd, numlist)


def main():
    _ = int(input())
    a = list(set(map(int, input().split())))
    if len(a) < 3:
        print(max(a))
        return

    gcds = []
    for i in range(len(a)):
        excepted = [a[j] for j in range(len(a)) if j != i]
        b = 0
        while all([k % 2 == 0 for k in excepted]):
            b += 1
            excepted = [k // 2 for k in excepted]

        if b > 0:
            gcds.append(gcdall(excepted) * 2 * b)
        else:
            gcds.append(gcdall(excepted))
    print(max(gcds))


main()

Submission status: Wrong Answer

Solution code:
import sys
import fractions
from functools import reduce
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
n = ni()
a = nl()
maxx = gcd_list(a)
for i in range(n - 1):
    if fractions.gcd(a[i], a[i + 1]) == maxx:
        ans = max(gcd_list(a[:i] + a[i + 1:]), gcd_list(a[:i + 1] + a[i + 2:]))
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = []
        for i in range(2, int(math.sqrt(m)) + 1):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False

    def is_prime(self, n):
        return self.A[n]

    def division(self, n):
        d = collections.defaultdict(int)
        for c in self.T:
            while n % c == 0:
                d[c] += 1
                n //= c
            if n < 2:
                break
        if n > 1:
            d[n] += 1
        return d.items()

    def sowa(self, n):
        r = 1
        for k,v in self.division(n):
            t = 1
            for i in range(1,v+1):
                t += math.pow(k, i)
            r *= t
        return r


def main():
    n = I()
    a = set(LI())
    l = len(a)
    m = max(a)
    lm = m // l * 10
    pr = Prime(10**9)
    p = collections.defaultdict(int)

    for b in a:
        r = [1]
        for k, v in pr.division(b):
            for c in r[:]:
                for i in range(1,v+1):
                    t = c*(k**i)
                    if t > lm:
                        break
                    r.append(t)
        for k in r:
            p[k] += 1
    r = 1
    for k,v in p.items():
        if v >= n-1 and r < k:
            r = k

    return r


print(main())

Submission status: Wrong Answer

Solution code:
import itertools
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=-100
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
for i in  list(itertools.permutations(A, N-1)):
    c=0
    for a in i:
        if c==0:
            tmp=a
            c+=1
        tmp1=gcd(a,tmp)
    ans=max(tmp1,ans)
print(ans)

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(1,N):
    if i == 1:
        g = fractions.gcd(A[0],A[i])
    else:
        g = fractions.gcd(g,A[i])
    ans.append(g)

    

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

# 一番小さい数字以下で割って、割れなかったものを…？

a = min(A)
m = 0;
for i in range(a, 0, -1):
    # print("i ="+str(i))
    n = 0
    # 2個割り切れなかったら次の数字へ
    for j in range(len(A)):
        if A[j]%i != 0:
            # print("j"+str(j))
            if n == 1:
                n = 2
                break
            n = 1
    if n <= 1:
        m = i
        break
print(i)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=(input()).split()
A=[]
for i in(a):
  A.append(int(i))
A.sort()
A.append(A[0])
GCD=[]
if(len(A)==2):
  for i in range(A[0],0,-1):
    if(A[0]%i==0 and A[1]%i==0):
      GCD.append(i)
      break
else: 
  for i in range(len(A)-1):
    for j in range(A[i],0,-1):
      if(A[i]%j==0 and A[i+1]%j==0):
        GCD.append(j)
        break
GCD.sort(reverse=True)

print(GCD[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
counter = {}
max_count = 0


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


for i in range(n):
    for j in make_divisors(a[i]):
        counter[j] = counter[j] + 1 if j in counter else 1
        max_count = max(max_count, counter[j])

counter = {k: v for k, v in counter.items() if v == max_count}

print(max(counter))