Problem:


Score : 300 points

Problem Statement

There are N integers, A_1, A_2, ..., A_N, written on the blackboard.

You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.

Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Output

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Sample Input 1

3
7 6 8

Sample Output 1

2

If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.

Sample Input 2

3
12 15 18

Sample Output 2

6

Sample Input 3

2
1000000000 1000000000

Sample Output 3

1000000000

We can replace an integer with itself.



Sample input:
3
7 6 8


Sample output:
2

Submission status: Wrong Answer

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

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


def gcd_wrapper(x, y):
    if x >= y:
        return gcd(x, y)
    else:
        return gcd(y, x)

if N == 2:
    print(max(A))
    exit()
if N == 3:
    x1 = gcd_wrapper(A[0], A[1])
    x2 = gcd_wrapper(A[1], A[2])
    x3 = gcd_wrapper(A[0], A[2])
    print(max([x1, x2, x3]))
    exit()

init_results = []
for k, g in enumerate(A[0:3]):
    for h in A[k:3]:
        init_results.append(gcd_wrapper(g, h))
if max(init_results) == 1:
    print(1)
    exit()
stop_flag = 0
x = max(init_results)
for i in A:
    tmp = gcd_wrapper(x, i)
    if tmp == 1:
        stop_flag =+ 1
    else:
        x = tmp
if stop_flag >= 2:
    print(1)
else:
    print(x)

Submission status: Wrong Answer

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


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


gcds = []
for i in range(N):
    m = 1
    for j in range(N):
        if i != j:
            continue
        m = gcd(m, A[j])
    gcds.append(m)

max_gcd = 1
for i in range(N):
    max_gcd = max(gcd(A[i], gcds[i]), max_gcd)

print(max_gcd)

Submission status: Wrong Answer

Solution code:

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

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


def gcd_wrapper(x, y):
    if x >= y:
        return gcd(x, y)
    else:
        return gcd(y, x)

if N == 2:
    print(max(A))
    exit()
if N == 3:
    x1 = gcd_wrapper(A[0], A[1])
    x2 = gcd_wrapper(A[1], A[2])
    x3 = gcd_wrapper(A[0], A[2])
    print(max([x1, x2, x3]))
    exit()

init_results = [gcd_wrapper(A[0], A[1]), gcd_wrapper(A[2], A[3])]
if max(init_results) == 1:
    print(1)
    exit()
stop_flag = 0
x = max(init_results)
for i in A:
    tmp = gcd_wrapper(x, i)
    if tmp == 1:
        stop_flag =+ 1
    else:
        x = tmp
if stop_flag >= 1:
    print(1)
else:
    print(x)

Submission status: Wrong Answer

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

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


def gcd_wrapper(x, y):
    if x >= y:
        return gcd(x, y)
    else:
        return gcd(y, x)

if N == 2:
    print(max(A))
    exit()
if N == 3:
    x1 = gcd_wrapper(A[0], A[1])
    x2 = gcd_wrapper(A[1], A[2])
    x3 = gcd_wrapper(A[0], A[2])
    print(max([x1, x2, x3]))
    exit()

init_results = [gcd_wrapper(A[0], A[1]), gcd_wrapper(A[2], A[3])]
if max(init_results) == 1:
    print(1)
    exit()

init_result = max(init_results)
stop_flag = 0
x = init_result
for i in A:
    tmp = gcd_wrapper(x, i)
    if tmp == 1:
        stop_flag =+ 1
    else:
        x = tmp
if stop_flag >= 2:
    print(1)
else:
    print(x)

Submission status: Wrong Answer

Solution code:

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

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


def gcd_wrapper(x, y):
    if x >= y:
        return gcd(x, y)
    else:
        return gcd(y, x)

if N == 2:
    print(max(A))
    exit()
if N == 3:
    x1 = gcd_wrapper(A[0], A[1])
    x2 = gcd_wrapper(A[1], A[2])
    x3 = gcd_wrapper(A[0], A[2])
    print(max([x1, x2, x3]))
    exit()

init_results = [gcd_wrapper(A[0], A[1]), gcd_wrapper(A[2], A[3])]
if max(init_results) == 1:
    print(1)
    exit()

init_result = max(init_results)
stop_flag = 0
x = init_result
for i in A:
    tmp = gcd_wrapper(x, i)
    if tmp == 1:
        stop_flag =+ 1
    else:
        x = tmp
if stop_flag >= 2:
    print(1)
else:
    print(x)

Submission status: Wrong Answer

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

flag = 0
for term in A:

    count = 0

    for i in range(N):
        if(A[i] % term != 0):
            count += 1
        if(count == 2):
            break

    if(count <= 1):
        flag = 1
        break

if(flag == 1):
    print(term)
else:
    for term in reversed(range(1, max(A))):

        count = 0

        for i in range(N):
            if(A[i] % term != 0):
                count += 1
            if(count == 2):
                break

        if(count <= 1):
            break

    print(term)

Submission status: Wrong Answer

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

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

term_list = []
for i in range(N):
    term_list.append(gcd(A[i], A[(i + 1) % N]))

term_List = list(set(term_list))
max = 0

for term in term_List:

    count = 0

    for i in range(N):
        if(A[i] % term != 0):
            count += 1
        if(count >= 2):
            break

    if(count <= 1):
        if(max < term):
            max = term

print(max)

Submission status: Wrong Answer

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

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

term_list = []
for i in range(N):
    term_list.append(gcd(A[i], A[(i + 1) % N]))

term_list = list(set(term_list))
max = 0

for term in term_list:

    count = 0

    for i in range(N):
        if(A[i] % term != 0):
            count += 1
        if(count >= 2):
            break

    if(count <= 1):
        if(max < term):
            max = term

print(max)

Submission status: Wrong Answer

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

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

term_list = []
for i in range(N):
    term_list.append(gcd(A[i], A[(i + 1) % N]))

term_list = list(set(term_list))
max = 0

for term in term_list:

    count = 0

    for i in range(N):
        if(A[i] % N != 0):
            count += 1
        if(count >= 2):
            break

    if(count <= 1):
        if(max < term):
            max = term

print(max)

Submission status: Wrong Answer

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

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

term_list = []
for i in range(N):
    term_list.append(gcd(A[i], A[(i + 1) % N]))

term_list = list(set(term_list))
max = 0

for term in term_list:

    count = 0

    for i in range(N):
        if(A[i] % N != 0):
            count += 1
        if(count >= 2):
            break

    if(count <= 1):
        if(max < term):
            max = term

print(term)

Submission status: Wrong Answer

Solution code:

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

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


def gcd_wrapper(x, y):
    if x >= y:
        return gcd(x, y)
    else:
        return gcd(y, x)

if N == 2:
    print(max(A))
else:
    CD = set()
    for index1 in range(len(A)):
        for array_val2 in A[index1 + 1:]:
            CD.add(gcd_wrapper(A[index1], array_val2))
    # print(CD)
    sorted_unique_CD = sorted(list(CD))
    sorted_unique_CD.reverse()
    # print(sorted_unique_CD)
    for j in sorted_unique_CD:
        flag = 0
        for k in A:
            if k % j != 0:
                flag += 1
        if flag <= 1:
            print(j)
            break

Submission status: Wrong Answer

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

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

max = 0
for i in range(N):
    num = gcd(A[i], A[(i + 1) % N])
    if(max < num):
        max = num

flag = 0
for term in A:

    count = 0

    for i in range(N):
        if(A[i] % term != 0):
            count += 1
        if(count == 2):
            break

    if(count <= 1):
        flag = 1
        break

if(flag == 1):
    print(term)
else:
    for term in reversed(range(1, max + 1)):

        count = 0

        for i in range(N):
            if(A[i] % term != 0):
                count += 1
            if(count == 2):
                break

        if(count <= 1):
            break

    print(term)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

n = int(input())
a_array = [int(x) for x in input().split()]
gcd_array = []
gcd_reverse_array = []
tmp = a_array[0]
tmp_reverse = a_array[-1]
for i, j in zip(a_array, a_array[::-1]):
    tmp = gcd(tmp, i)
    tmp_reverse = gcd(tmp_reverse, j)
    gcd_array.append(tmp)
    gcd_reverse_array.append(tmp_reverse)

gcd_reverse_array = gcd_reverse_array[::-1]
res = 0
for i in range(n):
    if i == 0:
        res = max(res, gcd_reverse_array[1])
    elif i == n - 1:
        res = max(res, gcd_array[-2])
    else:
        res = max(res, gcd(gcd_array[i-1], gcd_reverse_array[-i]))
print(res)

Submission status: Wrong Answer

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

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


def gcd_wrapper(x, y):
    if x >= y:
        return gcd(x, y)
    else:
        return gcd(y, x)

if N == 2:
    print(max(A))
else:
    CD = []
    for index1, array_val1 in enumerate(A):
        for index2, array_val2 in enumerate(A[index1 + 1:]):
            CD.append(gcd_wrapper(A[index1], array_val2))

    sorted_unique_CD = sorted(list(set(CD)))
    sorted_unique_CD.reverse()
    # print(sorted_unique_CD)
    for j in sorted_unique_CD:
        tmp_array = []
        for k in A:
            tmp_array.append(k % j)
        if sum(tmp_array) <= 1:
            print(j)
            break

Submission status: Wrong Answer

Solution code:
def gcd(a, b):

    if(a < b):
        a, b = b, a

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

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

max = 0

for i in range(N):

    term = gcd(A[i], A[(i + 1) % N])
    count = 0

    for j in range(N):
        if(A[j] % term != 0):
            count += 1
        if(count >= 2):
            break

    if(count <= 1):
        if(max < term):
            max = term

print (max)

Submission status: Wrong Answer

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

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


def gcd_wrapper(x, y):
    if x >= y:
        return gcd(x, y)
    else:
        return gcd(y, x)

if N == 2:
    print(max(A))
else:
    CD = []
    CD_alt = []
    base_val = sorted(A)
    for index, array_val in enumerate(base_val):
        if index != 0:
            CD.append(gcd_wrapper(base_val[0], array_val))
        if index != 1:
            CD_alt.append(gcd_wrapper(base_val[1], array_val))

    sorted_CD = sorted(CD)
    sorted_CD_alt = sorted(CD_alt)
    # print(sorted_CD)
    # print(sorted_CD_alt)
    print(max([max(sorted_CD[0:2]), max(sorted_CD_alt[0:2])]))

Submission status: Wrong Answer

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

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


def gcd_wrapper(x, y):
    if x >= y:
        return gcd(x, y)
    else:
        return gcd(y, x)

if N == 2:
    print(max(A))
else:
    CD = []
    CD_alt = []
    base_val = sorted(A)
    for index, array_val in enumerate(A):
        if index != 0:
            CD.append(gcd_wrapper(base_val[0], array_val))
        if index != 1:
            CD_alt.append(gcd_wrapper(base_val[1], array_val))

    sorted_CD = sorted(CD)
    sorted_CD_alt = sorted(CD_alt)
    print(max([max(sorted_CD[0:2]), max(sorted_CD_alt[0:2])]))

Submission status: Wrong Answer

Solution code:
# input dummy

# N = 2
# A = [1000000000, 10000]
# N = 5
# A = [16, 24, 12, 1, 12]
# N = 3
# A = [12, 15, 18]
# A = [7, 6, 8]

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

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


def gcd_wrapper(x, y):
    if x >= y:
        return gcd(x, y)
    else:
        return gcd(y, x)

if N == 2:
    print(max(A))
else:
    CD = []
    for index1, array_val1 in enumerate(A):

        for index2, array_val2 in enumerate(A[index1 + 1:]):
            CD.append(gcd_wrapper(A[index1], array_val2))

    sorted_CD = sorted(CD)
    print(sorted_CD[N-1:N][0])

Submission status: Wrong Answer

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

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


def gcd_wrapper(x, y):
    if x >= y:
        return gcd(x, y)
    else:
        return gcd(y, x)

if N == 2:
    print(max(A))
else:
    CD = []
    for index1, array_val1 in enumerate(A):

        for index2, array_val2 in enumerate(A[index1 + 1:]):
            CD.append(gcd_wrapper(A[index1], array_val2))

    sorted_CD = sorted(CD)
    print(sorted_CD)
    print(sorted_CD[N-1:N][0])

Submission status: Wrong Answer

Solution code:
import fractions

def get_m(_a, i):
  def _gcd(a, b):
    if a == 0:
      return b
    elif b == 0:
      return a
    else:
      return fractions.gcd(a, b)

  l = 0
  for t in range(0, i):
    l = _gcd(l, _a[t])
  r = 0
  for t in range(n-1, i, -1):
    r = _gcd(r, _a[t]) 
  return _gcd(l, r)

n = int(input())
a = list(map(int, input().split()))
gcds = []
for i in range(0, n-1):
  gcds.append(get_m(a, i))
print(max(gcds))

Submission status: Wrong Answer

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

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


def gcd_wrapper(x, y):
    if x >= y:
        return gcd(x, y)
    else:
        return gcd(y, x)

if N == 2:
    print(max(A))
else:
    CD = []
    CD_alt = []
    base_val = sorted(A)
    for index, array_val in enumerate(A):
        if index != 0:
            CD.append(gcd_wrapper(base_val[0], array_val))
        if index != 1:
            CD_alt.append(gcd_wrapper(base_val[1], array_val))

    sorted_CD = sorted(CD)
    sorted_CD_alt = sorted(CD_alt)
    print(sorted_CD)
    print(sorted_CD_alt)
    print(max([max(sorted_CD[0:2]), max(sorted_CD_alt[0:2])]))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split(' ')

for i in range(N):
    A[i] = int(A[i])

A_min = min(A)

flag = 0
for term in A:

    count = 0

    for i in range(N):
        if(A[i] % term != 0):
            count += 1
        if(count >= 2):
            break

    if(count <= 1):
        flag = 1
        break

if(flag == 1):
    print(term)
else:
    for term in range(1, A_min):
        
        term = A_min - term
        count = 0

        for i in range(N):
            if(A[i] % term != 0):
                count += 1
            if(count >= 2):
                break

        if(count <= 1):
            break

    print(term)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split(' ')
 
for i in range(N):
    A[i] = int(A[i])
 
A_min = min(A)
 
flag = 0
for term in A:
 
    count = 0
 
    for i in range(N):
        if(A[i] % term != 0):
            count += 1
        if(count >= 2):
            break
 
    if(count <= 1):
        flag = 1
        break
 
if(flag == 1):
    print(term)
else:
    for term in reversed(range(1, A_min)):
 
        count = 0
 
        for i in range(N):
            if(A[i] % term != 0):
                count += 1
            if(count >= 2):
                break
 
        if(count <= 1):
            break
 
    print(term)

Submission status: Wrong Answer

Solution code:
import copy
import fractions
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
max_gcd = 1
for i in range(0, n-1):
  _a = copy.copy(a)
  _a.pop(i)
  _gcd = reduce(fractions.gcd, _a)
  if _gcd > max_gcd:
    max_gcd = _gcd
print(max_gcd)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split(' ')
 
for i in range(N):
    A[i] = int(A[i])
 
A_min = min(A)
 
flag = 0
for term in A:
 
    count = 0
 
    for i in range(N):
        if(A[i] % term != 0):
            count += 1
        if(count == 2):
            break
 
    if(count <= 1):
        flag = 1
        break
 
if(flag == 1):
    print(term)
else:
    for term in reversed(range(1, A_min)):
 
        count = 0
 
        for i in range(N):
            if(A[i] % term != 0):
                count += 1
            if(count >= 2):
                break
 
        if(count <= 1):
            break
 
    print(term)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

n = int(input())
a_array = sorted([int(x) for x in input().split()])
gcd_array = []
gcd_reverse_array = []
tmp = a_array[0]
tmp_reverse = a_array[-1]
for i, j in zip(a_array, a_array[::-1]):
    tmp = gcd(tmp, i)
    tmp_reverse = gcd(tmp_reverse, j)
    gcd_array.append(tmp)
    gcd_reverse_array.append(tmp_reverse)

gcd_reverse_array = gcd_reverse_array[::-1]
res = 0
for i in range(n):
    if i == 0:
        res = max(res, gcd_reverse_array[1])
    elif i == n - 1:
        res = max(res, gcd_array[-2])
    else:
        res = max(res, gcd(gcd_array[i-1], gcd_reverse_array[-i]))
print(res)

Submission status: Wrong Answer

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

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


def gcd_wrapper(x, y):
    if x >= y:
        return gcd(x, y)
    else:
        return gcd(y, x)

if N == 2:
    print(max(A))
else:
    CD = []
    CD_alt = []
    for index, array_val in enumerate(A):
        if index != 0:
            CD.append(gcd_wrapper(A[0], array_val))
        if index != 1:
            CD_alt.append(gcd_wrapper(A[1], array_val))
    sorted_CD = sorted(CD)
    sorted_CD_alt = sorted(CD_alt)
    print(max([max(sorted_CD[0:2]), max(sorted_CD_alt[0:2])]))

Submission status: Wrong Answer

Solution code:
import fractions

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

l = [0 for i in range(n+1)]
r = [0 for i in range(n+1)]
l[1] = a[0]
r[n-1] = a[n-1]
for i in range(2, n+1):
  l[i] = fractions.gcd(l[i-1], a[i-1])
  r[n-i] = fractions.gcd(r[n-i+1], a[n-i])
  
max_gcd = 1
for i in range(n-1):
  if l[i] == 0 or r[i+1] == 0:
    gcd_ = l[i] + r[i+1]
  else:
    gcd_ = fractions.gcd(l[i], r[i+1])
  max_gcd = max(max_gcd, gcd_)
print(max_gcd)

Submission status: Wrong Answer

Solution code:
import random
import heapq

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

N = 3
A = [12, 15, 18]
# A = [random.randint(0, 1000000) for i in range(100)]
# process

# Common divisor
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義

CD = []
for i in A[1:]:
    if A[0] >= i:
        CD.append(gcd(A[0], i))
    else:
        CD.append(gcd(i, A[0]))


print(min(heapq.nlargest(2, CD)))

Submission status: Wrong Answer

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

front, back = [0], [0]
for a in A:
    front.append(gcd(front[-1], a))
front.append(0)
for a in A[::-1]:
    back.append(gcd(back[-1], a))
back = [0] + back[::-1]


ans = 0
for i in range(1, N):
    ans = max(ans, gcd(front[i - 1], back[i + 1]))
print(ans)

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=[]
tmp=0
sumx=0
val=[]
A = list(map(int, input().split()))

for i in range(0,N):
    for j in range(i,N):
        if(i!=j):
            val.append(gcd(A[i],A[j]))
print(max(val))

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=[]
tmp=0
sumx=0
val=[]
A = list(map(int, input().split()))

for i in range(0,N):
    for j in range(0,N):
        if(i!=j):
            val.append(gcd(A[i],A[j]))
print(max(val))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
def gcd(L):
    nextminb = L[0]
    nextn = len(L)
    while True:
        n = nextn
        minb = nextminb
        for l in L[:n]:
            nextn = 0
            r= l % minb
            
            if r != 0:
                L[nextn] = r
                nextn += 1
                if r < nextminb :
                    nextminb = r
        if minb == nextminb:
            return minb
        


lgcd = [0] * N
rgcd = [0] * N

for i in range(N):
    lgcd[i] = gcd(A[0:i+1])
    rgcd[i] = gcd(A[i:])
maxg = max(lgcd[N-2],rgcd[1])
for i in range(1,N-1):
    g = gcd([lgcd[i-1],rgcd[i+1]])
    if maxg < g:
        maxg = g

print(maxg)

Submission status: Wrong Answer

Solution code:
import collections

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

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

list = []
for i in a:
    list.extend(make_divisors(i))

list = sorted(list,reverse=True)

c = collections.Counter(list)
values, counts = zip(*c.most_common())


first = []
second = []
for value, count in zip(values,counts):
    if count == n:
        first.append(value)
    if count == n-1:
        second.append(value)
        break

if len(second) == 0:
    print(max(first))

elif max(first) > max(second):
    print(max(first))

else:
    print(max(second))

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
a = list(map(int,input().split()))
ans = 1
if len(a) == 2:
  print(max(a))
else:
  for i in range(n):
    b = copy.deepcopy(a)
    b.pop(i)
    b.sort
    b0 = b[0]
    print(b)
    for j in range(1,n-1):
      b1 = b[j]
      r = 0
      while True:
        r = b1 % b0
        if r == 0:
          break
        elif r > b0:
          b1, b0 = r, b0
        else:
          b1, b0 = b0, r
    if b0 > ans:
      ans = b0
  print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
v = [int(i) for i in input().split()]
if n == 2:
    print(max(v))


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


l = [0 for i in range(n)]
r = [0 for i in range(n)]

for i in range(1, n):
    l[i] = gcd(l[i - 1], v[i - 1])
for i in range(n - 1)[::-1]:
    r[i] = gcd(r[i+1], v[i+1])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
v = [int(i) for i in input().split()]
if n == 2:
    print(max(v))


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


l = [0 for i in range(n)]
r = l[:]

for i in range(1, n):
    l[i] = gcd(l[i - 1], v[i - 1])
for i in range(n - 1)[::-1]:
    r[i] = gcd(r[i+1], v[i+1])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
v = [int(i) for i in input().split()]
if n == 2:
    print(max(v))


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


l = [0 for i in range(n)]
r = l[:]

for i in range(1, n):
    l[i] = gcd(l[i - 1], v[i - 1])
for i in range(n - 1)[::-1]:
    r[i] = gcd(r[i+1], v[i+1])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
v = [int(i) for i in input().split()]
if n == 2:
    print(max(v))


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


l = [0 for i in range(n)]
r = l[:]

for i in range(1, n):
    l[i] = gcd(l[i - 1], v[i - 1])
for i in range(n - 1)[::-1]:
    r[i] = gcd(r[i-1], v[i-1])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
v = [int(i) for i in input().split()]
if n == 2:
    print(max(v))

l = [0 for i in range(n)]
r = l[:]
l[1] = v[0]
r[-2] = v[-1]


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


for i in range(1, n-1):
    l[i + 1] = gcd(l[i], v[i])
    r[-i-2] = gcd(r[-i-1], v[-i-1])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
v = [int(i) for i in input().split()]
if n == 2:
    print(max(v))

l = [0 for i in range(n)]
r = l[:]


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


for i in range(n-1):
    l[i + 1] = gcd(l[i], v[i])
    r[-i-2] = gcd(r[-i-1], v[-i-1])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
v = [int(i) for i in input().split()]
if n == 2:
    print(max(v))

l = [0 for i in range(n)]
r = l[:]


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


for i in range(1, n):
    l[i] = gcd(l[i-1], v[i-1])
    r[-i-1] = gcd(r[-i], v[-i])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
v = [int(i) for i in input().split()]
if n == 2:
    print(max(v))

l = [0 for i in range(n)]
r = l[:]


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


for i in range(n-1):
    l[i+1] = gcd(l[i], v[i])
for i in range(n - 1)[::-1]:
    r[i] = gcd(r[i + 1], v[i + 1])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
v = [int(i) for i in input().split()]
if n == 2:
    print(max(v))

l = [0 for i in range(n)]
r = l[:]


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


for i in range(n):
    l[i] = gcd(l[i-1], v[i-1])
for i in range(n - 1)[::-1]:
    r[i] = gcd(r[i + 1], v[i + 1])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from itertools import accumulate

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

l = list(accumulate(a, gcd))

r = list(reversed(list(accumulate(reversed(a), gcd))))

if n >= 3:
    ans = max(gcd(li, ri) for li, ri in zip(l[:-2], r[2:]))
    ans = max(ans, l[-1], r[1])
else:
    ans = max(l[-1], r[1])

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

l = [0] * n
l[0] = a[0]
for i in range(1, n):
    l[i] = gcd(l[i - 1], a[i])

r = [0] * n
r[-1] = a[-1]
for i in reversed(range(0, n - 1)):
    r[i] = gcd(r[i + 1], a[i])

if n >= 3:
    ans = max(gcd(li, ri) for li, ri in zip(l[:-2], r[2:]))
    ans = max(ans, l[-1], r[1])
else:
    ans = max(l[-1], r[1])

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import functools
import sys

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

left_gcd = [a[0]]
for i in range(1,len(a)):
  left_gcd.append(gcd(left_gcd[-1],a[i]))
#print(left_gcd)
  
right_gcd = [a[-1]]
for i in range(len(a)-1)[::-1]:
  right_gcd.append(gcd(right_gcd[-1],a[i]))
right_gcd = right_gcd[::-1]
#print(right_gcd)

each_gcd = [right_gcd[1]]
for i in range(1,len(a)-1):
  each_gcd.append(gcd(left_gcd[i-1],right_gcd[i+1]))
each_gcd.append(left_gcd[len(a)-1])

#print(each_gcd)
print(max(each_gcd))

Submission status: Wrong Answer

Solution code:
from fractions import *
N = int(input())
A = list(map(int, input().split()))
left = [A[0]]
right = [A[-1]]
for i in range(1, N):
    left.append(gcd(A[i], left[-1]))
    right.append(gcd(A[N-1-i], right[-1]))
right = right[::-1]
ans = right[1]
for i in range(1, N-1):
    ans = max(ans, gcd(left[i-1], right[i+1]))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
  if a*b==0:
    return a if b==0 else b
  else:
    while b:
      a,b=b,a%b
  return a

B=[0]*(n+5)
C=[0]*(n+5)

for i in range(n-2):
  B[i+1]=gcd(B[i],A[i])
  C[i+1]=gcd(C[i],A[n-i-1])
po=0
for i in range(n):
  po=max(po,gcd(B[i],C[n-1-i]))
print(po)

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())
if n == 2:
  q,w = map(int,input().split())
  print(gcd(q,w))
  exit()
  
s = list(map(int,input().split()))
max,a = 0,0

for i in range(n):
  sr = s[0:i]+s[i+1:n]
  a = gcd(sr[0],sr[1])
  for j in range(2,n-1):
    a = gcd(a,sr[j])
  if max<a:
    max = a
print(max)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split(' ')

for i in range(N):
    A[i] = int(A[i])

A_min = min(A)

flag = 0
for term in A:

    count = 0

    for i in range(N):
        if(A[i] % term != 0):
            count += 1
        if(count == 2):
            break

    if(count <= 1):
        flag = 1
        break

if(flag == 1):
    print(term)
else:
    for term in reversed(range(1, A_min)):

        count = 0

        for i in range(N):
            if(A[i] % term != 0):
                count += 1
            if(count == 2):
                break

        if(count <= 1):
            break

    print(term)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split(' ')

for i in range(N):
    A[i] = int(A[i])

A_min = min(A)

flag = 0
for term in A:

    count = 0

    for i in range(N):
        if(A[i] % term != 0):
            count += 1
        if(count == 2):
            break

    if(count <= 1):
        flag = 1
        break

if(flag == 1):
    print(term)
else:
    for term in reversed(range(0, A_min)):

        count = 0

        for i in range(N):
            if(A[i] % term != 0):
                count += 1
            if(count == 2):
                break

        if(count <= 1):
            break

    print(term)