Problem: 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.

Submission attempts (in order):
import numpy as np

def gcd(a,b):    
        if a < b:
            a, b = b, a
        if b == 0:
            return a
        c = a % b
        return gcd(b, c)
    
N = int(input())
A_list = list(map(int, input().split()))

# =====
# initialize L and R
# =====
L = np.zeros(N+1)
R = np.zeros(N+1)

for idx, element in enumerate(A_list):
    if idx == 0:
        continue
    else:
        if L[idx-1] == 0:
            L[idx] = element
        L[idx] = gcd(L[idx-1], element)

for idx, element in enumerate(A_list[-1::-1]):
    idx = N-idx
    if idx == N:
        continue
    else:
        if R[idx+1] == 0:
            R[idx] = element
        R[idx] = gcd(R[idx+1], element)

ans = 0
for i in range(N):
    if L[i] == 0:
        M = R[i+1]
    elif R[i+1] == 0:
        M = L[i]
    else:
        M = gcd(L[i], R[i+1])
    if ans < M:
        ans = M

print(int(ans))



N = int(input())

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

import fractions
import copy
from functools import reduce

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

max_gcd = 0
for idx in range(N):
    
    if idx == 0:
        cleaned = copy.copy(A_list)
        del cleaned[idx]
        gcd_value = gcd(tuple(cleaned))
        if max_gcd < gcd_value:
            max_gcd = gcd_value
    else:
        former_target = A_list[idx-1]
        if former_target % gcd_value == 0:
            cleaned = copy.copy(A_list)
            del cleaned[idx]
            gcd_value = gcd(tuple(cleaned))
            if max_gcd < gcd_value:
                max_gcd = gcd_value
        else:
            continue
        
print(max_gcd)



N = int(input())

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

import fractions
import copy
from functools import reduce

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

max_gcd = 0
for idx in range(N):
    
    if idx == 0:
        cleaned = copy.copy(A_list)
        del cleaned[idx]
        gcd_value = gcd(tuple(cleaned))
        if max_gcd < gcd_value:
            max_gcd = gcd_value
    else:
        former_target = A_list[idx-1]
        if former_target % max_gcd == 0:
            cleaned = copy.copy(A_list)
            del cleaned[idx]
            gcd_value = gcd(tuple(cleaned))
            if max_gcd < gcd_value:
                max_gcd = gcd_value
        else:
            continue
        
print(max_gcd)



import numpy as np

def gcd(a,b):
        if a < b:
            a, b = b, a
        if b == 0:
            return a
        c = a % b
        return gcd(b, c)
    
N = int(input())
A_list = list(map(int, input().split()))

# =====
# initialize L and R
# =====
L = np.zeros(N+1)
R = np.zeros(N+1)

for idx, element in enumerate(A_list):
    if idx == 0:
        continue
    else:
        L[idx] = gcd(L[idx-1], element)

for idx, element in enumerate(A_list[-1::-1]):
    idx = N-idx
    if idx == N:
        continue
    else:
        R[idx] = gcd(R[idx+1], element)

ans = 0
for i in range(N):
    M = gcd(L[i], R[i+1])
    if ans < M:
        ans = M

print(int(ans))



N = int(input())

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

import fractions
import copy
from functools import reduce

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

max_gcd = 0
for idx in range(N):
    cleaned = copy.copy(A_list)
    del cleaned[idx]
    gcd_value = gcd(tuple(cleaned))
    if max_gcd < gcd_value:
        max_gcd = gcd_value
print(max_gcd)



N = int(input())

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

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):
    remove_target = A_list.pop(0)
    if idx == 0:
        max_gcd = gcd(A_list)
        A_list.append(remove_target)
    else:
        newcomer = A_list[-1]
        if pair_gcd(A_list[0], newcomer) > max_gcd:
            gcd_value = gcd(A_list)
            A_list.append(remove_target)
            if max_gcd < gcd_value:
                max_gcd = gcd_value

        else:
            continue

print(max_gcd)



import numpy as np

def gcd(a,b):    
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
    
N = int(input())
A_list = list(map(int, input().split()))

# =====
# initialize L and R
# =====
L = np.zeros(N+1)
R = np.zeros(N+1)

for idx, element in enumerate(A_list):
    if L[idx] == 0:
        L[idx+1] = element
    else:
        L[idx+1] = gcd(L[idx], element)

for idx, element in enumerate(A_list[-1::-1]):
    idx = N-idx
    if R[idx] == 0:
        R[idx-1] = element
    else:
        R[idx-1] = gcd(R[idx], element)

ans = 0
for i in range(N):
    if L[i] == 0:
        M = R[i+1]
    elif R[i+1] == 0:
        M = L[i]
    else:
        M = gcd(L[i], R[i+1])
    if ans < M:
        ans = M

print(int(ans))



Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Time Limit Exceeded

Wrong Answer

Accepted