TnT/Multi_CodeNet4Repair huggingface dataset:
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):
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if b == 0:
        return a
    return gcd(b, a % b)


def main():
    n = int(input())
    A = list(map(int, input().split()))
    gcdA = [0]*n
    gcdB = [0]*n
    gcdA[0] = A[0]
    gcdB[0] = A[n-1]
    for i in range(1, n):
        gcdA[i] = gcd(A[i], gcdA[i-1])
        gcdB[n-i-1] = gcd(A[n-i-1], gcdB[n-1])
    ans = max(gcdA[n-2], gcdB[1])
    for i in range(1, n-1):
        ans = max(ans, gcd(gcdA[i-1], gcdB[i+1]))
    print(ans)


if __name__ == "__main__":
    main()


import sys
input = sys.stdin.readline


def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if b == 0:
        return a
    return gcd(b, a % b)


def main():
    n = int(input())
    A = list(map(int, input().split()))
    gcdA = [0]*n
    gcdB = [0]*n
    gcdA[0] = A[0]
    gcdB[0] = A[n-1]
    for i in range(1, n):
        gcdA[i] = gcd(A[i], gcdA[i-1])
        gcdB[i] = gcd(A[n-i-1], gcdB[n-1])
    ans = max(gcdA[n-2], gcdB[1])
    for i in range(1, n):
        ans = max(ans, gcd(gcdA[i-1], gcdB[i+1]))
    print(ans)


if __name__ == "__main__":
    main()


import copy
import functools
import fractions

n=int(input())
lstA=list(map(int,input().split()))
maximum=max(lstA)
gcdlst=[]

for i in range(n):
    cplstA=copy.copy(lstA)
    del cplstA[i]
    gcdlst.append(functools.reduce(fractions.gcd, cplstA))

print(max(gcdlst))


#import sys
#input = sys.stdin.readline


def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if b == 0:
        return a
    return gcd(b, a % b)


def main():
    n = int(input())
    A = list(map(int, input().split()))
    gcdA = [0]*n
    gcdB = [0]*n
    gcdA[0] = A[0]
    gcdB[0] = A[n-1]
    for i in range(1, n):
        gcdA[i] = gcd(A[i], gcdA[i-1])
        gcdB[i] = gcd(A[n-i-1], gcdB[n-1])
    ans = max(gcdA[n-2], gcdB[1])
    for i in range(1, n):
        ans = max(ans, gcd(gcdA[i-1], gcdB[i+1]))
    print(ans)


if __name__ == "__main__":
    main()


#import sys
#input=sys.stdin.readline

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if b == 0:
        return a
    return gcd(b, a % b)


def main():
    n = int(input())
    A = list(map(int, input().split()))
    gcdA = [0]*n
    gcdB = [0]*n
    gcdA[0] = A[0]
    gcdB[n-1] = A[n-1]
    for i in range(1, n):
        gcdA[i] = gcd(A[i], gcdA[i-1])
        gcdB[n-i-1] = gcd(A[n-i-1], gcdB[n-i])
    ans = max(gcdA[n-2], gcdB[1])
    for i in range(1, n-1):
        ans = max(ans, gcd(gcdA[i-1], gcdB[i+1]))
    print(ans)


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Runtime Error

Time Limit Exceeded

Runtime Error

Accepted
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,math,copy
from fractions import gcd
input = sys.stdin.readline

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

#     if b==0:
#         return a
    


ANS=[]
L=[0]
R=[0]
for i in range(len(A)):
    L.append(gcd(A[i],L[i]))
    R=[gcd(A[-1-i],R[0])]+R

for i in range(len(L)-1):
    ANS.append(gcd(L[i],R[i+1]))

print(max(ANS))


import sys,math,copy
from fractions import gcd
input = sys.stdin.readline

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

#     if b==0:
#         return a
    


ANS=[]
L=[0]
R=[0]
for i in range(len(A)):
    L.append(gcd(A[i],L[i]))
    R=[gcd(A[-1-i],R[-i])]+R

for i in range(len(L)-1):
    ANS.append(gcd(L[i],R[i+1]))

print(max(ANS))


import sys,math,copy
input = sys.stdin.readline

N=int(input().strip())
A=[int(x) for x in input().strip().split()]
def gcd(a,b):
    if b==0:
        return a
    
    return gcd(b,a%b)

ANS=[]
L=[0]
R=[0]
for i in range(len(A)):
    L.append(gcd(A[i],L[-1]))
    R.append(gcd(A[-1-i],R[-1]))

R.reverse()
for i in range(len(L)-1):
    ANS.append(gcd(L[i],R[i+1]))

print(max(ANS))


Verdicts: Time Limit Exceeded

Wrong Answer

Accepted
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):
N = int(input())
A = list(map(int, input().split()))

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

tmp = A[0]
for i in range(N):
    tmp = gcd(tmp, A[i])
    
    
for i in range(N):
    A[i] //= tmp
    
v1 = A[0]
for i in range(N):
    if i != 0:
        v1 = gcd(v1, A[i])
        
v2 = A[1]
for i in range(N):
    if i != 1:
        v2 = gcd(v2, A[i])
   

print(tmp * max(v1, v2))

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

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


tmp_gcd = A[0]
for i in range(1, N):
    tmp_gcd = gcd(tmp_gcd, A[i])
    
A.sort()

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

flag = False
gcd_0 = A[-1]
for i in range(1, N):
    tmp = gcd_0
    gcd_0 = gcd(gcd_0, A[i])
    
    if gcd_0 == 1:
        if flag:
            break
        else:
            flag = True
            gcd_0 = tmp
            
    
flag = False
gcd_1 = A[-2]
for i in range(N):
    tmp = gcd_1
    gcd_1 = gcd(gcd_1, A[i])
    
    if gcd_1 == 1:
        if flag:
            break
        else:
            flag = True
            gcd_1 = tmp
          
print(tmp_gcd * max(gcd_0, gcd_1))
    

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

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

tmp = A[0]
for i in range(N):
    tmp = gcd(tmp, A[i])
    
    
for i in range(N):
    A[i] //= tmp
 
A.sort(reverse=True)

v1 = A[0]
count1 = 0
for i in range(N):
    tmp1 = v1
    v1 = gcd(v1, A[i])
    if  v1 == 1:
        count1 += 1
        if count1 == 1:
            v1 = tmp1
        
        
v2 = A[1]
count2 = 0
for i in range(N):
    tmp2 = v2
    v2 = gcd(v2, A[i])
    if v2 == 1:
        count2 += 1
        if count2 == 1: 
            v2 = tmp2

if 1:
    s1 = 1
    s2 = 1
    if count1 == 1 and v1 <= 10 ** 9:
        s1 = v1
    if count2 == 1 and v2 <= 10 ** 9:
        s2 = v2
    print(tmp * max(s1, s2))

Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
N = int(input())
A = [int(i) for i in input().split()]

if len(A) > 1:
    result = sorted(A)[1]
else:
    result = min(A)

while True:
    counter = 0
    should_continue = False
    for e in A:
        if e % result != 0:
            counter += 1
            if counter > 1:
                should_continue = True
                break
    if should_continue:
        continue
    if counter <= 1:  
        break
    else:
        result -= 1

print(result)


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

if len(A) > 1:
    result = sorted(A)[1]
else:
    result = min(A)

while True:
    counter = 0
    should_continue = False
    for e in A:
        if e % result != 0:
            counter += 1
            if counter > 1:
                should_continue = True
                break
    if should_continue:
        result -= 1
        continue
    if counter <= 1:  
        break
    else:
        result -= 1

print(result)


Verdicts: Time Limit Exceeded

Accepted
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 sys import stdin

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

n = int(stdin.readline().rstrip())
an = list(map(int, input().split()))

left = []
right = []

for i in range(n):
  if(i==0):
    before = an[i]
  else:
    before = gcd(before, an[i])
  left.append(before)

for i in range(n):
  if(i==0):
    before = an[n-1-i]
  else:
    before = gcd(before, an[n-1-i])
  right.append(before)

max = 0
for i in range(n):
  if(i==0):
    before = right[n-2];
  elif(i==(n-1)):
    before = left[n-2];
  else:
    before = gcd(left[i-1],right[n-2-i])
  max = max(before,max)

print(max)

from sys import stdin

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

n = int(stdin.readline().rstrip())
an = list(map(int, input().split()))

left = []
right = []

for i in range(n):
  if(i==0):
    before = an[i]
  else:
    before = gcd(before, an[i])
  left.append(before)

for i in range(n):
  if(i==0):
    before = an[n-1-i]
  else:
    before = gcd(before, an[n-1-i])
  right.append(before)

max = 0
for i in range(n):
  if(i==0):
    before = right[n-2];
  elif(i==(n-1)):
    before = left[n-2];
  else:
    before = gcd(left[i-1],right[n-2-i])
  if(max < before ):
    max = before

print(max)

Verdicts: Runtime Error

Accepted
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 fractions

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

def gcd(l):
    ans = l[0]
    for i in range(1, N-1):
        ans = fractions.gcd(ans, l[i])
    return ans

max_res = -1
for i in range(N):
    A_removed = A[0:i] + A[i+1:N]
    res = gcd(A_removed)
    if (res>max_res):
        max_res = res

print(max_res)


import fractions
import numpy as np

N = int(input())
A = np.array(sorted([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)

    return divisors

divisors=make_divisors(A[0])
divisors_1=make_divisors(A[1]) 
divisors.extend(divisors_1)

def gcd(l):
    ans = l[0]
    for j in range(1, N-1):
        ans = fractions.gcd(ans, l[j])
    return ans

#res = 1
for i in sorted(list(set(divisors))):
#    print("{} / {}".format(i, A%i))
#    print(np.where(A%i != 0))
#    print((A%i != 0))
    if(np.sum(A%i != 0)<=1):
        #print(i)
        res = i


print(res)




Verdicts: Time Limit Exceeded

Accepted
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 math
from functools import reduce
import copy
import fractions
N = int(input())
A = list(map(int,input().split()))

def gcd_list(numbers):
    return reduce(fractions.gcd,numbers)
ans = 0
count = 0
for i in range(N):
    B = copy.copy(A)
    a = B.pop(i)
    gcd_a = gcd_list(B)
    ans = max(ans,gcd_a)

print(ans)

import fractions
N=int(input())
A=list(map(int,input().split()))
A.append(A[0])
ans=0
for i in range(N):
    val=fractions.gcd(A[i],A[i+1])
    ans=max(ans,val)
print(ans)

import fractions
N=int(input())
A=list(map(int,input().split()))
A.append(A[0])
ans=0
l=[]
if N==2:
    print(max(A))
    exit()
for i in range(N):
    val=fractions.gcd(A[i],A[i+1])
    l.append(val)
l.sort()
print(l)

lst=[]
for i in range(len(l)):
    if l[i]==l[0]:
        continue
    lst.append(l[i])

x=dict()
for i in range(len(lst)):
    val=lst[i]
    if val in x:
        x[val]+=1
    else:
        x[val]=1

cnt=0
for idx in x:
    cnt+=1
if cnt==0:
    print(l[0])
    exit()
if cnt==1:
    print(lst[0])
else:
    print(l[0])
    exit()


import fractions
N=int(input())
A=list(map(int,input().split()))
A.append(A[0])
ans=0
l=[]
if N==2:
    print(max(A))
    exit()
for i in range(N):
    val=fractions.gcd(A[i],A[i+1])
    l.append(val)
l.sort()
print(l[2])

import fractions
N=int(input())
A=list(map(int,input().split()))
A.append(A[0])
ans=0
l=[]
if N==2:
    print(max(A))
    exit()
for i in range(N):
    val=fractions.gcd(A[i],A[i+1])
    l.append(val)

print(l[2])

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

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

L=[0 for _ in range(N+1)]
L[0]=0
for i in range(N):
    L[i+1]=gcd(L[i],A[i])

R=[0 for i in range(N+1)]
R[N-1]=A[N-1]
for i in range(1,N)[::-1]:
    R[i-1]=gcd(R[i],A[i-1])

ans=0
for i in range(N):
    ans=max(ans,gcd(L[i],R[i+1]))
print(ans)

Verdicts: Time Limit Exceeded

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
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):
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


N = int(input())
A = list(map(int, input().split()))
L = [0 for i in range(N)]
R = [0 for i in range(N)]
T = [0 for i in range(N)]

for i in range(N):
    if i == 0:
        L[i] = 0
    else:
        L[i] = gcd(L[i-1], A[i-1])
for i in range(N-1, 0, -1):
    if i == N-1:
        R[i] = 0
    else:
        R[i] = gcd(R[i+1], A[i+1])
for i in range(N):
    T[i] = gcd(L[i], R[i])

print(max(T))

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


N = int(input())
A = list(map(int, input().split()))
L = [0 for i in range(N)]
R = [0 for i in range(N)]
T = [0 for i in range(N)]

for i in range(N):
    if i == 0:
        L[i] = 0
    else:
        L[i] = gcd(L[i-1], A[i-1])
for i in range(N-1, 0, -1):
    if i == N-1:
        R[i] = 0
    else:
        R[i] = gcd(R[i+1], A[i+1])
for i in range(N):
    T[i] = gcd(L[i], R[i])

print(T)

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


N = int(input())
A = list(map(int, input().split()))
L = [0 for i in range(N)]
R = [0 for i in range(N)]
T = [0 for i in range(N)]

for i in range(N):
    if i == 0:
        L[i] = 0
    else:
        L[i] = gcd(L[i-1], A[i-1])
for i in range(N-1, -1, -1):
    if i == N-1:
        R[i] = 0
    else:
        R[i] = gcd(R[i+1], A[i+1])
for i in range(N):
    T[i] = gcd(L[i], R[i])

print(max(T))

Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
def gcd(x,y):
    if x<y:
        x,y=y,x
    while x%y!=0:
        x,y=y,x%y
    return(y)

n=int(input())

v=[]
line=input().split()

for i in range(n):
    v.append(int(line[i]))

gcd_l=[]
gcd_r=[]

for i in range(n):
    if i==0:
        gcd_l.append(v[i])
    else:
        gcd_l.append(gcd(gcd_l[i-1],v[i]))

for i in range(n):
    if i==0:
        gcd_r.append(v[n-1])
    else:
        gcd_r.append(gcd(gcd_r[i-1],v[n-i-1]))

print(gcd_l,gcd_r)

gcd_list=[]

for i in range(n):
    if i==0:
        gcd_list.append(gcd_r[n-2])
    elif i==n-1:
        gcd_list.append(gcd_l[n-2])
    else:
        gcd_list.append(gcd(gcd_l[i-1],gcd_r[i-1]))

print(max(gcd_list))

def gcd(x,y):
    if x<y:
        x,y=y,x
    while x%y!=0:
        x,y=y,x%y
    return(y)

n=int(input())

v=[]
line=input().split()

for i in range(n):
    v.append(int(line[i]))

gcd_l=[]
gcd_r=[]

for i in range(n-1):
    if i==0:
        gcd_l.append(v[i])
    else:
        gcd_l.append(gcd(gcd_l[i-1],v[i]))

for i in range(n-1):
    if i==0:
        gcd_r.append(v[n-1])
    else:
        gcd_r.append(gcd(gcd_r[i-1],v[n-i-1]))

gcd_list=[]

for i in range(n):
    if i==0:
        gcd_list.append(gcd_r[n-2])
    elif i==n-1:
        gcd_list.append(gcd_l[n-2])
    else:
#        print(gcd(gcd_l[i-1],gcd_r[n-i-2]))
        gcd_list.append(gcd(gcd_l[i-1],gcd_r[n-i-2]))

#print(gcd_list)

print(max(gcd_list))


Verdicts: Wrong Answer

Accepted
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):
N = int(input()) 
def gcd(m, n):
  a = max(m,n)
  b = min(m,n)
  if a%b==0:
    return b
  while not a % b == 0:
      a, b = b, a % b
  return b

arr = [int(item) for item in input().split()]
a = [arr[0]]
b = [arr[-1]]
for i in range(1, N):
  a.append(gcd(a[i-1], arr[i]))
  b.append(gcd(b[i-1], arr[N-i-1]))
ans = max(a[-2], b[-2])
print(a, b)
for i, j in zip(a[:-2], b[:-2:]):
  ans = max(ans, gcd(i,j))
print(ans)


N = int(input()) 
def gcd(m, n):
  a = max(m,n)
  b = min(m,n)
  if a%b==0:
    return b
  while not a % b == 0:
      a, b = b, a % b
  return b

arr = [int(item) for item in input().split()]
a = [arr[0]]
b = [arr[-1]]
for i in range(1, N):
  a.append(gcd(a[i-1], arr[i]))
  b.append(gcd(b[i-1], arr[N-i-1]))
ans = max(a[-2], b[-2])
b = b[::-1]
for i, j in zip(a[:-2], b[2:]):
  ans = max(ans, gcd(i,j))
print(ans)


Verdicts: Wrong Answer

Accepted
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 functools
import fractions
n = int(input())
values = list(map(int, input().split()))
m = 1

for i in range(n):
    a = values[:]
    a.pop(i)
    gcd = functools.reduce(fractions.gcd, a)
    if m < gcd:
        m = gcd


print(m)


n = int(input())
v = list(map(int, input().split()))
m = 1
gf = []
gp = []


def gcd(x, y):
    if x < y:
        x += y
        y = x - y
        x -= y

    while y > 0:
        r = x % y
        x = y
        y = r

    return x


gf.append(v[0])
for i in range(n-1):
    gf.append(gcd(gf[i], v[i+1]))

gp.append(v[n-1])
for i in range(n-1):
    gp.append(gcd(gp[i], v[n-2-i]))

m = gp[n-2]

for i in range(n-1):
    b = gcd(gf[i], gp[n-3-i])
    if m < b:
        m = b
if m < gf[n-2]:
    m = gf[n-2]

print(m)


Verdicts: Time Limit Exceeded

Accepted
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):
N = int(input())
A = list(map(int, input().split()))


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


def m():
    left, right = A.copy(), A.copy()
    for i in range(1, N):
        left[i] = gcd(A[i], left[i-1])

    for i in reversed(range(0, N-1)):
        right[i] = gcd(A[i], right[i+1])

    res = max(left[N-1], right[0])
    for i in range(2, N-2):
        res = max(gcd(left[i-1],right[i+1]), res)
    return res


print(m())


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


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


def m():
    left, right = A.copy(), A.copy()
    for i in range(1, N):
        left[i] = gcd(A[i], left[i-1])

    for i in reversed(range(0, N-1)):
        right[i] = gcd(A[i], right[i+1])

    res = max(left[N-2], right[1])
    for i in range(1, N-1):
        res = max(gcd(left[i-1],right[i+1]), res)
    return res


print(m())


Verdicts: Wrong Answer

Accepted
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 math
n=int(input())
l = list(map(int, input().split()))
ans=1;
for i in range(n):
	ans=max(math.gcd(math.gcd(l[0],l[i-1]),math.gcd(l[i],l[n-1])),ans)
print(ans)

def gcd(a,b):
	while b:
		a,b=b,a%b
	return a
n=int(input())
l = list(map(int, input().split()))
ans=1;
m=[0]*(n+1)
o=[0]*(n+1)
for i in range(n):
	m[i+1]=gcd(m[i],l[i])
	o[i+1]=gcd(o[i],l[n-i-1])
for i in range(n):
	ans=max(gcd(m[i],o[n-i-1]),ans)
print(ans)

Verdicts: Runtime Error

Accepted
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 math
from functools import reduce 
from fractions import gcd
n = int(input())
*v, = map(int,input().split())
#print(v)

mn = 0
for i in range(n):
  c = v.copy()
  #print('c',c)
  c.pop(i)
  #print('c2',c)
  ans = reduce(gcd,c)
  #print('v',v)
  #print('ans',ans)
  if ans > mn:
    mn = ans
    
print(mn)

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

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

l, r = [], []

for i in range(n):
  l.append(gcd(l[i-1], a[i-1]) if i else 0)
  r.append(gcd(r[i-1], a[n-i]) if i else 0)
print(max([gcd(l[i], r[n-i-1]) for i in range(n)]))


Verdicts: Time Limit Exceeded

Accepted
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 math
from functools import reduce
import fractions
import numpy as np
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())
A = list(map(int, input().split()))
ans=0
for i in range(N):
    a = A[0]
    del A[0]
    
    b = gcd_list(A)
    if ans < b:
        ans = b
    A.append(a)

print(ans)
        

import math
from functools import reduce
from fractions import Fraction
import numpy as np
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = int(input())
A = list(map(int, input().split()))
ans=0
for i in range(N):
    a = A[0]
    del A[0]
    
    b = gcd_list(A)
    if ans < b:
        ans = b
    A.append(a)

print(ans)
        

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

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

left_gcd = [A[0]]
a = A[0]
for i in range(1,N-1):
  a = gcd(a, A[i])
  left_gcd.append(a)

right_gcd = [A[N-1]]
b = A[N-1]
for k in range(N-2, 0, -1):
  b = gcd(b, A[k])
  right_gcd.append(b)

ans_gcd = [right_gcd[N-2], left_gcd[N-2]]

for p in range(N-2):
  ans_gcd.append(gcd(left_gcd[p], right_gcd[N-p-3]))

print(max(ans_gcd))

Verdicts: Time Limit Exceeded

Runtime Error

Accepted
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):
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)

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

for i in range(1, n-1):
    a=gcd(a,a_array[i])
    left_gcd.append(a)

right_gcd=[a_array[-1]]
for i in range(n-2,0,-1):
    b=gcd(b,a_array[i])
    right_gcd.append(b)

ans_gcd=[right_gcd[n-2],left_gcd[n-2]]

for i in range(n-2):
    ans_gcd.append(gcd(left_gcd[i],right_gcd[n-i-3]))

print(max(ans_gcd))


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

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

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

right_gcd=[a_array[-1]]
b=a_array[-1]
for i in range(n-2,0,-1):
    b=gcd(b,a_array[i])
    right_gcd.append(b)

ans_gcd=[right_gcd[n-2],left_gcd[n-2]]

for i in range(n-2):
    ans_gcd.append(gcd(left_gcd[i],right_gcd[n-i-3]))



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

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


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


right_gcd=[a_array[-1]]
b=a_array[-1] 
for i in range(n-2,0,-1):
    b=gcd(b,a_array[i])
    right_gcd.append(b)


ans_gcd=[right_gcd[n-2],left_gcd[n-2]]

for i in range(n-2):
    ans_gcd.append(gcd(left_gcd[i],right_gcd[n-i-3]))

print(max(ans_gcd))


Verdicts: Runtime Error

Wrong Answer

Accepted
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):

# coding: utf-8

# In[1]:

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


# In[2]:

import copy
#import numpy as np


# In[3]:

def get_divisor_list(A):
    divisor_list = [1]
    if A == 1:
        return divisor_list
    else:
        for i in range(2, A//2+1):
            if A%i == 0:
                divisor_list.append(i)
        divisor_list.append(A)
        return divisor_list


# In[4]:

all_db = []
for i in range(N):
    all_db.append(set(get_divisor_list(A[i])))
#print(all_db)


# In[5]:

gcd_list = []
for i in range(N):
    all_dbc = copy.copy(all_db)
    all_dbc.pop(i)
    gcds = {all_db}.intersection(*all_dbc)
    gcd_list.append(max(gcds))
print(max(gcd_list))


# In[7]:

set().intersection({1, 2, 3})


# In[ ]:

"""
try:
    from math import gcd as ogcd
except:
    from fractions import gcd as ogcd
from functools import reduce

def gcd(*numbers):
    return reduce(ogcd, numbers)
"""


# In[4]:




# In[5]:

#print(np.max(np.array(gcd_list)))


# In[ ]:






# coding: utf-8

# In[1]:

import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))


# In[2]:

#import copy
#import numpy as np
try:
    from fractions import gcd
except:
    from math import gcd


# In[ ]:






# In[3]:

lg = [1]*(N)
rg = [1]*(N)
ans = 0


# In[4]:

#print(lg)
#print(rg)
#print(A)


# In[ ]:

lg[0] = A[1]
rg[0] = A[N-2]
lg[1] = A[0]
rg[1] = A[N-1]
#print(lg, rg)
for i in range(1, N-1):
    #print(i)
    lg[i+1] = gcd(lg[i], A[i])
    #print(lg[i], A[i])
    rg[i+1] = gcd(rg[i], A[N-1-i])
    #print(rg[N-1-i], A[N-1-i])
#print(lg, rg)


ans = [gcd(lg[i], rg[N-1-i]) for i in range(N)]

    #print(i, lg[i], rg[N-i-1])
    
print(max(ans))


# In[6]:

#print(ans)



Verdicts: Runtime Error

Accepted
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

def gcd(a,b,mem):
    str12 = "{}.{}".format(a, b)
    if b==0:
        return a
    elif str12 in mem.keys():
        return mem[str12]
    else:
        mem[str12] = gcd(b,a%b,mem)
        return  mem[str12]




N = int(input())
A = numpy.array([int(x) for x in input().split()])
a2 = list(A)
max = 0
mem = {}
for i,_ in enumerate(A):
    A.pop(i)
    res = A[0]
    for i in A[1:]:
        res = gcd(i,res,mem)
    max = res if res >= max else max
    A = list(a2)


print(max)

import fractions
import  functools

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

N = int(input())
A = [int(x) for x in input().split()]
a2 = A.copy()
max = 0
for i,_ in enumerate(A):
    A.pop(i)
    temp = gcd(A)
    max = temp if temp >= max else max
    A = a2.copy()


print(max)

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


gcdL = []
gcdR = []

N = int(input())
A = [int(x) for x in input().split()]
gcdL.append(0)
length_A = len(A)
for i in range(1,length_A):
    gcdL.append(gcd(A[i-1],gcdL[i-1]))


gcdR.append(0)
for i in range(1,length_A):
    gcdR.append(gcd(A[length_A-i],gcdR[i-1]))



list_gcd = []
for i in range(length_A):
        list_gcd.append(gcd(gcdL[i],gcdR[length_A-i-1]))

print(max(list_gcd))

Verdicts: Runtime Error

Wrong Answer

Accepted
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 copy
n = int(input())
a = list(map(int,input().split()))
ans = 1
for i in range(n):
  b = copy.deepcopy(a)
  b.pop(i)
  for j in range(max(b)+1,2):
    c = list(map(lambda x: x % j,b))
    if sum(c) == 0:
      ans = j
      break
print(ans)

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)


n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 1
if n == 2:
  print(max(a))
else:
  a0 = a[0]
  a1 = a[1]
  r = 0
  while True:
    r = a1 % a0
    if r == 0:
      b0 = a0
      break
    elif r > a0:
      a1, a0 = r, a0
    else:
      a1, a0 = a0, r
  a1 = a[1]
  a2 = a[2]
  r = 0
  while True:
    r = a2 % a1
    if r == 0:
      b1 = a1
      break
    elif r > a1:
      a2, a1 = r, a1
    else:
      a2, a1 = a1, r
  a0 = a[0]
  a2 = a[2]
  r = 0
  while True:
    r = a2 % a0
    if r == 0:
      b2 = a0
      break
    elif r > a0:
      a2, a0 = r, a0
    else:
      a2, a0 = a0, r
  max_a = max(b0,b1,b2)
  for j in range(max_a,1,-1):
    if max_a % j == 0:
      c = list(map(lambda x: x % j,a))
      c_ng = [i for i in c if i > 0]
    #print("j=",j,"c=",c,"c_ng=",c_ng)
      if len(c_ng) <= 1:
        ans = j
        break
  print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
#!/usr/bin/env python3

import fractions
import functools
import math


def number_of_divisors(x):
    res = 0
    for i in range(1, math.floor(math.sqrt(x)) + 1):
        d, m = divmod(x, i)
        if m == 0:
            res += 1 + int(d != i)
    return res


def gcds(xs):
    return functools.reduce(fractions.gcd, xs)


def solve(xs):
    m = min(xs, key=number_of_divisors)
    ys = xs[:]
    for i in range(len(ys)):
        if ys[i] == m:
            ys[i] = 0
            break
    return gcds(ys)


def main():
    _ = int(input())
    xs = [int(x) for x in input().split()]
    print(solve(xs))


if __name__ == "__main__":
    main()

#!/usr/bin/env python3

import itertools
try:
    from math import gcd
except ImportError:
    from fractions import gcd


class Cumulative(object):

    def __init__(self, seq, op):
        self.cumul_array = [0]
        self.cumul_array.extend(itertools.accumulate(seq, op))


def solve(n, xs):
    left_cumul = Cumulative(xs, gcd)
    right_cumul = Cumulative(reversed(xs), gcd)
    res = 1
    for i in range(n):
        left_gcd = left_cumul.cumul_array[i]
        right_gcd = right_cumul.cumul_array[n - i - 1]
        cand = gcd(left_gcd, right_gcd)
        if cand > res:
            res = cand
    return res


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    res = solve(n, xs)
    print(res)


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
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
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
pref,suf = [0]*(n+2),[0]*(n+2)
pref[1] = a[0]
for i in range(2,n+1):
    pref[i] = gcd(pref[i-1],a[i-1])
suf[n] = a[n-1]
for i in range(n-1,0,-1):
    suf[i] = gcd(suf[i+1],a[i-1])
ans = max(suf[2],pref[n-1])
for i in range(2,n):
    ans = max(ans,gcd(pref[i-1],suf[i+1]))
print(ans)

import sys
# from math import gcd
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
pref,suf = [0]*(n+2),[0]*(n+2)
pref[1] = a[0]
for i in range(2,n+1):
    pref[i] = gcd(pref[i-1],a[i-1])
suf[n] = a[n-1]
for i in range(n-1,0,-1):
    suf[i] = gcd(suf[i+1],a[i-1])
ans = max(suf[2],pref[n-1])
for i in range(2,n):
    ans = max(ans,gcd(pref[i-1],suf[i+1]))
print(ans)


Verdicts: Runtime Error

Accepted
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):
N = int(input())
A = list(map(int, input().split()))

def gcd(a, b):
  if b > a:
    a, b = b, a  
  red = a % b
  if red == 0:
    return b
  else:
    return gcd(red, b)

L = [A[0]]
for i in range(1, N):
  L.append(gcd(A[i], L[-1]))
  
R = [A[-1], A[-1]]
for i in range(N-2, -1, -1):
  R.append(gcd(A[i], R[-1]))
R = list(reversed(R))
#print(L)
#print(R)

result = 0
for i in range(N-1):
  #print(L[i], R[i+2], i, i+2)
  g = gcd(L[i], R[i+2])
  result = max([g, result])
  
print(result)

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

def gcd(a, b):
  if b > a:
    a, b = b, a  
  red = a % b
  if red == 0:
    return b
  else:
    return gcd(red, b)

L = [A[0]]
for i in range(0, N):
  L.append(gcd(A[i], L[-1]))
  
R = [A[-1]]
for i in range(N-1, -1, -1):
  R.append(gcd(A[i], R[-1]))
R = list(reversed(R))
print(L)
print(R)

result = 0
for i in range(N-1):
  #print(L[i], R[i+2], i, i+2)
  g = gcd(L[i], R[i+2])
  print(g)
  result = max([g, result])
  
print(result)

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

def gcd(a, b):
  if b > a:
    a, b = b, a
  if b == 0:
    return a
  red = a % b
  if red == 0:
    return b
  else:
    return gcd(red, b)

L = [0]
for i in range(0, N):
  L.append(gcd(A[i], L[-1]))
  
R = [0]
for i in range(N-1, -1, -1):
  R.append(gcd(A[i], R[-1]))
R = list(reversed(R))
#print(L)
#print(R)

result = 0
for i in range(N):
  #print(L[i], R[i+2], i, i+2)
  g = gcd(L[i], R[i+1])
  #print(g)
  result = max([g, result])
  
print(result)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
n=int(input())
l=list(map(int,input().split()))
import functools
import fractions
l1=[]
for i in range(n):
  a=l[0]
  del l[0]
  s = functools.reduce(fractions.gcd, l)
  l1.append(s)
  l.append(a)
print(max(l1))

n=int(input())
l=list(map(int,input().split()))
def gcd(n,m):
  l0=[]
  if n==0:
    return m
  elif m==0;
  return n
  else:
    for i in range(1,n//2):
      if n%i==0:
        l0.append(i)
    l0.append(n)
    g=1
    for i in l0:
      if m%i==0:
        g=i
    return(g)
l1=[]
for i in range(n):
  ll1=gcd(0,l[0])
  ll2=gcd(0,l[n-1])
  if i==0:
    ll1=gcd(0,l[1])
    for j in range(1,n-1):
      ll1=gcd(ll1,l[j])
    l1.append(ll1)
  elif i==n-1:
    ll2=gcd(0,l[0])
    for j in range(n-1):
      ll2=gcd(ll2,l[j])
    l1.append(ll2)
  else:
      for j in range(i):
        ll1=gcd(ll1,l[j])
      for j in range(n-1,i:-1):
        ll2=gcd(ll2,l[j])
      l1.append(gcd(ll2,ll1))
print(max(l1))


def gcd(n,m):
  a=max(n,m)
  b=min(n,m)
  while b!=0:
    a,b=b,a%b
  return a
n=int(input())
l=list(map(int,input().split()))
l1=[]
l1.append(l[0])
for i in range(1,n):
  l1.append(gcd(l1[-1],l[i]))
l2=[]
l2.append(l[-1])
for i in range(n-2,-1,-1):
  l2.append(gcd(l2[-1],l[i]))
l3=[]
for i in range(2,n):
  l3.append(gcd(l1[i-2],l2[n-i-1]))
l3.append(l2[n-2])
l3.append(l1[n-2])
print(max(l3))
            
                



Verdicts: Time Limit Exceeded

Runtime Error

Accepted
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 fractions

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

left_gcds = [fractions.gcd(As[0], As[0])]
for i in range(1, len(As)):
    left_gcds.append(fractions.gcd(left_gcds[i-1], As[i]))

right_gcds = [fractions.gcd(As[-1], As[-1])]
for i in reversed(range(len(As)-1)):
    right_gcds.append(fractions.gcd(right_gcds[i-1], As[i]))
right_gcds.reverse()

gcds = []
for i in range(N):
    if i == 0:
        gcds.append(right_gcds[1])
    elif i == N-1:
        gcds.append(left_gcds[-2])
    else:
        gcds.append(fractions.gcd(left_gcds[i-1], right_gcds[i+1]))
print(max(gcds))

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

def calcKou(num):
    result = []
    for i in range(1, num+1):
        if num % i == 0:
            result.append(i)
    return result

kous = list(map(calcKou, As))
all = []
for v in kous:
    all += v
all = list(set(all))
all = list(reversed(all))

counts = []
for v in all:
    count = 0
    for a in As:
        if v in calcKou(a):
            count += 1
    counts.append(count)

print(all)    
print(counts)

ans = 1
for i in range(len(counts)):
    if counts[i]>=N-1:
        ans = all[i]
        break
print(ans)

import sys
if sys.version_info.minor >= 5:
    from math import gcd
else:
    from fractions import gcd



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

left_gcds = [gcd(As[0], As[0])]
for i in range(1, len(As)):
    left_gcds.append(gcd(left_gcds[i-1], As[i]))

right_gcds = [gcd(As[-1], As[-1])]
for i in range(1, len(As)):
    right_gcds.append(gcd(right_gcds[i-1], As[-(i+1)]))
right_gcds.reverse()

gcds = []
for i in range(N):
    if i == 0:
        gcds.append(right_gcds[1])
    elif i == N-1:
        gcds.append(left_gcds[-2])
    else:
        gcds.append(gcd(left_gcds[i-1], right_gcds[i+1]))
print(max(gcds))

Verdicts: Runtime Error

Wrong Answer

Accepted
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 fractions
import copy
from functools import reduce
num = int(input())
nums = [int(s) for s in input().split()]

def gcd_list(numbers):
    return reduce(fractions.gcd, nums)
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
answer = []
for i in range(num):
  ls = copy.deepcopy(nums)
  del ls[i]
  answer.append(gcd(*ls))
print(max(answer))

def gcd(a,b):
  if not a or not b:
    return 0
  else:
    while b:
      a,b = b,a%b
    return a

num = int(input())
nums = [int(s) for s in input().split()]

l = nums[0]
r = nums[-1]
left = []
right = []
for i in range(num-1):
  l,r = gcd(l,nums[i]), gcd(r,nums[-i-1])
  left.append(l)
  right.append(r)
answer = [left[-1],right[-1]]
for i in range(len(left)-1):
  answer.append(gcd(left[i],right[-i-2]))
print(max(answer))

Verdicts: Time Limit Exceeded

Accepted
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 fractions
N = int(input())
A = list(map(int, input().split()))
L = [0]
R = [0]
for i in range(N-1):
    L.append(gcd(L[i], A[i]))
    R.append(gcd(R[i], A[-i-1]))
MAX = 0
for i in range(N):
    MAX = max(MAX, gcd(L[i], R[-i-1]))
print(MAX)




import fractions
L = [0]
R = [0]
for i in range(N-1):
    L.append(gcd(L[i], A[i]))
    R.append(gcd(R[i], A[-i-1]))
MAX = 0
for i in range(N):
    MAX = max(MAX, gcd(L[i], R[-i-1]))
print(MAX)



import functools
import math
import fractions
N = int(input())
A = list(map(int, input().split()))
gcd_max = 1
for i in range(N):
    gcd = functools.reduce(fractions.gcd, A[i+1:] + A[:i])
    if gcd > gcd_max:
        gcd_max = gcd

print(gcd_max)



import numpy as np

def gcd(v1, v2):
    if v1 == 0 or v2 == 0:
        return max(v1, v2)
#     print(v1, v2, v1%v2)
    if v1 % v2 == 0:
        return v2
    return gcd(v2, v1%v2)

N = int(input())

A = list(map(int, input().split()))
L = np.zeros(N+1)
R = np.zeros(N+1)
for i in range(N):
    L[i+1] = gcd(L[i], A[i])
#     print(N-i-1, N-i, N-i-1)
    R[N-i-1] = gcd(R[N-i], A[N-i-1])
M = []
print(L)
print(R)
for j in range(N):
    M.append(gcd(L[j], R[j+1]))

print(int(max(M)))

import numpy as np

def gcd(v1, v2):
    if v1 == 0 or v2 == 0:
        return max(v1, v2)
#     print(v1, v2, v1%v2)
    if v1 % v2 == 0:
        return v2
    return gcd(v2, v1%v2)

N = int(input())

A = list(map(int, input().split()))
L = np.zeros(N+1)
R = np.zeros(N+1)
for i in range(N):
    L[i+1] = gcd(L[i], A[i])
#     print(N-i-1, N-i, N-i-1)
    R[N-i-1] = gcd(R[N-i], A[N-i-1])
M = []
for j in range(N):
    M.append(gcd(L[j], R[j+1]))

print(int(max(M)))

Verdicts: Runtime Error

Runtime Error

Time Limit Exceeded

Wrong Answer

Accepted
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 functools import reduce
from fractions import gcd


def gcd_check(data, ans):
    for i in range(len(data) - 1):
        ans.append(reduce(gcd, [data[i], data[i + 1]]))
 
N = int(input())
data = list(map(int, input().split()))
ans_data = []
gcd_check(data, ans_data)

print(max(ans_data))


from functools import reduce
from fractions import gcd
import itertools

def gcd_check(data, ans):
    p = list(itertools.permutations(data, 2))
    for i in range(len(p)):
        ans.append(reduce(gcd, p[i]))
 
N = int(input())
data = list(map(int, input().split()))
ans_data = []
gcd_check(data, ans_data)

print(max(ans_data))


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

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

left_ = [0] * (n + 1)
right_ = [0] * (n + 1)
ans = []

for i in range(n):
    left_[i] = gcd( left_[i-1], data[i] )

for i in range(n-1, 0, -1):
    right_[i] = gcd( right_[i+1], data[i] )

print( left_ )
print( right_ )

for i in range(n):
    ans += [ gcd( left_[i-1], right_[i+1] ) ]

print( max(ans) )


def check(ary, div):
    c = 0
    for i in range(len(ary)):
        if ary[i] % div == 0:
            c += 1
    if c >= len(ary) - 1:
        return True
    else:
        return False 

N = int(input())
data = list(map(int, input().split()))
ans = 1
for i in range(1, max(data) + 1):
    print(i)
    if check(data, i):
        ans = i

print(ans)


from functools import reduce
from fractions import gcd
import itertools

def gcd_check(data, ans):
    p = list(itertools.combinations(data, 2))
    for i in range(len(p)):
        ans.append(reduce(gcd, p[i]))
 
N = int(input())
data = list(map(int, input().split()))
ans_data = []
gcd_check(data, ans_data)

print(max(ans_data))


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

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

left_ = [0] * (n + 1)
right_ = [0] * (n + 1)
ans = []

for i in range(n):
    left_[i] = gcd( left_[i-1], data[i] )

for i in range(n-1, 0, -1):
    right_[i] = gcd( right_[i+1], data[i] )

for i in range(n):
    ans += [ gcd( left_[i-1], right_[i+1] ) ]

print( max(ans) )


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
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):
a

def g_c_d(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return g_c_d(y, x % y)


a = int(input())
b = list(map(int, input().split()))
c = [0] * (a + 1)
d = [0] * (a + 1)
for i in range(1, a + 1):
    c[i] = g_c_d(b[i-1], c[i-1])
    d[-i-1] = g_c_d(b[-i], d[-i])
e = 0
for i in range(len(c)-1):
    e = max(e, g_c_d(c[i], d[i+1]))
print(e)


Verdicts: Runtime Error

Accepted