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

def calcKou(num):
    result = []
    for i in range(1, num+1):
        if num % i == 0:
            result.append(i)
    return result

kous = list(map(calcKou, As))
all = []
for v in kous:
    all += v
all = list(set(all))
all = list(reversed(all))

counts = []
for v in all:
    count = 0
    for a in As:
        if v in calcKou(a):
            count += 1
    counts.append(count)

print(all)    
print(counts)

ans = 1
for i in range(len(counts)):
    if counts[i]>=N-1:
        ans = all[i]
        break
print(ans)

Submission status: Wrong Answer

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

n = int(input())
an = [int(i) for i in input().split(" ")]
an = sorted(an)
if len(an) <= 2:
    print(max(an))
else:
    sample = []
    for i in range(len(an)):
        for j in range(i+1, len(an)):
            tmo = gcd(an[i], an[j])
            if an[i] == an[j]:
                continue
            sample.append(gcd(an[i], an[j]))

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

Submission status: Wrong Answer

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

n=int(input())
a=sorted([int(i) for i in input().split()])
gcd1=[0]*n
gcd2=[0]*n
for i in range(n):
    if i!=0:
        gcd1[i]=gcd(a[0],a[i])
    if i!=1:
        gcd2[i]=gcd(a[1],a[i])
print(max(max(gcd1),max(gcd2)))

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

Submission status: Wrong Answer

Solution code:
def make_divisors(arg):
    divisors = set()
    for i in range(1, int(arg**0.5)+1):
        if arg % i == 0:
            divisors.add(i)
            if i != arg // i:
                divisors.add(arg//i)

    return divisors


n = int(input())
a = list(map(int, input().split()))
a.sort()
a0y = make_divisors(a[0])
a1y = make_divisors(a[1])
common = a0y & a1y
one = a0y ^ a1y
last = 0
for e in a[2:]:
    if e == last:
        continue
    tmp = make_divisors(e)
    common = tmp & common
    one = (one & tmp)
    last = e

print(max(common.union(one)))

Submission status: Wrong Answer

Solution code:
import fractions
import math


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

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

    gcd_listScd = []
    for i in range(1, N):
        gcd_listScd.append(fractions.gcd(scdNum, A[i]))

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

from fractions import gcd

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap



@mt
def slv(N, A):
    a0 = A[0]
    a1 = A[1]

    a0_min_gcd = (sys.maxsize, -1)
    a1_min_gcd = (sys.maxsize, -1)

    for i, a in enumerate(A):
        a0_min_gcd = min(a0_min_gcd, (gcd(a0, a), i))
        a1_min_gcd = min(a1_min_gcd, (gcd(a1, a), i))
    
    A0 = A.copy()
    A0.pop(a0_min_gcd[1])
    A1 = A.copy()
    A1.pop(a1_min_gcd[1])

    return max(reduce(gcd, A0), reduce(gcd, A1))


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))

    # N  = 10**5
    # A = [10**9] * N
    # # print(slv(N, A))
    # A = [2, 4, 8, 16]
    # N = len(A)
    # print(slv(N, A))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

def gcd(numbers) :
    return reduce(fractions.gcd, numbers)
  
def ans(list) :
  tmp = gcd(list)
  if tmp != 1 :
    for i in range(len(list)) :
      list[i] /= tmp
  return(list)

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

for i in range(N) :
  tmp = gcd(A[0:i] + A[i+1:N])
  if tmp != 1 :
    print(tmp)
    break

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 < 1:
        return tr
    if l < 3:
        r = 0
        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

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

    if tr == -1:
        return r

    return fractions.gcd(r, tr)


print(main())

Submission status: Wrong Answer

Solution code:
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()))
ans = 0
if len(A) == 1:
    ans = A[0]
elif len(A) == 2:
    ans = max(A)
else:
    d = {}
    for a in A:
        T = make_divisors(a)
        for t in T:
            if t in d:
                d[t] += 1
            else:
                d[t] = 1
    for k, v in d.items():
        if v == N - 1:
            ans = max(ans, k)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
def gcd(x,y):
  while y != 0:
    k = x
    x = y
    y = k%y
  return  x
ans = 1
for i in range(N):
  flag = True
  if i == 0:
    p = A[1]
    for j in range(2,N):
      p = gcd(A[i],p)
      if p == 1:
        flag = False
        break
    if flag:
      if ans <= p:
        ans = p
  else:
    p = A[0]
    for j in range(1,N):
      if j != i:
        p = gcd(A[i],p)
      if p == 1:
        flag = False
        break
    if flag:
      if ans <= p:
        ans = p
print(ans)

Submission status: Wrong Answer

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


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


def list_lcm(number_list):
    lcm_number = 1
    for j in number_list:
        lcm_number = lcm(lcm_number, j)

    return lcm_number


def list_gcd(number_list):
    gcd_number = number_list[0]
    for i in number_list:
        gcd_number = gcd(gcd_number, i)

    return gcd_number


def ignore_list_gcd(number_list, ignore_index):
    _list = []
    for i in range(len(number_list)):
        if i != ignore_index:
            _list.append(number_list[i])

    return list_gcd(_list)


if __name__ == '__main__':
    n = int(input())
    numbers = list(map(int, input().split()))
    gcds = []
    for i in range(n - 1):
        gcds.append(gcd(numbers[i], numbers[i + 1]))
    min_index = gcds.index(min(gcds))
    ans = max(ignore_list_gcd(numbers, min_index), ignore_list_gcd(numbers, min_index + 1))

    print(ans)

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

def gcd(a, b):
  if a is None:
    return b
  a, b = (a, b) if a < b else (b, a)
  while a > 0:
    a, b = b % a, a
  return b

if N == 2:
  print(max(A[0], A[1]))
  exit()

gcdA = None
for a in A:
  gcdA = gcd(gcdA, a)

# A[0]をスキップするパターン
gcdA2 = None
for a in A[1:]:
  gcdA2 = gcd(gcdA2, a)

flag = False
ans = None
for a in A:
  tmp = gcd(ans, a)
  if tmp == gcdA:
    if not flag:
      # 1回だけスキップ
      flag = True
      continue
    else:
      ans = gcdA
      break
  ans = tmp
print(max(ans, gcdA2))

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 = 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:
from fractions import gcd
n = int(input())
a = list(map(int, (input().split())))

if n == 2:
    print(max(a[0], a[1]))
    exit()

noskip = gcd(a[0], a[1])
skipped = max(gcd(a[0], a[2]), gcd(a[1], a[2]))

for i in range(2, n):
    noskip = gcd(noskip, a[i])
    skipped = max(gcd(skipped, a[i]), noskip)

print(max(noskip, skipped))

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)
A.sort()
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:
import fractions as frc
n = int(input())
a = [int(i) for i in input().split()]
ls = [frc.gcd(a[0],a[1])]
#for i in range(n):
ans = []
if n == 2:
    print(max(a))
else:
    for i in range(1,n):
        new_ls = a[:i-1]+a[i:]
        if i == 1:
            m = frc.gcd(a[1],a[2])
        elif i == 2:
            m = frc.gcd(a[0],a[2])
        else:
            m = frc.gcd(a[0],a[1])
            
        for j in range(1,n-1):
            ans.append(frc.gcd(new_ls[j],m))

    print(max(ans))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

memo = {(0,0):1, (N,N):1}

for i in range(1,N+1):

    if i == 1:
        memo[(0,1)] = A[0]
        memo[(N-1,N)] = A[-1]

    else:

        # gcd first i
        memo[(0,i)] = gcd(memo[(0,i-1)], A[i-1])

        # gcd last i
        memo[(N-i,N)] = gcd(memo[(N-i+1,N)], A[-i])
ans = -1

for i in range(1,N+1):

    curgcd = gcd(memo[(0,i-1)], memo[(i,N)])

    ans = max(ans, curgcd)

    
gcd_all = gcd(A[0], memo[(1,N)])

ans = max(ans, gcd_all)

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):
            print(i, j + 1)
            n_dict[gcv(a[i], a[j + 1 + i - 1])] += 1
    print(sorted(n_dict.items(), key=lambda x: x[0]))
    n_new = sorted(n_dict.items(), key=lambda x: x[0])
    if n_new[0][0] == 1:
        return n_new[1][0]
    return n_new[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:
import fractions
from functools import reduce

n = int(input())

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


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


gcd_l = [a[0]]
gcd_r = [a[-1]]
for i in range(1,n):
    gcd_l.append(fractions.gcd(gcd_l[i-1],a[i]))
    gcd_r.append(fractions.gcd(gcd_r[i-1],a[-i-1]))

gcd_r.reverse()

ans = max(gcd_l[1],gcd_r[-2])
for i in range(1,n-1):
    gcd = fractions.gcd(gcd_l[i-1],gcd_r[i+1])
    ans = max(ans,gcd)

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
from functools import reduce

N = int(input())
As = list(map(int,input().split(' ')))

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

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

ms = []

for i in range(N):
	nl = As[0:i] + As[i+1:N]
	ms.append(gcd_list(nl))

ms = list(set(ms))

if len(ms) == 1:
	print(ms[0])
else:
	m1,m2 = heapq.nsmallest(2,ms)
	print(m2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

g1 = A[0]
g2 = A[1]
for a in A[2:]:
    g1 = gcd(g1,a)
    g2 = gcd(g2,a)
print(max(g1,g2))

Submission status: Wrong Answer

Solution code:
n = int(input())

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


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


max_ans = 1
for i in range(n-1):
    f = a[:i] + a[i+1:]
    ans = f[0]
    for j in f:
        ans = gcd(ans, j)
            
    if ans > max_ans:
        max_ans = ans

print(max_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 < 1:
        return tr
    if l < 3:
        r = 0
        for i in a:
            kr = fractions.gcd(i,tr)
            if r < kr:
                r = kr
        return r

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

    if tr == -1:
        return r

    return fractions.gcd(r, tr)


print(main())

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 = AList[0]
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 = AList[0]
    aFlag, bFlag, cFlag, dFlag = 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
    ans = max(ansA, ansB, ansC, ansD)

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import functools
import operator
N=int(stdin.readline().rstrip())
data=[int(x) for x in stdin.readline().rstrip().split()]
seki = functools.reduce(operator.mul, data)
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
ans=1
for k,l in factorize(seki):
    if l >= N:
        ans=ans*(k**(l//N))
    elif l-1 == N:
        ans=ans*k
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
n = int(input())
a = list(map(int, input().split(" ")))
a.sort(reverse=True)
for i in range(n):
    for j in range(i+1,n):
        x = fractions.gcd(a[i], a[j])
        if x == 1:
            continue
        else:
            if list(map(lambda s: s%x, a)).count(0) == n-1:
                print(x)
            else:
                continue

Submission status: Wrong Answer

Solution code:
import copy
ans = 1
N = int(input())
A = list(map(int, input().split()))
l = []

def gcd(a,b):
    x = max(a, b)
    y = min(a, b)
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z
    
def gcd_list(list):
    p = 1
    for i in range(len(list)-1):
        if i == 0:
            p = gcd(list[0], list[1])
        else:
            p = gcd(p,list[i+1]) 
    return p

if N == 2:
    print(gcd(A[0], A[1]))
else:
    for i in range(N):
        l = copy.copy(A)
        l.pop(i)
        ans = max(gcd_list(l), ans)
    print(ans)

Submission status: Wrong Answer

Solution code:
import copy

Submission status: Wrong Answer

Solution code:
from functools import reduce
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
def gcd_list(numbers):
    return reduce(gcd, numbers)

n = int(input())
a = list(map(int, input().split()))
if n == 2:
  print(max(a))
else:
  p = gcd_list(a[:3])
  q = max([gcd(a[0], a[1]), gcd(a[0], a[2]), gcd(a[1], a[2])])
  for i in range(3, n):
    p = gcd(p, a[i])
    q = max([p, gcd(q, a[i])])
  print(q)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

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

def gcds(n):
    return reduce(gcd, n)

n=int(input())
a=list(map(int, input().split()))
a=sorted(a)
# print(a)
m1=a[0]
m2=a[1]
ans=1
ans_temp=1
divm2=make_divisors(m2)
divm2.reverse()
f1=0
# print(divm2)
for d in divm2:
    if d<=1:
        if ans_temp==1:
            f1=0
        break
    for i in range(2,len(a)):
        if f1==1:
            break
        if a[i]%d !=0:
            # print(a[i],d)
            f1=0
            break
        # print("survived",a[i],d)
        ans_temp = d
        f1=1
        break
f2=1
divm1=make_divisors(m1)
divm1.reverse()
# print(divm1)
for d in divm1:
    if d == 1:
        continue
    f2=1
    count=0
    for i in range(1,len(a)):
        # print(d,a[i])
        if a[i]%d !=0:
            count+=1
            if count>=2:
                f2=0
                break
    # print("--",d,a[i],count,f2)
    if f2==1:
        ans=d
        break
        # print(ans)
# print(max(ans,ans_temp))
print(max(ans,ans_temp))

Submission status: Wrong Answer

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

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

for i in range(n-1):
    values = a[:i] + a[i+1:]
    res = functools.reduce(gcd, values)
    ans = max(ans, res)
print(ans)

Submission status: Wrong Answer

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

min_a = min(A)
c = 0
for i in range(1,min_a+1)[::-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:
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
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
if idx == -1:
    print(minn)
else:
    print(max(gcd_list(a[:idx] + a[idx + 1:]), gcd_list(a[:idx + 1] + a[idx + 2:])))

Submission status: Wrong Answer

Solution code:
import fractions


def gcd(l, t):
    a = l.pop(0)
    for v in l:
        a = fractions.gcd(a, v)
        if a <= t:
            break
    return a


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

dp = [[1]*N for i in range(2)]
dp[0][0] = A[0]

a, b = A[0], A[-1]
for i in range(1, N):
    a = fractions.gcd(a, A[i])
    dp[0][i] = a
    b = fractions.gcd(b, A[N-i])
    dp[1][N-i] = b

ans = 1
for i in range(N):
    g = 1
    if i == 0:
        g = dp[1][i]
    elif i == (N-1):
        g = dp[0][i]
    else:
        g = fractions.gcd(dp[0][i-1], dp[1][i+1])
    if g > ans:
        ans = g
print(ans)

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()))
l = []
for i in range(N):
    a = A[i]
    for j in range(i+1, N):
        l.append(gcd(a, A[j]))
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):
    rest = a % b
    while(rest):
        a = b
        b = rest
        rest = a % b
    return b

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
    
    minval = gcd(a, b)
    if minval < tempmin:
        minindex = temp

if len(vals) > 2 and vals[1] == minindex:
    # 調整
    v1 = gcd(vals[0], vals[2])
    v2 = gcd(vals[1], vals[2])
    if v1 < v2:
        minindex = vals[0]

if minindex == vals[0]:
    minval = vals[1]
else:
    minval = vals[0]
for b in vals[1:]:
    if b == minindex:
        continue
    a = minval
    minval = gcd(a, b)

print(minval)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

import copy
from functools import reduce
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)
def gcd(numbers):
    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:
        target = A_list[idx]
        if pair_gcd(target, A_list[idx-1]) == max_gcd:
            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:
n = input()
A = input().split(" ")

n = int(n)
A_tmp = []
for a in A:
    A_tmp.append(int(a))
A = A_tmp

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

if n == 2:
    if A[0] > A[1]:
        print(A[0])
    else:
        print(A[1])
else:
    biggest = 0
    for i in range(n):
        print("else" + str(i))
        index = []
        for j in range(n):
            if i == j:
                pass
            else:
                index.append(j)

        tmp = euclid(A[index[0]], A[index[1]])
        print(tmp)
        for j in range(n-1):
            tmp = euclid(tmp ,A[index[j]])
        print(tmp)

        if tmp > biggest:
            biggest = tmp
    print(biggest)

Submission status: Wrong Answer

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

import itertools
def eratosthenes_sieve(n):
    table = [0] * (n + 1)
    prime_list = []
    
    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1
    
    return prime_list

if N == 2:
    if a[0] > a[1]:
        print(a[0])
    else:
        print(a[1])
        
else:
    prime =  eratosthenes_sieve(int(10**(5)))
    num   =  1
    for i in prime:
        flag = 0
        for cnt, j in enumerate(a):
            if j % i == 0:
                a[cnt] = a[cnt]/i
            elif flag == 0:
                flag = 1
            else:
                print(num)
                exit()
        num = i

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
w=sorted(a)
ans=1
end=False

flag=False
for h in range(n):
    if a[h]%w[0]!=0 and flag==True:
       break
    if a[h]%w[0]!=0:
        flag=True
    if h==n-1:
        ans=w[0]
        end=True




for i in reversed(range(2,-(-w[0]//2)+1)):
    flag=False
    if end==True:
        break
    for h in range(n):
        if a[h]%i!=0 and flag==True:
            break
        if a[h]%i!=0:
            flag=True
        if h==n-1:
            ans=i
            end=True
            break


print(ans)

Submission status: Wrong Answer

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

def gcdl(l):
    res = l[0]
    for i in l:
        res = gcd(res, i)
    return res

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

m = 1
count = 0
for i in range(n):
    tmp = ass[:]
    tmp.pop(i)

    mm = gcdl(tmp)
    if mm > m:
        m = mm
    if mm == 1:
        count += 1
        if count == 2:
            break
        
print(m)

Submission status: Wrong Answer

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

gcd = 0;

for i in range(N):
	for j in range(i+1,N):
		x = A[i];
		y = A[j];

		while y != 0:
			x %= y;
			x, y = y, x;

		if gcd < x:
			gcd = x;

print(gcd);