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 = sorted([int(i) for i in input().split()])
ma = A[0]
for i in range(ma):
    tof = [a%ma==0 for a in A]
    if sum(tof)>=N-1:
        break
    ma = int((ma+1)//2)
print(ma)

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) 
N = int(input()); A = input().split(" ");
ret = 0
for i in range(N-1):
  for j in range(i+1, N):
    ret = max(ret, gcd(int(A[i]), int(A[j])))
print(ret)

Submission status: Wrong Answer

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

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
ans = 0
for i in range(N):
  tmp = A[:]
  tmp.pop(i)
  ans_ = gcd(max(tmp),min(tmp))
  if ans_ > ans:
    ans = ans_
print(ans)

Submission status: Wrong Answer

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


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


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


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


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:
import fractions 
from functools import reduce
import copy

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

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

a.sort(reverse=True)
tmp_a = copy.deepcopy(a)
tmp_a.pop(0)
result = gcd_list(tmp_a)

for i in range(1, n):
    tmp_a = copy.deepcopy(a)
    tmp_a.pop(i)
    tmp = gcd_list(tmp_a)
    if(result < tmp):
        result = tmp
        break

print(result)

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:]
    print(a)
    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:
import fractions
def main():
    N = int(input())
    *A, = map(int, input().split())
    A.sort()
    gcds = []
    for i in range(1,N):
        gcds.append(fractions.gcd(A[0],A[i]))
    gcds.sort()
    if len(gcds) == 1:
        print(max(A))
    elif gcds[0] == gcds[1]:
        print(gcds[0])
    elif gcds[0] != gcds[1]:
        print(gcds[1])
main()

Submission status: Wrong Answer

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


def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g

n = int(input())

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

gcdf = gcd_core(a[0],a[1])

for i in range(n):
    if a[i] % gcdf == 0:
        continue
    else:
        gcdf = gcd_core(a[i],gcdf)

if n==2:
    print(max(a))
elif n == 3:
    for i in range(n):
        a[i] = a[i]//gcdf
    kouho = a[0]
    count = 0
    for i in range(n):
        if a[i] % kouho != 0:
            temp = gcd_core(a[i],kouho)
            if temp == 1:
                count += 1
                if count > 1:
                    kouho = 1
                    break
                else:
                    continue
            else:
                kouho = temp
        else:
            continue
    kouho2 = a[1]
    count = 0
    for i in range(n):
        if a[i] % kouho2 != 0:
            temp = gcd_core(a[i], kouho2)
            if temp == 1:
                count += 1
                if count > 1:
                    kouho2 = 1
                    break
                else:
                    continue
            else:
                kouho2 = temp
        else:
            continue
    print(gcdf*max(kouho,kouho2))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
A = [int(i) for i in input().split()]
g = A[0]
mini_index_1 = 0
mini_index_2 = 0
glist = [0]
for i in range(N):
    ng = gcd(g, A[i])
    if ng < g:
        mini_index_1 = i
        mini_index_2 = i-1
        g = ng
        glist.append(i)
# print(mini_index_1)

ans = 1
gcddd = 0

for gindex in glist:
    gcddd = 0
    for i in range(N):
        if gindex == i:
            continue
        else:
            if gcddd == 0:
                gcddd = A[i]
            else:
                gcddd = gcd(gcddd, A[i])
    print(gcddd, A[i], ans)
    ans = max(ans, gcddd)
print(ans)

Submission status: Wrong Answer

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

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

for i in range(n):
    for j in range(n):
        if(i != j):
            e=gcd(a[i],a[j])
            if(e > d):
                d = e
        else:
            continue
print(e)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import math
from collections import Counter
INF = float("inf")


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


def GCDs(*a):
    # リストで入力しないよう注意。
    if len(a) == 0:
        return -1  # エラー

    if len(a) == 1:
        return a[0]

    res = a[0]
    for i in range(1, len(a)):
        res = GCD(res, a[i])
    return res


def solve(N: int, A: "List[int]"):
    b = A[0]
    m = INF
    mi = -1
    for i in range(len(A)):
        g = GCD(A[i], b)
        if m > g:
            m = g
            mi = i

    buf = None
    for i in range(len(A)):
        if mi == i:
            continue
        if buf is None:
            buf = A[i]
        else:
            buf = GCD(buf, A[i])
    print(max([buf, GCDs(*A[1:])]))
    # print(g)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import numpy as np
N = int(input())
A = list(map(int, input().split()))

min_a = min(A)
c = 0
for i in range(1,min_a)[::-1]:
    for a in A:
        if a%i == 0:
            c += 1
    if c == N - 1 or c == N:
        print(i)
        break
    c = 0

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):
    d = divi(all_d, A[i])
    max_d = divi(max_d, A[i])
    if max_d < all_d:
        max_d = all_d
    all_d = d
print(max_d)

Submission status: Wrong Answer

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


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


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

a = get(al[0], al[1:])
b = get(al[1], [al[0]] + al[2:])

if a is None:
    print(b)
elif b is None:
    print(a)
else:
    print(max(a, b))

Submission status: Wrong Answer

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

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

for i in range(n-1):
    cnt.append(gcd(a[i],a[i+1]))
cnt.append(gcd(a[0],a[n-1]))

while 1:
    tmp = max(cnt)
    if cnt.count(tmp)>=len(cnt)-2:
        print(tmp)
        break
    else:
        cnt = [i for i in a if i != tmp]

Submission status: Wrong Answer

Solution code:
import fractions


def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    sortedA = sorted(A)
    minNum = min(A)

    gcd_list = []
    for i in range(N):
        gcd_list.append(fractions.gcd(minNum, sortedA[i]))

    gcd_list = sorted(gcd_list)
    print(max(gcd_list[0], gcd_list[1]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
if n==2:
    print(max(a[0],a[1]))
    exit()
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
g = gcd(max(a[0],a[1]),min(a[0],a[1]))
ind = [0,1]
for i in range(1,n):
    tmp = gcd(max(g,a[i]),min(g,a[i]))
    if tmp<g:
        ind = [i-1,i]
    g = tmp
import copy
a1,a2 = copy.copy(a),copy.copy(a)
del a1[ind[0]]
del a2[ind[1]]
g1=a1[0]
g2=a2[0]
for i in range(n-1):
    g1 = gcd(max(g1,a1[i]),min(g1,a1[i]))
    g2 = gcd(max(g2,a2[i]),min(g2,a2[i]))
print(max(g1,g2))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted([int(i) for i in input().split()])
ma = A[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)
print(ma)

Submission status: Wrong Answer

Solution code:
import functools
import fractions

N = int(input())
a_list = list(map(int, input().split()))
gcd_list = []
for i in range(N):
    copied = a_list
    copied[i] = 1
    gcd = functools.reduce(fractions.gcd, copied)
    gcd_list.append(gcd)

print(max(gcd_list))

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()))
ans = 0
for i in range(N):
    X = A[:]
    X.pop(i)
    g = gcd(max(X), min(X))
    if g >= ans:
        ans = g
print(ans)

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=1
init=1
#maxa=99999999999999999999999999
#maxa=A[1]
B=[]
for i in A:
    if init==1:
        a=i
        init=0

    a=gcd(a,i)
    B.append(a)
#print(B)
removenum=min(enumerate(B), key=lambda x: x[1])[0]
#print(a)
init=1

#両はし
for num,i in enumerate(A):
    if num==removenum:
        continue
    if init==1:
        a=i
        init=0
    a=gcd(a,i)
#print(a)

init=1
for num,i in enumerate(A):
    if num==0:
        continue
    if init==1:
        b=i
        init=0
    b=gcd(b,i)

init=1
for num,i in enumerate(A):
    if num==len(A)-1:
        continue
    if init==1:
        c=i
        init=0
    c=gcd(c,i)

print(max(a,b,c))

Submission status: Wrong Answer

Solution code:
import fractions

N=int(input())
A=list(map(int,input().split()))
a1=[]
a2=[]
for i in range(N-1):
    a1+=[fractions.gcd(A[N-1], A[i])]
    a2+=[fractions.gcd(A[0], A[i+1])]
a1.sort()
a2.sort()

if N>2:
    print(max(a1[1],a2[1]))
elif N==2:
    print(max(A))

Submission status: Wrong Answer

Solution code:
import sys
import math
import fractions

sys.setrecursionlimit(10000)
INF = float('inf')


def inp():
    return int(input())


def inl():
    return list(map(int, input().split()))


def inls():
    return input().split()


def Yesif(cond):
    print('Yes' if cond else 'No')


def YESIF(cond):
    print('YES' if cond else 'NO')


def yesif(cond):
    print('yes' if cond else 'no')


N = inp()
A = inl()

ans = set()
ans.add(A[1])
gcd = A[0]
for i, a in enumerate(A):
    if i == 0:
        continue
    new_gcd = fractions.gcd(gcd, a)
    if new_gcd < gcd:
        ans.add(gcd)

    news = set()
    for ss in ans:
        news.add(fractions.gcd(ss, a))
    ans = news

print(max(ans))

Submission status: Wrong Answer

Solution code:
from sys import exit
def gcd(a,b):#greatest common divisor
    if (a<b):
        a,b = b,a
    while(b>0):
        a,b = b ,a%b
    return a
N = int(input())
A = [int(n) for n in input().split()]
gcds = {}
for i in range(1,N):
    g = gcd(A[0],A[i])
    if(g in gcds):
        gcds[gcd(A[0],A[i])]+=1
    else:
        gcds[gcd(A[0],A[i])]=1
for i in range(N-2,-1,-1):
    g = gcd(A[-1],A[i])
    if(g in gcds):
        gcds[gcd(A[-1],A[i])]+=1
    else:
        gcds[gcd(A[-1],A[i])]=1
ans = sorted(list(gcds.keys()))
if(len(ans) == 1):
    print(ans[0])
else:
    print(ans[1])

# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())
# exit()

Submission status: Wrong Answer

Solution code:
inputs = [input() for i in range(2)]
N = int(inputs[0])
A = inputs[1].split()
A = [int(i) for i in A]

yakusuu = []
for i in range(1,max(A)+1): 
    amari = [a % i for a in A]
    if sum(amari) == 0:
        yakusuu.append(i)

print(max(yakusuu))

Submission status: Wrong Answer

Solution code:
import itertools

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

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

ans = 0
lst = []
for v in itertools.combinations(A, 2):
    lst.append(gcd(v[0], v[1]))
print(max(lst))

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
    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(c*(k**i))
        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:
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):
    d = divi(all_d, A[i])
    max_d = divi(max_d, A[i])
    if max_d < d:
        max_d = all_d
    all_d = d
print(max_d)

Submission status: Wrong Answer

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

min=10000000000000000000
cnt=0
for i in range(N):
    if A[i] < min:
        cnt+=1
    if cnt == N-1:
        min=A[i]

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

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] % ans[2] == 0:
            continue
        else:
            ans.remove(max(ans))
            kouho = max(ans)
            flag = 1
            break
    if flag == 0:
        print(kouho)
    else:
        flag = 0
        for i in range(3,n):
            if li[i] % kouho == 0:
                continue
            else:
                ans.remove(max(ans))
                kouho = max(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:
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
    elif i == n-1:
        mx = max(A1[ n-1 ], mx)
        continue
    else: # i < n-1 && i > 0
        nxt = gcd(A1[i-1], A2[i+1])
        mx = max(nxt, mx)
print(mx)
# A1, A2

Submission status: Wrong Answer

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split(" ")))
x = []
for i in range(n):
    for j in range(i+1, n):
        x.append(fractions.gcd(a[i], a[j]))
print(max(x))

Submission status: Wrong Answer

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


n = int(input())  # ���l
a = list(map(int, input().split()))  # �������l�����X�g�Ɋi�[

li = []
for i in range(n - 1):
    li.append(gcd(a[i], a[i + 1]))

    if (n - 2) != i and n != 2:
        li.append(gcd(a[i], a[i + 2]))

li.sort()
if(n != 2):
    print(li[2])
else:
    print(li[0])

Submission status: Wrong Answer

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


N = int(input())
A = input().split()

gcd_max = 0
for i in range(N):
    if i==0 and N>2: 
        first=int(A[1])
        second=int(A[2])
        start = 3
    elif i==1 and N>2:
        first=int(A[0])
        second=int(A[2])
        start = 3
    else:
        first=int(A[0])
        second=int(A[1])
        start = 2
    gcd_tmp = gcd(first,second)
    for j in range(N):
        if i!=j:
            gcd_tmp = gcd(gcd_tmp,int(A[j]))
    if gcd_max<gcd_tmp:
        gcd_max=gcd_tmp

print(gcd_max)

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)
g = gcd(max(a[0],a[1]),min(a[0],a[1]))
ind = [0,1]
for i in range(1,n):
    tmp = gcd(max(g,a[i]),min(g,a[i]))
    if tmp<g:
        ind = [i-1,i]
    g = tmp
import copy
a1,a2 = copy.copy(a),copy.copy(a)
del a1[ind[0]]
del a2[ind[1]]
g1=a1[0]
g2=a2[0]
for i in range(n-1):
    g1 = gcd(max(g1,a1[i]),min(g1,a1[i]))
    g2 = gcd(max(g2,a2[i]),min(g2,a2[i]))
print(max(g1,g2))

Submission status: Wrong Answer

Solution code:
import fractions
n=int(input())
a=list(map(int,input().split()))
#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 sys
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()
    ans = max(gcd(a[0], a[-1]), gcd(a[1], a[-1]), gcd(a[0], a[-2]))
    for e in a:
        if e % ans != 0:
            print(1)
            sys.exit()
        else:
            continue
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
mini = int(min(li))
maxim = int(max(li))
ans = int(maxim - mini)
if(mini == maxim):
    print(maxim)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

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

    tmp = gcd_list(a)
    ans = 0
    for i in range(n):
        a_ = a.copy()
        a_.pop(i)
        res = gcd_list(a_)
        if  tmp != res:
            print(res)
            break

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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


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

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

print(lo)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
a = list(map(int,input().split()))
for i in range(1, 10**9):
  count = 0
  for j in range(len(a)):
    if a[j] % i != 0:
      count += 1
      index = j
  if count == 1:
    ans_list = []
    for m in range(len(a)):
      if m != index:
        ans_list.append(a[m])
    for n in range(1, 10**9):
      count_b = 0
      for u in range(len(ans_list)):
        if ans_list[u] % n != 0:
          count_b += 1
        if count_b !=0:
          print((n-1)*j)
          sys.exit()

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
  for i, v in enumerate(vs):
    if ss:
      s = gcd(ss, v)
      if tt > s:
        tt = s
      else:
        ss = s
    else:
      ss = v
      tt = v
      mi = i
  from functools import reduce
  r = reduce(gcd, vs[1:])
  return max(r, ss)
  
print(g())

Submission status: Wrong Answer

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

MAX_A = 10**9

num = 1

for i in range(max(A)//2, 1, -1):
    c = 0
    for j in range(N):
        if A[j] % i == 0:
            c += 1
    if c == N:
        num = i
        break
    elif c == N-1:
        num = i
        break


print(num)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
def GCD(x,y):
	if x>y:
		a=x
		b=y
	else:
		a=y
		b=x
	while(True):
		c=a%b
		if c==0:
			return b
		else:
			a,b=b,c

B=[]
C=[]
a0=A[0]
a1=A[1]
for aa in A[1:]:
	B.append(GCD(aa,a0))
for aa in A[2:]:
	C.append(GCD(a1,aa))
B.sort()
C.sort()
if N==2:
	print(max(A))
else:
	if GCD(a0,a1)<C[0]:
		print(C[0])
	else:
		print(B[1])

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array([int(x) for x in input().split(' ')])

m = sorted(A)[1]

while True:
    tmp = A % m
    if sum(tmp != 0) < 2:
        break
    m = max(tmp)

print(m)

Submission status: Wrong Answer

Solution code:
def main():
    input = sys.stdin.readline
    try:
        n = int(input())
        a = list(map(int, input().split()))
        print(max(a) % min(a))
    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

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

import copy
from functools import reduce

def gcd(numbers):
    def pair_gcd(a,b):
        if a < b:
            a, b = b, a
        if b == 0:
            return a
        c = a % b
        return pair_gcd(b, c)
    return reduce(pair_gcd, numbers)

max_gcd = 1
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:
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())
at=[int(i) for i in input().split()]
a=set(at)
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:
    x=0
    for j in at:
        if j%i: x+=1
    if x<2: ans=max(ans,i)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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


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

  
num1 = A[0] 
gcd = find_gcd(num1, num1) 
  
for i in range(1, len(A)): 
    gcd = find_gcd(gcd, A[i]) 
print(gcd*(n - 1))

Submission status: Wrong Answer

Solution code:
#coding: utf-8
from fractions import gcd
#from math import gcd
N = int(input())
A = list(map(int, input().split()))
A.sort()
l = []
for i in range(N-1):
    l.append(gcd(A[i], A[i+1]))
l.append(gcd(A[0], A[-1]))
l = list(set(l))
l.sort()
print(l[1] if len(l) > 1 else l[0])

Submission status: Wrong Answer

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


n = int(input())
a_lst = list(map(int,input().split()))
cnt = 0
max_n = max(a_lst)
min_n = min(a_lst)
if max_n % 2 != 0 and min_n % 2 == 0:
    a_lst[a_lst.index(max_n)] += 1
    cnt += 1
if min_n % 2 != 0 and max_n % 2 == 0:
    min_n += 1
    cnt += 1
ans = gcd(max(a_lst),min(a_lst))

for a in a_lst:
    if a%ans != 0:
        cnt += 1
    if cnt > 1:
        print(ans)
        print(1)
        exit()
print(ans)

Submission status: Wrong Answer

Solution code:
def hcf(x, y): 
    for i in range(1,min(x,y) + 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 sys
sys.setrecursionlimit(pow(10, 6))

n = int(input())
alist = list(sorted(map(int, input().split())))

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

mina = gcd(alist[1], alist[0])
mini = 0

for i, a in enumerate(alist[2:]):
  gcda = gcd(a, mina)
  if mina > gcda:
    mini = i + 2
    mina = gcda

if n == 2:
  print(max(alist))
elif mini == 0:
  mina1 = gcd(alist[1], alist[2])
  for a in alist[3:]:
    gcda = gcd(a, mina1)
    if mina1 > gcda:
      mina1 = gcda
  mina2 = gcd(alist[0], alist[2])
  for a in alist[3:]:
    gcda = gcd(a, mina2)
    if mina2 > gcda:
      mina2 = gcda
  if mina1 > mina2:
    print(mina1)
  else:
    print(mina2)
else:
  mina = gcd(alist[1], alist[0])

  for i, a in enumerate(alist[2:]):
    if i + 2 == mini:
      continue
    gcda = gcd(a, mina)
    if mina > gcda:
      mina = gcda
  print(mina)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions


N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

res = []


for i in range(N):
    B = A[:]
    del B[i]
    a = max(B)
    b = min(B)
    gcd_num = fractions.gcd(a, b)
    res.append(gcd_num)
        


print(max(res))

Submission status: Wrong Answer

Solution code:
def main():
    input = sys.stdin.readline
    try:
        n = int(input())
        a = list(map(int, input().split()))
        if n == 2:
            print(max(a))
        else:
            print(max(a) % min(a))
    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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

b_list = []

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

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

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

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

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