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):
from fractions import gcd
#from functools import reduce
a=int(input())
li=list(map(int,input().split()))
left_gcd=[]
left_gcd.append(li[0])
right_gcd=[]
right_gcd.append(li[a-1])

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

#     return reduce(math.gcd, numbers)
#print(right_gcd)
#print(left_gcd)
num_li=[]
num_li.append(right_gcd[a-2])
num_li.append(left_gcd[a-2])
#s=2
for i in range(a):
    ans=math.gcd(left_gcd[(a-3)-i],right_gcd[i])
    #print(left_gcd[(a-3-i)],right_gcd[i])
  
    #print(ans)
    num_li.append(ans)
    

print(max(num_li))


from fractions import gcd
#from functools import reduce
a=int(input())
li=list(map(int,input().split()))
left_gcd=[]
left_gcd.append(li[0])
right_gcd=[]
right_gcd.append(li[a-1])

for i in range(a-1):
    left_gcd.append(math.gcd(left_gcd[i],li[i+1]))
k=0
for i in range(a-1,0,-1):
    right_gcd.append(math.gcd(right_gcd[k],li[i-1]))
    k=k+1

#     return reduce(math.gcd, numbers)
#print(right_gcd)
#print(left_gcd)
num_li=[]
num_li.append(right_gcd[a-2])
num_li.append(left_gcd[a-2])
#s=2
for i in range(a):
    ans=math.gcd(left_gcd[(a-3)-i],right_gcd[i])
    #print(left_gcd[(a-3-i)],right_gcd[i])
  
    #print(ans)
    num_li.append(ans)
    

print(max(num_li))


 
#from functools import reduce
def gcd(m,n):
  x=max(m,n)
  y=min(m,n)
  while y!=0:
    x,y=y,x%y
  return x
 
a=int(input())
li=list(map(int,input().split()))
left_gcd=[0]
#left_gcd.append(li[0])
right_gcd=[0]
#right_gcd.append(li[a-1])

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

#     return reduce(math.gcd, numbers)
print(right_gcd)
print(left_gcd)
num_li=[]
#num_li.append(right_gcd[a-2])
#num_li.append(left_gcd[a-2])
#s=2
for i in range(a):
    ans=gcd(left_gcd[(a-1)-i],right_gcd[i])
    #print(left_gcd[(a-3-i)],right_gcd[i])
  
    #print(ans)
    num_li.append(ans)
    

print(max(num_li))


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


#     return x/gcd(x,y)*y
#ans=1

a=int(input())
li=list(map(int,input().split()))
#li_same=li
num=0
num_li=[]
for i in range(a):
    #li=li_same
    b=li.pop(i)
    k=len(li)
    for j in range(1,k):
        ans=gcd(li[j-1],li[j])
        print(ans)
    print('hoge')
    num_li.append(ans)
    li.insert(i,b)

print(int(max(num_li)))



 
#from functools import reduce
def gcd(m,n):
  x=max(m,n)
  y=min(m,n)
  while y!=0:
    x,y=y,x%y
  return x
 
a=int(input())
li=list(map(int,input().split()))
left_gcd=[0]
#left_gcd.append(li[0])
right_gcd=[0]
#right_gcd.append(li[a-1])

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

#     return reduce(math.gcd, numbers)
#print(right_gcd)
#print(left_gcd)
num_li=[]
#num_li.append(right_gcd[a-2])
#num_li.append(left_gcd[a-2])
#s=2
for i in range(a):
    ans=gcd(left_gcd[(a-1)-i],right_gcd[i])
    #print(left_gcd[(a-3-i)],right_gcd[i])
  
    #print(ans)
    num_li.append(ans)
    

print(max(num_li))


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Accepted