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 sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

kouho = []
n = ni()
li = na()
flag = 0
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    kouho.append(fractions.gcd(li[0], li[1]))
    kouho.append(fractions.gcd(li[1], li[2]))
    kouho.append(fractions.gcd(li[2], li[0]))
    for i in range(3,n):
        if len(kouho) == 0:
            print(i)
            break
        for num in kouho:
            if li[i] % num != 0:
                kouho.remove(num)
print(max(kouho))
    







import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

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

    
    return divisors

n = ni()
li = na()
li2 = []
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    a = fractions.gcd(li[0], li[1])
    b = fractions.gcd(li[1], li[2])
    c = fractions.gcd(li[2], li[0])
    li2.append(a)
    li2.append(b)
    li2.append(c)
    li2.extend(make_divisors(a))
    li2.extend(make_divisors(b))
    li2.extend(make_divisors(c))
    kouho = list(set(li2))
    for i in range(3,n):
        if len(kouho) == 0:
            break
        for num in kouho:
            if li[i] % num != 0:
                kouho.remove(num)
    if len(kouho) == 0:
        print(1)
    else:
        print(max(kouho))







import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

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

    
    return divisors

n = ni()
li = na()
li2 = []
kouho = []
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    a = fractions.gcd(li[0], li[1])
    b = fractions.gcd(li[1], li[2])
    c = fractions.gcd(li[2], li[0])
    li2.append(a)
    li2.append(b)
    li2.append(c)
    li2.extend(make_divisors(a))
    li2.extend(make_divisors(b))
    li2.extend(make_divisors(c))
    kouho = set(li2)
    for i in range(3,n):
        if len(kouho) == 0:
            break
        for num in kouho:
            if li[i] % num != 0:
                kouho.remove(num)
    if len(kouho) == 0:
        print(1)
    else:
        print(max(kouho))







import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

kouho = []
n = ni()
li = na()
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    kouho.append(fractions.gcd(li[0], li[1]))
    kouho.append(fractions.gcd(li[1], li[2]))
    kouho.append(fractions.gcd(li[2], li[0]))
    for i in range(3,n):
        if len(kouho) == 0:
            break
        for num in kouho:
            if li[i] % num != 0:
                kouho.remove(num)
    if len(kouho) == 0:
        print(1)
    else:
        print(max(kouho))







import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

kouho = []
n = ni()
li = na()
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    kouho.append(fractions.gcd(li[0], li[1]))
    if fractions.gcd(li[1], li[2]) not in kouho:
        kouho.append(fractions.gcd(li[1], li[2]))
    if fractions.gcd(li[2], li[0]) not in kouho:
        kouho.append(fractions.gcd(li[2], li[0]))
    for i in range(3,n):
        if len(kouho) == 0:
            break
        for num in kouho:
            if li[i] % num != 0:
                kouho.remove(num)
    if len(kouho) == 0:
        print(1)
    else:
        print(max(kouho))

import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

ans = []
n = ni()
li = na()
flag = 0
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    ans.append(fractions.gcd(li[0], li[1]))
    ans.append(fractions.gcd(li[1], li[2]))
    ans.append(fractions.gcd(li[2], li[0]))
    kouho = max(ans)
    for i in range(3,n):
        if li[i] % ans[2] == 0:
            continue
        else:
            ans.remove(max(ans))
            kouho = max(ans)
            flag = 1
            break
    if flag == 0:
        print(kouho)
    else:
        flag = 0
        for i in range(3,n):
            if li[i] % kouho == 0:
                continue
            else:
                ans.remove(max(ans))
                kouho = max(ans)
                flag = 1
                break
        if flag == 0:
            print(kouho)
        else:
            for i in range(3, n):
                if li[i] % kouho == 0:
                    continue
                else:
                    print(1)
                    break






import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

kouho = []
n = ni()
li = na()
flag = 0
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    kouho.append(fractions.gcd(li[0], li[1]))
    kouho.append(fractions.gcd(li[1], li[2]))
    kouho.append(fractions.gcd(li[2], li[0]))
    for i in range(3,n):
        if len(kouho) == 0:
            print(i)
            break
        for num in kouho:
            if li[i] % num != 0:
                kouho.remove(num)
    print(max(kouho))
    






import sys
import fractions

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

ans = []
n = ni()
li = na()
flag = 0
if len(li) == 2:
    print(max(li[0], li[1]))
else:
    ans.append(fractions.gcd(li[0], li[1]))
    ans.append(fractions.gcd(li[1], li[2]))
    ans.append(fractions.gcd(li[2], li[0]))
    kouho = max(ans)
    for i in range(3,n):
        if li[i] % kouho == 0:
            continue
        else:
            kouho = min(ans)
            flag = 1
            break
    if flag == 0:
        print(kouho)
    else:
        for i in range(3,n):
            if li[i] % kouho == 0:
                continue
            else:
                print(1)
                break






import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
#from heapq import heappush, heappop
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ni()
A = na()
b = [0] * N
c = [0] * N
b[0] = A[0]
c[-1] = A[-1]
for i in range(N-1):
    b[i+1] = math.gcd(b[i], A[i+1])
    c[-(i+2)] = math.gcd(c[-(i+1)], A[-(i+2)])

ans = 1
ans = max(c[1], ans)
ans = max(b[-2], ans)
for i in range(1, N-1):
    ans = max(math.gcd(b[i-1], c[i+1]), ans)
print(ans)


Verdicts: Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Accepted