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

def gcd(a, b):
    return fractions.gcd(a,b)

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

if __name__ == '__main__':
    N = int(input())
    A_list = list(map(int, input().split()))

    answer = 0

    for i in range(0, len(A_list)-1):
        A_list_copy = copy.deepcopy(A_list)
        A_list_copy.pop(i)

        gcd_number = gcd_list(A_list_copy)

        if answer < gcd_number:
            answer = gcd_number

    print(answer)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
import fractions
from functools import reduce

N = int(input())
A = np.array(input().split()).astype(int)

def gcd(numbers):
    return reduce(fractions.gcd, numbers)
rt = 1
for i in range(N):
    ind = np.ones(N, dtype=bool)
    ind[i]=False
    A_tmp = A[ind]
    f = gcd(A_tmp)
    print(f)
    if rt < f:
        rt = f
print(rt)

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
p=a[0]
a[0]=a[1]
a[1]=p
#mae
r3=a[0]
flag3=0
for v in range(1,n):
    x=fractions.gcd(r3,a[v])
    if x<r3 and flag3==0 and v!=0:
        flag3=1
    elif x<r3:
        r3=x
#usiro
r4=a[n-1]
flag4=0
for w in range(n-1):
    y=fractions.gcd(r4,a[n-w-2])
    if y<r4 and flag4==0 and w!=0:
        flag4=1
    elif y<r4:
        r4=y
print(max(r1,r2,r3,r4))

Submission status: Wrong Answer

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

GCD = [fractions.gcd(A[0],A[N-1])]
for i in range(N-1):
  GCD.append(fractions.gcd(A[i],A[i+1]))
a = GCD.index(min(GCD))
if a == 0:
  if GCD[1] < GCD[N-1]:
    a = 0
  else:
    a = N-1
elif a == N-1:
  if GCD[0] < GCD[N-2]:
    a = N-1
  else:
    a = N-2
elif GCD[a-1] < GCD[a+1]:
  a = a-1
A.pop(a)

d = A[0]
for i in range(N-2):
  d = fractions.gcd(d,A[i+1])
print(d)

Submission status: Wrong Answer

Solution code:
import math
from sys import stdin
import numpy as np

n = int(stdin.readline().rstrip())
nums = np.sort(np.array(list(map(lambda x: int(x), stdin.readline().rstrip().split()))))

n1 = nums[1]

flag1 = list(map(lambda x: x.is_integer(), nums[1:]/nums[1]))
if not False in flag1:
    print(n1)
else:
    n2 = np.min(np.diff(np.delete(nums, 1)))
    if (n2/nums[0]).is_integer():
        print(n2)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = map(int, input().split())
lst1 = list(A)
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors
lst2 = make_divisors(min(lst1))
for i in lst2:
  ans = 0
  for j in lst1:
    if (j % i == 0):
      ans += 1
  if (ans == N - 1):
    print(i) 
    break

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

if n == 2:
  gcdnum = max(numbers[0], numbers[1])
else:
  gcdnum = max(gcd(numbers[0], numbers[1]), gcd(numbers[0], numbers[2]), gcd(numbers[1], numbers[2]))
  for i in range(3, n):
    if gcd(gcdnum, numbers[i]) == 1:
      break
    else:
      gcdnum = gcd(gcdnum, numbers[i])
    
print(gcdnum)

Submission status: Wrong Answer

Solution code:
import functools
n = int(input())
a_list = list(map(int,input().split()))

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

res = []
for i in range(len(set(a_list))):
    e = a_list.pop(0)
    res.append(functools.reduce(gcd, a_list))
    a_list.append(e)

print(max(res))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
if N == 2:
    print(max(A))
    exit()
for n in range(A[1] // 2, 0, -1):
    num = 0
    for a in A:
        if a % n != 0:
            num += 1
            if num == 2:
                break
    else:
        print(n)
        exit()

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)

G = len([i for i in A if i % 2 == 0])
K = len([i for i in A if i % 2 == 1])
GG = [i for i in A if i % 2 == 0]
KK = [i for i in A if i % 2 == 1]
if abs(G - K) > 0 and G > 0 and K > 0:
  temp = A[:]
  temp.remove(max(KK))
  temp.append(max(GG))
  list.append(gcd_list(temp))

  temp = A[:]
  temp.remove(max(GG))
  temp.append(max(KK))
  list.append(gcd_list(temp))
else:
  temp = A[:]
  temp[0] = temp[N - 1]
  list.append(gcd_list(temp))

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

Submission status: Wrong Answer

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

import math
def primeFactor(n):
    ret = []
    div = 2
    limit = math.sqrt(n)
    while div < limit+1:
        if n%div==0:
            n=n//div
            ret.append(div)
        else:
            div+=1
    
    if n != 1:
        ret.append(div)
        
    return ret

primes = []
for it in a:
    primes.append(primeFactor(it))
#     print(primes[-1])

first = primes[0]
second = primes[1]



rest_data = {}
while len(first) > 0:
    el = first[0]
    rest_data[el] = [1 for i in range(first.count(el))]
    while first.count(el) > 0:
        first.remove(el)
        
while len(second) > 0:
    el = second[0]
    if not el in rest_data.keys():
        rest_data[el] = [1 for i in range(second.count(el))]
    else:
        for i in range(second.count(el)):
            if i < len(rest_data[el]):
                rest_data[el][i] += 1
            else:
                rest_data[el].append(1)
    while second.count(el) > 0:
        second.remove(el)

for it in primes[2:]:

    delete_key = []
    for key, val in rest_data.items():
        if key in it:
            for i in range(len(val)):
                if i < it.count(key):
                    continue
                if val[i] == 0:
                    break
                val[i] -= 1
        else:
            ZERO = True
            for i in range(len(val)):
                val[i] -= 1
                if val[i] > 0:
                    ZERO = False
            if ZERO:
                delete_key.append(key)

    for key in delete_key:
        rest_data.pop(key, None)

ret = 1
for key, val in rest_data.items():
    while val.count(0) > 0:
        val.remove(0)
    ret *= key**len(val)
    
print(ret)

Submission status: Wrong Answer

Solution code:
def gls(n, v):
	if len(v) == 1:
		return v[0]
	elif n == -1:
		return gcd(v[0],v[1])
	else:
		return gls(gcd(n,v[0]),v[1:])

#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

result = 0;
for i in range(N):
	if(i == N-1):
		ls = A[:-1]
	else:
		ls = A[:i] + A[i+1:]
	
	#print(ls)
	x = gls(-1,ls)
	#print(x)
	if x > result:
		result = x
		
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
if N == 2:
  print(A[1])
  exit()
ans = 1
cnt = 1
while cnt <= A[1]:
  warenai = 0
  for j in range(N):
    if A[j] % cnt != 0:
      warenai += 1
  if warenai == 1:
    ans = cnt
  cnt += 1
print(ans)

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()
    ac = collections.Counter(LI())
    a = []
    aa = []
    for k,v in ac.items():
        if v > 1:
            aa.append(k)
        else:
            a.append(k)

    tr = -1
    if len(aa) > 0:
        tr = aa[0]
        for k in aa[1:]:
            tr = fractions.gcd(k,tr)

    l = len(a)
    if l < 2:
        return tr
    if l < 3:
        r = 1
        for i in a:
            kr = fractions.gcd(i,tr)
            if r < kr:
                r = kr
        return r

    m = max(a)
    lm = m // (l-1)
    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



    if tr == -1:
        r = 1
        for k,v in p.items():
            if v >= l-1 and r < k:
                r = k
        return r

    r = 1
    for k,v in p.items():
        kk = fractions.gcd(tr,k)
        if v >= l-1 and r < kk:
            r = kk

    return r


print(main())

Submission status: Wrong Answer

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

D = {}

def trial_division(n):
    a = []  
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2   
    if n != 1: a.append(n)
    #Only odd number is possible
    return a

for i in range(N) :
    L = trial_division(A[i])
    SET = list(set(L))
    for l in SET :
        if l not in D :
            D[l] = [L.count(l)]
        else :
            D[l].append(L.count(l))

#print(D)

ans = 1
for element in D :
    if len(D[element]) <= N-2 :
        continue
    elif len(D[element]) == N-1 :
        ans *= (element ** min(D[element]))
    elif len(D[element]) == N :
        D[element] = sorted(D[element])
        if D[element][0] == D[element][1] :
            ans *= (element ** D[element][0])
        else :
            ans *= (element ** D[element][1])
    #print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import fractions
import sys

n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
m=[]
m.append(fractions.gcd(a[0],a[1]))
if(n==2):
    print(m[0])
    sys.exit()
t=-1
for i in range(2,a[-1]+1):
    t=np.argmax(np.mod(np.array(a),i))
    if(t!=0 and t!=-1):
        a.pop(t)
        break

s=fractions.gcd(a[0],a[1])
for i in range(2,len(a[1:])):
    s=fractions.gcd(s,a[i])
print(s)

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(a)
                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:
N = int(input())
A = list(map(int,input().split()))
def gcd(a):
    m = min([c for c in a if c>0])
    i = a.index(m)
    b = [c%m for c in a]
    if sum(b) == 0:
        return m,i
    b[i] = m
    return gcd(b)

m,i = gcd(A)
A.pop(i)
m,i = gcd(A)
print(m)

Submission status: Wrong Answer

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

cm = np.prod(A)
# max_gcd = 0
# for i in range(len(A)):
#     Am = A.copy()
#     Am[i] = cm
#     gcd = np.gcd.reduce(Am)
#     if gcd > max_gcd:
#         max_gcd = gcd
print(cm)

Submission status: Wrong Answer

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

def getNum(a, b):
    if a == b:
        return a
    while(True):
        a, b = max(a, b), min(a, b)
        a -= b
        if a == b:
            return a

ans = getNum(AList[0], AList[1])
if N == 3:
    ans = max(getNum(AList[0], AList[1]), getNum(AList[1], AList[2]), getNum(AList[2], AList[0]))
elif N > 3:
    ansA = getNum(AList[0], AList[1])
    ansB = getNum(AList[2], AList[3])
    ansC = getNum(AList[1], AList[2])
    ansD, ansE = AList[0], AList[3]
    aFlag, bFlag, cFlag, dFlag, eFlag = True, True, True, True, True
    for i in range(N):
        num = AList[i]
        if num % ansA != 0:
            if not aFlag:
                ansA = 1
            aFlag = False
        if num % ansB != 0:
            if not bFlag:
                ansB = 1
            bFlag = False
        if num % ansC != 0:
            if not cFlag:
                ansC = 1
            cFlag = False
        if num % ansD != 0:
            if not dFlag:
                ansD = 1
            dFlag = False
        if num % ansE != 0:
            if not eFlag:
                ansE = 1
            eFlag = False
    ans = max(ansA, ansB, ansC, ansD, ansE)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
min_a=min(a)
"""
def primes(max_number):

    指定値未満の素数を取得するジェネレータ
    :param max_number: 最大値
    :return: 素数ジェネレータ

    if max_number <= 2:
        raise StopIteration
    yield 2
    is_prime = [1] * max_number
    square_root_of_max = max_number ** 0.5
    for number in range(3, max_number, 2):
        if is_prime[number] is 0:
            continue
        yield number
        if number <= square_root_of_max:
            for multiple in range(number * 2, max_number, number):
                is_prime[multiple] = 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

a.sort()
if n==2:
    print(max(a))
else:
    kouho_1=gcd(a[0], a[1])
    kouho_2=gcd(a[0], a[2])
    if kouho_1>=kouho_2:
        kouho=kouho_1
    else:
        kouho=kouho_2

    print(kouho)

Submission status: Wrong Answer

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

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

n = int(input())
a = input().split()
num1 = 10000000000
num2 = 10000000000

b = gcd(int(a[0]),int(a[1]))
cntr = 0

for i in range(1,n):
    w = gcd(int(a[i]),b)
    b = w
    
    if w < num1:
        num1 = w
    elif num1 <= w <= num2:
        num2 = w

if num2 == 10000000000:
    print(num1)
else:
    print(num2)

Submission status: Wrong Answer

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

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


n = int(input())

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

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

g = []
gg = []
for i in range(0, n):
    if i!=0: g.append(gcd(a[0], a[i]))
    if i!=1: gg.append(gcd(a[1], a[i]))
g.sort()
gg.sort()

g.pop(0)
gg.pop(0)

if g[0]>gg[0]: print(g[0])
else: print(gg[0])

Submission status: Wrong Answer

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

n=int(input())
if n==2:
  a,b=map(int,input().split())
  print(max(a,b))
  exit()
elif n==3:
  a,b,c=map(int,input().split())
  print(max(gcd(a,b),gcd(a,c),gcd(b,c)))
  exit()
else:
  l=list(map(int,input().split()))
  aa=l[0]
  for x in l:
    aa=gcd(aa,x)
  print(aa)

Submission status: Wrong Answer

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

# cm = np.prod(A)
# max_gcd = 0
# for i in range(len(A)):
#     Am = A.copy()
#     Am[i] = cm
#     gcd = np.gcd.reduce(Am)
#     if gcd > max_gcd:
#         max_gcd = gcd
print(sum(A))

Submission status: Wrong Answer

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




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


print(max)

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 - 1):
    temp = gcd(ans, A[i])
    if temp == g:
        ans = gcd(ans, list(itertools.accumulate(A[i + 1:], func=gcd))[-1])
        break
    else:
        ans = temp
ans = max(ans, list(itertools.accumulate(A[1:], func=gcd))[-1])
print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(p,q):
  while q!=0:
    p,q=q,p%q
  return p

n=int(input())
a=list(map(int,input().split()))
a.sort()
cnt1=0
cnt2=0
cnt3=0

if n==2:
  print(a[-1])
else:
  b=a[0]
  c=gcd(a[0],a[2])
  d=a[1]
  for i in range(n-1):
    if gcd(b,a[i+1])==1 and cnt1==0:
      cnt1=1
      continue
    elif gcd(b,a[i+1])==1 and cnt1==1:
      b=1
      break
    else:
      b=gcd(b,a[i+1])
      
  if n>=4:
    for i in range(n-3):
      if gcd(c,a[i+3])==1 and cnt2==0:
        cnt2=1
        continue
      elif gcd(c,a[i+3])==1 and cnt2==1:
        c=1
        break
      else:
        c=gcd(c,a[i+3])
  for i in range(n-2):
    if gcd(d,a[i+2])==1 and cnt3==0:
      cnt3=1
      continue
    elif gcd(d,a[i+2])==1 and cnt3==1:
      d=1
      break
    else:
      d=gcd(d,a[i+2])
  print(max(b,c,d))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
# N=3
# A=[12 ,15 ,18]
l=[0]*N
r=[0]*N
l[0]=A[0]
r[0]=A[N-1]
for i in range(1,N-1):
    l[i]=gcd(l[i-1],A[i])
    r[i]=gcd(r[i-1],A[i])    
gcdlist = [1,l[N-2],r[N-2]]
for i in range(N-2):
    gcdlist.append(gcd(l[i],r[N-3-i]))
#print(gcdlist)
print(max(gcdlist))

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8:
import fractions
from functools import reduce


def main():
    N = int(input())
    A = [int(ele) for ele in input().split()]
    gcds = [-1] * N

    # ans = tle_solver(A)
    ans = ac_solver(A)
    print(ans)


def ac_solver(A):
    a_min = min(A)
    a_min_divisors = sorted(make_divisors(a_min), reverse=True)
    for d in a_min_divisors:
        ct = 0
        for a in A:
            if a % d != 0:
                ct += 1

            if 2 < ct:
                break

        if ct == 1:
            break

    return d


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

    return divisors


def tle_solver(A):
    gcds = [-1] * len(A)
    for idx in range(len(A)):
        tmp = A[:idx] + A[idx+1:]
        gcds[idx] = gcd(*tmp)

    return max(gcds)


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,a,b=int(input()),list(map(int,input().split())),[]
if n==2:print(gcd(a[0],a[1]))
elif n==3:print(max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])))
else:
  no,mi=a[0],a[0]
  for i in range(1,n):
    s=gcd(no,a[i])
    if s!=no:
      no=max(s,mi)
      mi=gcd(s,mi)
  print(no)

Submission status: Wrong Answer

Solution code:
import fractions

N = int(input())
Al = list(map(int, input().split()))
a = 0
b = 0

if N == 2:
  a = max(Al)
  print(a)
else:
  for i in range(0, N-1):
    for j in range(i+1, N):
      c = fractions.gcd(Al[i], Al[j])
      if c > b:
        b = c
  a = b
  print(a)

Submission status: Wrong Answer

Solution code:
input();input();N=1;print(N)

Submission status: Wrong Answer

Solution code:
import fractions

n = int(input())
a = list(int(n) for n in input().split())

f = fractions.gcd(a[0], a[1])

print(f)

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)
min_A = min(A)
min_A_i = A.index(min_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 = []
for i,x in enumerate(A):
	# print(ans)
	if i != min_A_i:
		ans.append(gcd(S-x, min_A))
	else:
		tmp = S-min_A
		tmp_lis = A.copy()
		tmp_lis.pop(i)
		min_A_tmp = min(tmp_lis)
		ans.append(gcd(S-x, min_A_tmp))
# print(ans)
print(max(ans))

Submission status: Wrong Answer

Solution code:
import fractions

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

INF = 99999999
first = second = INF
dic = {}

max_gcd = 0
for i in range(N):
    tmp = INF
    for j in range(N):
        if j != i:
            if tmp == INF:
                tmp = fractions.gcd(A[i], A[j])
            else:
                tmp = max(tmp, fractions.gcd(A[i], A[j]))
    max_gcd = max(tmp, max_gcd)

print(max_gcd)

Submission status: Wrong Answer

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

N = input()
As =  list(map(int, input().split()))
sorted(As)
r = []
r.append(gcd(As[0], As[-1]))
r.append(gcd(As[1], As[-1]))
r.append(gcd(As[0], As[-2]))
print(max(r))

Submission status: Wrong Answer

Solution code:
import sys
import fractions as math
from functools import reduce

input = sys.stdin.readline


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


def gcd2(index, a_list):
    nums = a_list[:]
    del nums[index]
    return gcd(nums)


def main():
    n = int(input())
    a_list = [int(i) for i in input().split()]
    if n > 10:
        n = 10
    print(max([gcd2(i, a_list) for i in range(n)]))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a0 = [0]*n
a0 = list(map(int, input().split()))

a0.sort()
a = [0]*n
a = a0
totalans = 1
for x in range(n):
    a = a0
    if x == 0:
        a[x] = a[x+1]
    else:
        a[x] = a[x-1]
    
    i = 1
    ans = 1
    while i <= a[0] and a[0] > 1:
        for j in range(n):
            if a[j] % i != 0:
                break
        else:
            for j in range(n):
                a[j] = int(a[j] / i)
            ans *= i
        if a[0] < i:
        	i = 1
        else:
        	i += 1
    if totalans < ans:
        totalans = ans

print(totalans)

Submission status: Wrong Answer

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

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

for i in range(N-1):
    for j in range(i+1,N):
        ans = max(ans,GCD(A[i],A[j]))

print(ans)

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)

G = len([i for i in A if i % 2 == 0])
K = len([i for i in A if i % 2 == 1])
GG = [i for i in A if i % 2 == 0]
KK = [i for i in A if i % 2 == 1]
if abs(G - K) > 0 and G > 0 and K > 0:
  temp = A[:]
  temp.remove(max(KK))
  temp.append(max(GG))
  list.append(gcd_list(temp))

  temp = A[:]
  temp.remove(max(GG))
  temp.append(max(KK))
  list.append(gcd_list(temp))

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

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
A = list(map(int, input().split()))
ans = A[1]
for i in range(2, N):
	ans = fractions.gcd(ans, A[i])
G = [A[0]]
for j in range(1, N):
	G.append(fractions.gcd(A[0], A[j]))
k = G.index(min(G))
if k == N - 1:
	B = A[: N - 1]
else:
	B = A[: k] + A[k + 1:]
g = B[0]
for l in range(1, N - 1):
	g = fractions.gcd(g, B[l])
print(max(ans, g))

Submission status: Wrong Answer

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


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

gcd_1 = [gcd(A[0],A[i]) for i in range(1,n)]

gcd_1.sort()

gcd_2 = A[1]

for i in range(2,n):
      gcd_2 = gcd(gcd_2,A[i])

if n == 2:
    print(A[0])
else:
    print(max(gcd_1[1],gcd_2))

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()
minn = 10 ** 9 + 1
idx = -1
for i in range(n - 1):
    if minn >= fractions.gcd(a[i], a[i + 1]):
        minn = fractions.gcd(a[i], a[i + 1])
        idx = i
print(max(gcd_list(a[:idx] + a[idx + 1:]), gcd_list(a[:idx + 1] + a[idx + 2:])))

Submission status: Wrong Answer

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

A = list(set(A))

result = []
for i,a in enumerate(A):
    if len(A)==1:
        tmpA=A
        result = tmpA
        break
        
    tmpA = A[:i]+A[i+1:]
    while True:
        minA = min(tmpA)
        tmpA = set([a%minA for a in tmpA])
        tmpA.discard(0)
        tmpA.add(minA)
        if len(tmpA)==1:
            break
    result.append(list(tmpA)[0])

print(max(result))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
if N == 2:
  print(A[1])
  exit()
ans = 1
cnt = 1
while cnt <= A[0]:
  warenai = 0
  for j in range(N):
    if A[j] % cnt != 0:
      warenai += 1
  if warenai == 1:
    ans = cnt
  cnt += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(y,x%y)

n = int(input())
if n==1:
  a = int(input())
  print(a)
  sys.exit()
a = list(map(int, input().split()))



sort_a = sorted(a)
max_a = sort_a.pop()
if max_a==0:
  print(0)

else:
  max_gcd=0
  
  for i in sort_a:
    temp = gcd(max_a, i)
    if temp>max_gcd:
      max_gcd = temp
  
  print(max_gcd)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np
import fractions
import math

n = stdin.readline().rstrip()
n = int(n)

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

max = 0
for i in range(len(a)):
    for j in range(i, len(a)):
        if i == j:
            continue

        g = fractions.gcd(a[i], a[j])
        if max < g:
            max = g

print(max)