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:
from functools import reduce
import fractions
n=int(input())
a=list(map(int,input().split()))
gcd0=reduce(fractions.gcd,a[1:])
gcdn=reduce(fractions.gcd,a[:n])
gcd=1
for i in range(1,n-1):
    gcd1=reduce(fractions.gcd,a[:i])
    gcd2=reduce(fractions.gcd,a[i+1:])
    gcdi=fractions.gcd(gcd1,gcd2)
    if gcd<gcdi:
        gcd=gcdi
print(max(gcd0,gcd,gcdn))

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())

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

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

s = []
for i in itertools.combinations(A,2):
  s.append(gcd(i[0],i[1]))

print(max(s))

Submission status: Wrong Answer

Solution code:
# coding:UTF-8


def calc_gcd(num1, num2):
    """
    最大公約数算出
    :param num1: 対象の値1
    :param num2: 対象の値2
    :return:最大公約数
    """
    if num1 < num2:
        num1, num2 = num2, num1

    while num2 > 0:
        remainder = num1 % num2

        num1 = num2
        num2 = remainder

    return num1


# 値の個数を取得
num_count = int(input())

# 最大公約数を求める対象の値群を取得
target_num = list(map(int, input().split()))

# 累積GCDリスト(可変で扱うと処理速度が遅くなるため、あらかじめ領域を確保)
left_gcd = [0] * (num_count + 1)  # +1は0用の領域(1番目を除外する場合に使用)
right_gcd = [0] * (num_count + 1)  # 同上

for i in range(num_count):
    left_gcd[i+1] = calc_gcd(left_gcd[i], target_num[i])
    right_gcd[num_count-1-i] = calc_gcd(right_gcd[num_count-i], target_num[num_count-1-i])

print(left_gcd)
print(right_gcd)

gcd = 0

for i in range(num_count):
    result = calc_gcd(left_gcd[i], right_gcd[i+1])
    if gcd < result:
        gcd = result

print(gcd)

Submission status: Wrong Answer

Solution code:
# coding:UTF-8


def calc_gcd(num1, num2):
    """
    最大公約数算出
    :param num1: 対象の値1
    :param num2: 対象の値2
    :return:最大公約数
    """
    if num1 < num2:
        num1, num2 = num2, num1

    while num2 > 0:
        remainder = num1 % num2

        num1 = num2
        num2 = remainder

    return num1


# 値の個数を取得
num_count = int(input())

# 最大公約数を求める対象の値群を取得
target_num = list(map(int, input().split()))

# 累積GCDリスト(可変で扱うと処理速度が遅くなるため、あらかじめ領域を確保)
left_gcd = [0] * num_count  # +1は0用の領域(1番目を除外する場合に使用)
right_gcd = [0] * num_count  # 同上

for i in range(num_count-1):
    left_gcd[i+1] = calc_gcd(left_gcd[i], target_num[i])
    right_gcd[num_count-2-i] = calc_gcd(right_gcd[num_count-1-i], target_num[num_count-1-i])

print(left_gcd)
print(right_gcd)

gcd = 0

for i in range(num_count):
    result = calc_gcd(left_gcd[i], right_gcd[i])
    if gcd < result:
        gcd = result

print(gcd)

Submission status: Wrong Answer

Solution code:
import sys
import copy
from functools import reduce

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

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    
    l = []
    l2 = []
    
    for i in range(N):
    
        l2 = copy.deepcopy(A)
        l2.pop(i)
        
        l.append(max([ gcd(A[i], j) for j in l2 ]))
    
    print(max(l))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    
    A_max = max(A)
    
    l = [A_max % a for a in A]
    
    print(max(l) if max(l) != 0 else A_max)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import fractions as mt

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


def solve(n: int, a: list):
    lgcd = [0] * (n - 1)
    lgcd[0] = a[0]
    for i in range(1, n - 1):
        lgcd[i] = mt.gcd(a[i], lgcd[i - 1])
    a.reverse()

    rgcd = [0] * (n - 1)
    rgcd[0] = a[0]
    for i in range(1, n - 1):
        rgcd[i] = mt.gcd(a[i], rgcd[i - 1])
    a.reverse()

    ans = [0] * n
    ans[0] = rgcd[n - 2]
    ans[n - 1] = lgcd[n - 2]
    for i in range(1, n):
        ans[i] = mt.gcd(lgcd[i - 1], rgcd[n - 2 - i])
    ans.append(1)
    return max(ans)


print(solve(N, A))

Submission status: Wrong Answer

Solution code:
import fractions as mt

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


def solve(n: int, a: list):
    lgcd = [0] * (n - 1)
    lgcd[0] = a[0]
    for i in range(1, n - 1):
        lgcd[i] = mt.gcd(a[i], lgcd[i - 1])
    a.reverse()

    rgcd = [0] * (n - 1)
    rgcd[0] = a[0]
    for i in range(1, n - 1):
        rgcd[i] = mt.gcd(a[i], rgcd[i - 1])
    a.reverse()

    ans = [0] * n
    ans[0] = rgcd[n - 2]
    ans[n - 1] = lgcd[n - 2]
    for i in range(1, n):
        ans[i] = mt.gcd(lgcd[i - 1], rgcd[n - 2 - i])

    return max(ans)


print(solve(N, A))

Submission status: Wrong Answer

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

def GCD(N,A_i):
  if N==2:
    GCD=max(A_i)
  else:
    GCD=[]
    for i in range(N):
      A=A_i.copy()
      A=np.array(A)
      ind=[True]*N
      ind[i]=False
      A[i]=np.random.choice(A[ind],1)
      ans=A[0]
      for j in range(1,N):
        ans=gcd(ans,A[j])
      GCD.append(ans)
  return GCD

print("{}".format(N,A_i))

Submission status: Wrong Answer

Solution code:
#import math
import fractions

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

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

others_gcd = []
for i in range(0, N) :
    max_gcd = 1
    for j in range(0, N) :
        if i == j :
            continue
        #gcd = math.gcd(A[i], A[j])
        gcd = fractions.gcd(A[i], A[j])
        max_gcd = max(max_gcd, gcd)
    others_gcd.append(max_gcd)

print(max(others_gcd))

Submission status: Wrong Answer

Solution code:
import fractions
N=int(input())
a=list(map(int,input().split()))
b=[a[0]]

#ansをa[0]と置く
ans=a[0]
#ansに一つ前のansとa[i]の最大公約数を代入する
for i in range(1,N):  
  ans_i=(fractions.gcd(b[i-1],a[i]))
  b.append(ans_i)
b.sort(reverse=True)
print(b)

b.pop(N-1)
print(b)

ans=b[0]
for i in range(1,N-1):
  ans=(fractions.gcd(ans,b[i]))
       
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

def gcd(x, y):
    if x == 0:
        return y
    if y == 0:
        return x
        
    if y > x:
        temp = y
        y = x
        x = temp
    amari = x % y
    if amari == 0:
        return y
    else:
        return gcd(y, amari)
        
L = [0]
for i in range(N):
    l = L[-1]
    L.append(gcd(l, A[i]))
    
R = [0]
for i in reversed(range(N)):
    r = R[0]
    R.insert(0, gcd(r, A[i]))

M = [gcd(L[i], R[i+1]) for i in range(N)] # i=1,...,N

print(L)
print(R)
print(M)

print(max(M))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

def gcd(x, y):
    if x == 0:
        return y
    if y == 0:
        return x
        
    if y > x:
        temp = y
        y = x
        x = temp
    amari = x % y
    if amari == 0:
        return y
    else:
        return gcd(y, amari)
        
L = [0]
for i in range(N):
    l = L[-1]
    L.append(gcd(l, A[i]))
    
R = [0]
for i in reversed(range(N)):
    r = L[0]
    R.insert(0, A[i])

M = [gcd(L[i], R[i+1]) for i in range(N)] # i=1,...,N

print(max(M))

Submission status: Wrong Answer

Solution code:
from functools import reduce
import fractions


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

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

    print(algorithm(N, A))

def algorithm(N, A):
    if N == 0:
        return 0
    if N == 1:
        return A[0]
    if N == 2:
        return max(A[0],A[1])

    L_i = 0
    R_i = [0] * N
    R_i[N - 1] = A[N - 1]
    R_i[N-2] = fractions.gcd(A[N-1], A[N-2])
    
    for i in range(3,N):
        R_i[N - i] = fractions.gcd(R_i[N - i + 1], A[N - i])

    maxGCD = R_i[1]
    for i in range(1, N-1):
        L_i = fractions.gcd(L_i, A[i - 1])
        tmp = fractions.gcd(L_i, R_i[i+1])
        if tmp > maxGCD:
            maxGCD = tmp

    L_i = fractions.gcd(L_i, A[N - 1])
    if L_i > maxGCD:
        maxGCD = L_i
    return maxGCD


problem()

Submission status: Wrong Answer

Solution code:
from functools import reduce
import fractions


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

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

    print(algorithm(N, A))


def algorithm(N, A):
    if N == 0:
        return 0
    if N == 1:
        return A[0]
    if N == 2:
        return max(A[0],A[1])
        
    L_i = 0
    R_i = [0] * N
    R_i[N - 1] = A[N - 1]
    
    for i in range(2,N):
        R_i[N - i] = fractions.gcd(R_i[N - i + 1], A[N - i])

    maxGCD = R_i[1]
    for i in range(1, N-1):
        L_i = fractions.gcd(L_i, A[i - 1])
        tmp = fractions.gcd(L_i, R_i[i+1])
        if tmp > maxGCD:
            maxGCD = tmp

    L_i = fractions.gcd(L_i, A[N - 1])
    if L_i > maxGCD:
        maxGCD = L_i
    return maxGCD

problem()

Submission status: Wrong Answer

Solution code:
from functools import reduce
import fractions


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

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

    print(algorithm(N, A))


def algorithm(N, A):
    if N == 0:
        return 0
    if N == 1:
        return A[0]

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

    maxGCD = R_i[1]
    for i in range(1, N-1):
        L_i = fractions.gcd(L_i, A[i - 1])
        tmp = fractions.gcd(L_i, R_i[i+1])
        if tmp > maxGCD:
            maxGCD = tmp

    L_i = fractions.gcd(L_i, A[N - 1])
    if L_i > maxGCD:
        maxGCD = L_i
    return maxGCD

problem()

Submission status: Wrong Answer

Solution code:
from functools import reduce
import fractions


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

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

    print(algorithm(N, A))


def algorithm(N, A):
    if N == 0:
        return 0

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

    maxGCD = R_i[1]
    for i in range(1, N-1):
        L_i = fractions.gcd(L_i, A[i - 1])
        tmp = fractions.gcd(L_i, R_i[i+1])
        if tmp > maxGCD:
            maxGCD = tmp

    L_i = fractions.gcd(L_i, A[N - 1])
    if L_i > maxGCD:
        maxGCD = L_i
    return maxGCD

problem()

Submission status: Wrong Answer

Solution code:
from functools import reduce
import fractions


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

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

    print(algorithm(N, A))


def algorithm(N, A):
    L_i = 0
    R_i = gcd_list(A[1:])
    maxGCD = R_i

    for i in range(1,N):
        L_i = fractions.gcd(L_i, A[i-1])
        right = A[i + 1 :]
        if len(right) != 0:
            tmp = fractions.gcd(L_i, gcd_list(right))
            if tmp > maxGCD:
                maxGCD = tmp

    return maxGCD
  
problem()

Submission status: Wrong Answer

Solution code:
from functools import reduce
import fractions


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

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

    print(algorithm(N, A))



def algorithm(N, A):
    L_i = 0
    maxGCD = 0

    for i in range(N):
        L_i = fractions.gcd(L_i, A[i-1] if i > 0 else 0)
        right = A[i + 1 :]
        if len(right) != 0:
            tmp = fractions.gcd(L_i, gcd_list(right))
            if tmp > maxGCD:
                maxGCD = tmp

    return maxGCD
problem()

Submission status: Wrong Answer

Solution code:
from functools import reduce
import fractions


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

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

    print(algorithm(N, A))


def algorithm(N, A):
    gcdList = [0] * N
    L_i = 0

    for i in range(N):
        L_i = fractions.gcd(L_i, A[i-1] if i > 0 else 0)
        right = A[i + 1 :]
        if len(right) != 0:
            gcdList[i] = fractions.gcd(L_i, gcd_list(right))

    return max(gcdList)
problem()

Submission status: Wrong Answer

Solution code:
from functools import lru_cache, reduce


@lru_cache(maxsize=None)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    # As = sorted(As, reverse=True)

    memG = 0
    if N == 2:
        memG = gcd(As[0], As[1])
    elif N < 10:
        for i in range(N):
            tmp = As[:i] + As[i + 1 :]
            g = reduce(gcd, tmp)
            if g > memG:
                memG = g
    else:
        gLeft = {0: As[0], 1: gcd(As[0], As[1])}
        for i in range(2, N):
            gI = gcd(gLeft[i - 1], As[i])
            gLeft[i] = gI
        gRight = {N - 1: As[N - 1], N - 2: gcd(As[N - 1], As[N - 2])}
        for i in range(2, N):
            gI = gcd(gRight[N - i], As[N - 1 - i])
            gRight[N - 1 - i] = gI

        buf = []
        for i in range(N):
            leftG = None
            if (i - 1) in gLeft:
                leftG = gLeft[i - 1]
            rightG = None
            if (i + 1) in gRight:
                rightG = gRight[i + 1]
            # tmpG = None
            if leftG is None:
                leftG = rightG
            elif rightG is None:
                rightG = leftG
            buf.append(gcd(leftG, rightG))
            # tmpG = gcd(leftG, rightG)
            # if tmpG > memG:
            #     memG = tmpG
        memG = max(buf)

    print("{}".format(memG))


sub()

Submission status: Wrong Answer

Solution code:
from functools import lru_cache


@lru_cache(maxsize=None)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    As = sorted(As, reverse=True)

    memG = 0
    if N == 2:
        memG = gcd(As[0], As[1])
    else:
        gLeft = {0: As[0], 1: gcd(As[0], As[1])}
        for i in range(2, N):
            gI = gcd(gLeft[i - 1], As[i])
            gLeft[i] = gI
        gRight = {N - 1: As[N - 1], N - 2: gcd(As[N - 1], As[N - 2])}
        for i in range(2, N):
            gI = gcd(gRight[N - i], As[N - 1 - i])
            gRight[N - 1 - i] = gI

        buf = []
        for i in range(N):
            leftG = None
            if (i - 1) in gLeft:
                leftG = gLeft[i - 1]
            rightG = None
            if (i + 1) in gRight:
                rightG = gRight[i + 1]
            # tmpG = None
            if leftG is None:
                leftG = rightG
            elif rightG is None:
                rightG = leftG
            buf.append(gcd(leftG, rightG))
            # tmpG = gcd(leftG, rightG)
            # if tmpG > memG:
            #     memG = tmpG
        memG = max(buf)

    print("{}".format(memG))


sub()

Submission status: Wrong Answer

Solution code:
from functools import lru_cache


@lru_cache(maxsize=None)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    # As = sorted(As, reverse=True)

    memG = 0
    if N == 2:
        memG = gcd(As[0], As[1])
    else:
        gLeft = {0: As[0], 1: gcd(As[0], As[1])}
        for i in range(2, N):
            gI = gcd(gLeft[i - 1], As[i])
            gLeft[i] = gI
        gRight = {N - 1: As[N - 1], N - 2: gcd(As[N - 1], As[N - 2])}
        for i in range(2, N):
            gI = gcd(gRight[N - i], As[N - 1 - i])
            gRight[N - 1 - i] = gI

        buf = []
        for i in range(N):
            leftG = None
            if (i - 1) in gLeft:
                leftG = gLeft[i - 1]
            rightG = None
            if (i + 1) in gRight:
                rightG = gRight[i + 1]
            # tmpG = None
            if leftG is None:
                leftG = rightG
            elif rightG is None:
                rightG = leftG
            buf.append(gcd(leftG, rightG))
            # tmpG = gcd(leftG, rightG)
            # if tmpG > memG:
            #     memG = tmpG
        memG = max(buf)

    print("{}".format(memG))


sub()

Submission status: Wrong Answer

Solution code:
from functools import lru_cache


@lru_cache(maxsize=None)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    # As = sorted(As, reverse=True)

    memG = 0
    if N == 2:
        memG = gcd(As[0], As[1])
    else:
        gLeft = {0: As[0], 1: gcd(As[0], As[1])}
        for i in range(2, N):
            gI = gcd(gLeft[i - 1], As[i])
            gLeft[i] = gI
        gRight = {N - 1: As[N - 1], N - 2: gcd(As[N - 1], As[N - 2])}
        for i in range(2, N):
            gI = gcd(gRight[N - i], As[N - 1 - i])
            gRight[N - 1 - i] = gI

        for i in range(N):
            leftG = None
            if (i - 1) in gLeft:
                leftG = gLeft[i - 1]
            rightG = None
            if (i + 1) in gRight:
                rightG = gRight[i + 1]
            tmpG = None
            if leftG is None:
                leftG = rightG
            elif rightG is None:
                rightG = leftG
            tmpG = gcd(leftG, rightG)
            if tmpG > memG:
                memG = tmpG

    print("{}".format(memG))


sub()

Submission status: Wrong Answer

Solution code:
from functools import lru_cache


@lru_cache(maxsize=None)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    # As = sorted(As, reverse=True)

    memG = 0
    if N == 2:
        memG = gcd(As[0], As[1])
    else:
        gLeft = {0: As[0], 1: gcd(As[0], As[1])}
        for i in range(2, N):
            gI = gcd(gLeft[i - 1], As[i])
            gLeft[i] = gI
        gRight = {N - 1: As[N - 1], N - 2: gcd(As[N - 1], As[N - 2])}
        for i in range(2, N):
            gI = gcd(gRight[N - i], As[N - 1 - i])
            gRight[N - 1 - i] = gI

        for i in range(N):
            leftG = None
            if (i - 1) in gLeft:
                leftG = gLeft[i - 1]
            rightG = None
            if (i + 1) in gRight:
                rightG = gRight[i + 1]
            assert leftG is not None or rightG is not None
            tmpG = None
            if leftG is None:
                tmpG = rightG
            elif rightG is None:
                tmpG = leftG
            else:
                tmpG = gcd(leftG, rightG)
            if tmpG > memG:
                memG = tmpG

        # for i in range(N):
        #     tmp = As[:i] + As[i + 1 :]
        #     gI = gcd(tmp[0], tmp[1])
        #     tmp = tmp[2:]
        #     for t in tmp:
        #         gI = gcd(t, gI)
        #         if gI < memG:
        #             break
        #     if gI > memG:
        #         memG = gI
    print("{}".format(memG))


sub()

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

n=input()
targets=set([int(i) for i in input().split()])
max_gcd = 0
if len(targets) < 3:
    max_gcd = max(targets)
else:
    for i in targets:
        gcd = reduce(fractions.gcd, targets - {i})
        if gcd > max_gcd:
            max_gcd = gcd
print(max_gcd)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

n=input()
targets=set([int(i) for i in input().split()])
max_gcd = 0
for i in targets:
    gcd = reduce(fractions.gcd, targets - {i} if len(targets) > 1 else targets)
    if gcd > max_gcd:
        max_gcd = gcd
print(max_gcd)

Submission status: Wrong Answer

Solution code:
from functools import lru_cache


@lru_cache(maxsize=None)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    # As = sorted(As, reverse=True)

    memG = 0
    if N == 2:
        memG = gcd(As[0], As[1])
    else:
        gLeft = {1: gcd(As[0], As[1])}
        for i in range(2, N):
            gI = gcd(gLeft[i - 1], As[i])
            gLeft[i] = gI

        gRight = {N - 2: gcd(As[N - 1], As[N - 2])}
        for i in range(2, N):
            gI = gcd(gRight[N - i], As[N - 1 - i])
            gRight[N - 1 - i] = gI

        for i in range(N):
            leftG = None
            if i - 1 in gLeft:
                leftG = gLeft[i - 1]
            rightG = None
            if i + 1 in gRight:
                rightG = gRight[i + 1]
            if leftG is None:
                memG = rightG
            elif rightG is None:
                memG = leftG
            else:
                memG = gcd(leftG, memG)

        # for i in range(N):
        #     tmp = As[:i] + As[i + 1 :]
        #     gI = gcd(tmp[0], tmp[1])
        #     tmp = tmp[2:]
        #     for t in tmp:
        #         gI = gcd(t, gI)
        #         if gI < memG:
        #             break
        #     if gI > memG:
        #         memG = gI
    print("{}".format(memG))


sub()

Submission status: Wrong Answer

Solution code:
from functools import lru_cache

@lru_cache(maxsize=None)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    # As = sorted(As, reverse=True)

    memG = 0
    if N == 2:
        memG = gcd(As[0], As[1])
    else:
        for i in range(N):
            tmp = As[:i] + As[i + 1 :]
            gI = gcd(tmp[0], tmp[1])
            tmp = tmp[2:]
            for t in tmp:
                gI = gcd(t, gI)
                if gI < memG:
                    break
            if gI > memG:
                memG = gI
    print("{}".format(memG))


sub()

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  
n=int(input())
l=list(map(int,input().split()))
if n==2:
  print(max(l))
else:
  ma=0
  if gcd(l[-1],l[-2])>ma:
    ma=gcd(l[-1],l[-2])
  if gcd(l[-2],l[-3])>ma:
    ma=gcd(l[-2],l[-3])
  if gcd(l[-3],l[-1])>ma:
    ma=gcd(l[-3],l[-1])
  print(ma)

Submission status: Wrong Answer

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


def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    # As = sorted(As, reverse=True)

    memG = 0
    if N == 2:
        memG = gcd(As[0], As[1])
    else:
        for i in range(N):
            tmp = As[:i] + As[i + 1 :]
            gI = gcd(tmp[0], tmp[1])
            tmp = tmp[2:]
            for t in tmp:
                gI = gcd(t, gI)
                if gI < memG:
                    break
            if gI > memG:
                memG = gI
    print("{}".format(memG))


sub()

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  
n=int(input())
l=list(map(int,input().split()))
if n==2:
  print(max(l))
else:
  ma=0
  if gcd(l[0],l[1])>ma:
    ma=gcd(l[0],l[1])
  if gcd(l[1],l[2])>ma:
    ma=gcd(l[1],l[2])
  if gcd(l[0],l[2])>ma:
    ma=gcd(l[0],l[2])
  print(ma)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  
n=int(input())
l=list(map(int,input().split()))
if n==2:
  print(max(l))
else:
  ma=0
  if gcd(l[0],l[1])>ma:
    ma=gcd(l[0],l[1])
  if gcd(l[1],l[2])>ma:
    ma=gcd(l[1],l[2])
  if gcd(l[0],l[2]):
    ma=gcd(l[0],l[2])
  print(ma)

Submission status: Wrong Answer

Solution code:

import math


def gcd_list(numbers):
    return 10


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

    print(algorithm(N, A))


def algorithm(N, A):
    gcdList = [0] * N
    for i in range(N):
        copy_A = A.copy()
        copy_A.pop(i)
        gcdList[i] = gcd_list(copy_A)

    return max(gcdList)
problem()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

gcd_array = []
for index in range(n):
    if index == 0:
        gcd_array.append(a_array[0])
    else:
        gcd_array.append(gcd(gcd_array[index - 1], a_array[index]))
gcd_reversed_array = []
for index in range(n):
    if index == 0:
        gcd_reversed_array.append(a_array[index - 1])
    else:
        gcd_reversed_array.append(gcd(gcd_reversed_array[index - 1], a_array[-(index + 1)]))

res = 0
gcd_reversed_array.reverse()
for i in range(n):
    if i == 0:
        res = max(res, gcd_reversed_array[1])
    elif i == n - 1:
        res = max(res, gcd_array[1])
    else:
        res = max(res, gcd(gcd_array[i - 1], gcd_reversed_array[i+1]))
print(res)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

gcd_array = []
for index in range(n):
    if index == 0:
        gcd_array.append(a_array[0])
    else:
        gcd_array.append(gcd(gcd_array[index - 1], a_array[index]))
gcd_reversed_array = []
for index in range(n):
    if index == 0:
        gcd_reversed_array.append(a_array[index - 1])
    else:
        gcd_reversed_array.append(gcd(gcd_reversed_array[index - 1], a_array[-(index + 1)]))

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

gcd_array = []
for index in range(n):
    if index == 0:
        gcd_array.append(a_array[0])
    else:
        gcd_array.append(gcd(gcd_array[index - 1], a_array[index]))
gcd_reversed_array = []
for index in range(n):
    if index == 0:
        gcd_reversed_array.append(a_array[index - 1])
    else:
        gcd_reversed_array.append(gcd(gcd_reversed_array[index - 1], a_array[-(index + 1)]))

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

gcd_array = []
for index in range(n):
    if index == 0:
        gcd_array.append(a_array[0])
    else:
        gcd_array.append(gcd(gcd_array[index - 1], a_array[index]))
gcd_reversed_array = []
for index in range(n):
    if index == 0:
        gcd_reversed_array.append(a_array[index - 1])
    else:
        gcd_reversed_array.append(gcd(gcd_reversed_array[index - 1], a_array[-(index + 1)]))

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import numpy as np
import copy as copy
N=int(input())
A_i=list(map(int,input().split()))

def GCD(N,A_i):
  if len(A_i)==2:
    GCD=max(A_i)
  else:
    GCD=[]
    for i in range(N):
      A=A_i.copy()
      A=np.array(A)
      ind=[True]*N
      ind[i]=False
      A[i]=np.random.choice(A[ind],1)
      ans=A[0]
      for j in range(1,N):
        ans=gcd(ans,A[j])
      GCD.append(ans)
    GCD=max(GCD)
  return GCD

print("{}".format(GCD(N,A_i)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import numpy as np
import copy as copy
N=int(input())
A_i=list(map(int,input().split()))

def GCD(N,A_i):
  if len(A_i)==2:
    GCD=[max(A_i)]
  else:
    GCD=[]
    for i in range(N):
      A=A_i.copy()
      A=np.array(A)
      ind=[True]*N
      ind[i]=False
      A[i]=np.random.choice(A[ind],1)
      ans=A[0]
      for j in range(1,N):
        ans=gcd(ans,A[j])
      GCD.append(ans)
    GCD=max(GCD)
  return GCD

print("{}".format(GCD(N,A_i)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

gcd_array = []
for index in range(n):
    if index == 0:
        gcd_array.append(a_array[0])
    else:
        gcd_array.append(gcd(gcd_array[index - 1], a_array[index]))
gcd_reversed_array = []
for index in range(n):
    if index == 0:
        gcd_reversed_array.append(a_array[index - 1])
    else:
        gcd_reversed_array.append(gcd(gcd_reversed_array[index - 1], a_array[-(index + 1)]))

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import numpy as np
import copy as copy
N=int(input())
A_i=list(map(int,input().split()))

def GCD(N,A_i):
  if len(A_i)==2:
    ans=[max(A_i)]
  else:
    for i in range(N):
      A=A_i.copy()
      A=np.array(A)
      ind=[True]*N
      ind[i]=False
      A[np.where(ind==False)]=np.random.choice(A[ind],1)
      ans=A[0]
      ans=[gcd(ans,A[j]) for j in range(1,N)]
  return max(ans)

print("{}".format(GCD(N,A_i)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import numpy as np
import copy as copy
N=int(input())
A_i=list(map(int,input().split()))

def GCD(N,A_i):
  if len(A_i)==2:
    ans=[max(A_i)]
  else:
    for i in range(N):
      A=A_i.copy()
      A=np.array(A)
      ind=[True]*N
      ind[i]=False
      A[ind==False]=np.random.choice(A[ind],1)
      ans=A[0]
      ans=[gcd(ans,A[j]) for j in range(1,N)]
  return max(ans)

print("{}".format(GCD(N,A_i)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import numpy as np
import copy as copy
N=int(input())
A_i=list(map(int,input().split()))

def GCD(N,A_i):
  if len(A_i)==2:
    ans=[max(A_i)]
  else:
    for i in range(N):
      A=A_i.copy()
      A=np.array(A)
      ind=[True]*N
      ind[i]=False
      A[ind]=np.random.choice(A[ind],1)
      ans=A[0]
      ans=[gcd(ans,A[j]) for j in range(1,N)]
  return max(ans)

print("{}".format(GCD(N,A_i)))