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):
    if b == 0:
        return a
    elif a%b == 0:
        return b
    else:
        return gcd(b,a%b)

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

L = [0]*N
R = [0]*N

L[0] = A[0]
R[N-1] = A[N-1]

for n in range(1,N):
    L[n] = gcd(L[n-1],A[n])
    R[N-1-n] =gcd(R[N-n],A[N-1-n])

for n in range(N):
    GCDs[n] = gcd(L[n], R[N-1-n])

print(max(GCDs))

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

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

L = [0]
R = [0]
for n in range(N-1):
    L.append(gcd(L[-1],A[n]))
    R.append(gcd(R[-1],A[N-n-1]))
    
GCDs = []
for n in range(N):
    GCDs.append(gcd(L[n], R[N-n-1]))
    
print(max(GCDs))

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 a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

X = [0]*N
Y = [0]*N

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

Z = [0]*n
for i in range(N):
    Z[i]=gcd(X[i],Y[i])
print(max(Z))

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

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

X = [0]*N
Y = [0]*N

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

Z = [0]*N
for i in range(N):
    Z[i]=gcd(X[i],Y[i])
print(max(Z))

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):
def main():
  N=int(input())
  A=list(map(int, input().split()))
  
  for GCD in reversed(range(1,10**9)):
    error=0
    for i in range(0,N):
      if i%GCD==0:
        pass
      else:
        error+=1
        if error>=2:
          break
    if error<=1:
      break

  print(GCD)
    
main()

from math import gcd
N=int(input())
A=list(map(int,input().split()))

L=[A[0]]
R=[A[-1]]

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

ans=1
for j in range(N):
    if j==0:
        tmp = R[1]
    elif j==N-1:
        tmp = L[N-2]
    else:
        tmp = gcd(L[j-1],R[j+1])
    #print(j,tmp)
    ans=max(ans,tmp)
    
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):
n = int(input())
a = [int(i) for i in input().split()]
l_list = [0]
r_list = [0]
for i in range(n):
    l = gcd(l_list[i], a[i])
    l_list.append(l)
    r = gcd(r_list[-1], a[-i-1])
    r_list.append(r)
r_list = list(reversed(r_list))
r_list = r_list[1:]
l_list = l_list[:n]
c_list = []
for i in range(n):
    c_list.append(gcd(l_list[i], r_list[i]))
print(max(c_list))

from functools import reduce

def gcdd(x, y):
    for i in range(min(x, y), 1, -1):
        if x % i == 0 and y % i == 0:
            return i

def gcd(numbers):
    return reduce(gcdd, numbers)

n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(n):
    d = a[:i] + a[i+1:]
    b.append(gcd(d))
print(max(b))

def gcd(x, y):
    if x * y == 0:
        return (x+y)
    x, y = max(x, y), min(x, y)
    while y > 0:
        r = x % y
        x, y = y, r
    return x

n = int(input())
a = [int(i) for i in input().split()]
l_list = [0]
r_list = [0]
for i in range(n):
    l = gcd(l_list[i], a[i])
    l_list.append(l)
    r = gcd(r_list[-1], a[-i-1])
    r_list.append(r)
r_list = list(reversed(r_list))
r_list = r_list[1:]
l_list = l_list[:n]
c_list = []
for i in range(n):
    c_list.append(gcd(l_list[i], r_list[i]))
print(max(c_list))

Verdicts: Runtime Error

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_seq(seq):
    from fractions import gcd
    size = len(seq)
    if size == 1:
        return seq[0]
    if size == 2:
        return gcd(seq[0], seq[1])
    ans = gcd(seq[0], seq[1])
    for i in range(2, size):
        ans = gcd(seq[i], ans)
    return ans


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

ANS = gcd_seq(A)  
for i in range(N):
    a = A[:]
    a.pop(i)
    ANS = max((gcd_seq(a), ANS))
print(ANS)



def gcd(a, b):
    bigger = max(a, b)
    smaller = min(a, b)
    while smaller != 0:
        bigger, smaller = smaller, bigger % smaller
    return bigger


N = int(input())
A = list(map(int, input().split()))
gcd_l = [A[0]] + [0] * (N - 1)
for i in range(1, N):
    gcd_l[i] = gcd(gcd_l[i - 1], A[i])
del gcd_l[-1]

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

gcds = [gcd_l.pop(), gcd_r.pop(0)]
for l, r in zip(gcd_l, gcd_r):
    gcds.append(gcd(l, r))
print(max(gcds))


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


N = int(input())
A = input().split()
for i in range(N):
    A[i] = int(A[i])
    
if N == 2:
    print(max(A[0],A[1]))
if N >= 3:
    gcd_all = gcd(A[0], A[1])
    gcd_without_1 = A[0]
    gcd_without_2 = A[1]
    gcd_without_1 = max(gcd_all, max( gcd(gcd_without_1, A[i]),gcd(gcd_without_2, A[i])))
    gcd_all = math.gcd(gcd_all,A[2])
    for i in range(3,N):
        gcd_without_1 = max(gcd_all, gcd(gcd_without_1, A[i]))
        gcd_all = gcd(gcd_all,A[i])
    print(max(gcd_all, gcd_without_1))





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


N = int(input())
A = input().split()
for i in range(N):
    A[i] = int(A[i])
    
if N == 2:
    print(max(A[0],A[1]))
if N >= 3:
    gcd_all = gcd(A[0], A[1])
    gcd_without_1 = A[0]
    gcd_without_2 = A[1]
    gcd_without_1 = max(gcd_all, max( gcd(gcd_without_1, A[i]),gcd(gcd_without_2, A[i])))
    gcd_all = gcd(gcd_all,A[2])
    for i in range(3,N):
        gcd_without_1 = max(gcd_all, gcd(gcd_without_1, A[i]))
        gcd_all = gcd(gcd_all,A[i])
    print(max(gcd_all, gcd_without_1))





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 = list(map(int,input().split()))
hard = A[0]*A[1]
easy = A[0]
del A[0]
while len(A) != 0:
  easyt = fractions.gcd(hard,A[0])
  if easyt < easy:
    easy = easyt
  hard = fractions.gcd(hard,A[0])
  del A[0]
print(easy)

import fractions
N = int(input())
A = list(map(int,input().split()))
hard = fractions.gcd(A[0],A[1])
easy = [A[0],A[1]]
del A[0],A[1]
while len(A) != 0:
  easyt1 = fractions.gcd(easy[0],A[0])
  easyt2 = fractions.gcd(easy[1],A[0])
  easyt3 = hard
  easy = sorted([easyt1,easyt2,easyt3])[1:3]
  hard = fractions.gcd(hard,A[0])
  del A[0]
print(max(easy))

#14:10
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
  if i == 0:
    b.append(a[i])
  else:
    big = b[-1]
    sml = a[i]
    while sml != 0:
      big,sml = sml,big%sml
    b.append(big)
c = []
for j in range(n)[::-1]:
  if j == n-1:
    c.append(a[j])
  else:
    big = c[-1]
    sml = a[j]
    while sml != 0:
      big,sml = sml,big%sml
    c.append(big)
c.reverse()
d = []
for i in range(n):
  if i == 0:
    d.append(c[1])
  elif i == n-1:
    d.append(b[n-2])
  else:
    big = b[i-1]
    sml = c[i+1]
    while sml != 0:
      big,sml = sml,big%sml
    d.append(big)
#print(b)
#print(c)
#print(d)
print(max(d))

Verdicts: Wrong Answer

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()))

l=[]
l.append(0)
l.append(0)
r=[]
r.append(a[n-1])
r.append(a[n-1])
g=[]

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


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

for j in range(0,n):
  g.append(gcd(l[j+1],r[n-j-1]))

print(max(g))    
  
  


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

l=[]
l.append(a[0])
r=[]
r.append(a[n-1])
g=[]

def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(y,x%y)
  
for i in range(1,n-1):
  l.append(gcd(l[i-1],b[i]))
  r.append(gcd(r[i-1],b[n-1-i]))
  
for j in range(0,n):
  g.append(gcd(l[i],r[n-2-i]))
  
print(max(g))    
  
  


n=int(input())
a=list(map(int,input().split()))
b=[0]*n
x=0
def gcd(x,y):
  if x%y==0:
    print(y)
  else:
    return gcd(y,x%y)
  
for i in range(0,n-1):
  for j in range(i+1,n):
    x=gcd(a[i],a[j])
    b.append(x)
    
print(max(b))    
  
  


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

l=[]
l.append(0)
l.append(0)
r=[]
r.append(0)
r.append(a[n-1])
g=[]

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


for i in range(1,n):
  l.append(gcd(l[i],a[i-1]))
  r.append(gcd(r[i],a[n-1-i]))
  
  
for j in range(0,n):
  g.append(gcd(l[j+1],r[n-j-1]))

print(max(g))    
  
  


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

l=[]
l.append(a[0])
r=[]
r.append(a[n-1])
g=[]

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


for i in range(1,n):
  l.append(gcd(l[i-1],a[i]))
  r.append(gcd(r[i-1],b[n-1-i]))
  
  
for j in range(0,n-2):
  g.append(gcd(l[i],r[n-3-i]))
  
g.append(l[n-1])  
g.append(r[n-1])

print(max(g))    
  
  


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

l=[]
l.append(0)
l.append(0)
r=[]
r.append(0)
r.append(a[n-1])
g=[]

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


for i in range(1,n):
  l.append(gcd(l[i],a[i-1]))
  r.append(gcd(r[i],a[n-1-i]))
  
  
for j in range(0,n):
  g.append(gcd(l[j+1],r[n-j-1]))

print(max(g))    
  
  


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

l=[]
l.append(0)
l.append(0)
r=[]
r.append(a[n-1])
r.append(a[n-1])
g=[]

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


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

for j in range(0,n):
  g.append(gcd(l[j+1],r[n-j-1]))

print(max(g))    
  
  


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

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 as np
N = int(input())
As=input().split()
A = np.array([int(s) for s in As])
del(As)

min2A = A[A.argsort()[1]]
minA = np.amin(A)
if np.sum((A%min2A)==0)>=N-1:
    print(min2A)
elif np.sum((A%minA)==0)>=N-1:
    print(minA)
else:
    
    #    if np.sum((A%i)==0)>=N-1:
    #        print(i)
    #        break
    for i in range(min2A):
        if (min2A%i == 0) or (minA%i == 0):
            j = min2A/i
            if np.sum((A%j)==0)>=N-1:
                print(j)
                break



import numpy as np
N = int(input())
As=input().split()
A = np.array([int(s) for s in As])
del(As)

min2A = A[A.argsort()[1]]
minA = np.amin(A)
if np.sum((A%min2A)==0)>=N-1:
    print(min2A)
elif np.sum((A%minA)==0)>=N-1:
    print(minA)
else:
    for i in range(2,min2A+1):
        if (min2A%i == 0) or (minA%i == 0):
            if(min2A%i == 0):
                j = int(min2A/i)
            elif(minA%i == 0):
                j=int(minA/i)
            if np.sum((A%j)==0)>=N-1:
                print(j)
                break


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 fractions
from functools import reduce
N = int(input())
A = list(map(int,input().split()))
S = []
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
for i in range(N):
  B = A.copy()
  del B[i]
  m = gcd(*B)
  S.append(m)
print(max(S))

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: 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 fractions import gcd
n = int(input())
aaa = list(map(int, input().split()))
p = aaa[0]
f = [p]
for a in aaa[1:-1]:
    p = gcd(p, a)
    f.append(p)
aaa.reverse()
p = aaa[0]
b = [p]
for a in a[1:-1]:
    p = gcd(p, a)
    b.append(p)
f = [b[0]] + f
b = b + [f[-1]]
print(max(gcd(p, q)) for p, q in zip(f, b))

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

n = int(input())
aaa = list(map(int, input().split()))
cnt_l = [0] * (n - 1)
cnt_r = [0] * (n - 1)

cnt_l[0] = aaa[0]
for i in range(1, n - 1):
cnt_l[i] = gcd(cnt_l[i - 1], aaa[i])

aaa.reverse()
cnt_r[0] = aaa[0]
for i in range(1, n - 1):
cnt_r[i] = gcd(cnt_r[i - 1], aaa[i])

cnt_l = [cnt_r[-1]] + cnt_l
cnt_r = [cnt_l[-1]] + cnt_r
cnt_r.reverse()

ans = 0
for i in range(n - 1):
tmp = gcd(cnt_l[i], cnt_r[i])
ans = max(ans, tmp)

print(ans)


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

n = int(input())
aaa = list(map(int, input().split()))
cnt_l = [0] * (n - 1)
cnt_r = [0] * (n - 1)

cnt_l[0] = aaa[0]
for i in range(1, n - 1):
    cnt_l[i] = gcd(cnt_l[i - 1], aaa[i])

aaa.reverse()
cnt_r[0] = aaa[0]
for i in range(1, n - 1):
    cnt_r[i] = gcd(cnt_r[i - 1], aaa[i])

cnt_l = [cnt_r[-1]] + cnt_l
cnt_r = [cnt_l[-1]] + cnt_r
cnt_r.reverse()

ans = 1
for i in range(n):
    tmp = gcd(cnt_l[i], cnt_r[i])
    ans = max(ans, tmp)

print(ans)

Verdicts: Runtime Error

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

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


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

if N<=2:
	print(max(a))
else:
	ans = gcd_list(a[1:])
	for i in range(1,N):
		temp_gcd = gcd_list(a[0:i]+a[i+1:])

		ans = max(ans , temp_gcd)

print(ans)


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


def gcd(a, b):
    if a < b: return gcd(b, a)
    elif b > 0: return gcd(b, a % b)
    else:
        return a

L = [0,a[0]]
R = [0,a[-1]]

for i in range(1,N):
	L.append(gcd(a[i] , L[-1]))
	R.append(gcd(a[-(i+1)] , R[-1]))
gcd_val_list = []
for i in range(N):
	gcd_val_list.append(gcd(L[i] , R[-(i+2)]))
print(max(gcd_val_list))

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):
# C - GCD on Blackboard

n = int(input())
a = list(int(x) for x in input().split())
a.sort()

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

if n==2:
    print(max(a))
else:
    ans = max(gcd(a[0],a[1]), gcd(a[1],a[2]), gcd(a[2],a[0]))
    print(ans)
    for i in range(3, n):
        ans = gcd(a[i], ans)
    print(ans)

# C - GCD on Blackboard
from collections import defaultdict

n = int(input())
a = list(int(x) for x in input().split())

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


L = [0]*(n+1)
L[0] = 0
for i in range(n):
    L[i+1] = gcd(L[i], a[i])


R = [0]*(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: 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):
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a%b)
    }
}

fn main() {
    let N: usize = read_line().parse().unwrap();
    let A = read_vec();

    let mut left = vec![0; N];
    let mut right = vec![0; N];

    left[0] = A[0];
    for i in 1..N {
        left[i] = gcd(left[i-1], A[i]);
    }
    right[N-1] = A[N-1];
    for i in (0..N-1).rev() {
        right[i] = gcd(right[i+1], A[i]);
    }

    let mut max = right[1];
    for i in 1..N-1 {
        max = std::cmp::max(max, gcd(left[i-1], right[i+1]));
    }
    max = std::cmp::max(max, left[N-2]);
    println!("{}", max);
}


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


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

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

ans = gcd_from_right[1]
gcd_from_left = A[0]
for i in range(1, N-1):
    ans = max(ans, gcd(gcd_from_left, gcd_from_right[i+1]))
    gcd_from_left = gcd(gcd_from_left, A[i])
ans = max(ans, gcd_from_left)
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):
from functools import reduce


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


def lcm(a, b):
    return a * b // gcd(a, b)


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

l = [0 for i in range(n)]
for i in range(0, n - 1, 1):
    l[i + 1] = gcd(l[i], a[i])
    print(l[i + i])

r = [0 for i in range(n)]
for i in range(n - 2, -1, -1):
    r[i] = gcd(r[i + 1], a[i + 1])
    print(r[i])

m = [gcd(l[i], r[i]) for i in range(n)]

print(reduce(max, m))


from functools import reduce


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


def lcm(a, b):
    return a * b // gcd(a, b)


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

l = [0 for i in range(n)]
for i in range(0, n - 2, 1):
    l[i + 1] = gcd(l[i], a[i])

r = [0 for i in range(n)]
for i in range(n - 2, 0, -1):
    r[i] = gcd(r[i + 1], a[i + 1])

m = [gcd(l[i], r[i]) for i in range(n)]

print(reduce(max, m))


from functools import reduce


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


def lcm(a, b):
    return a * b // gcd(a, b)


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

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

r = [0 for i in range(n)]
for i in range(n - 2, -1, -1):
    r[i] = gcd(r[i + 1], a[i + 1])

m = [gcd(l[i], r[i]) for i in range(n)]

print(reduce(max, m))


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 

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

N = int(input())
T = list(map(int,input().split()))
T.sort()
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
GCD = 0
GCD += LIS[N-1]
if N == 2:
    ANS = max(T[0],T[1])
else:
    
    S = copy.copy(T)
    S.pop(0)
    LS = [0]*(N-1)
    LS[0] += S[0]
    for i in range(N-2):
        LS[i+1] += gcd(LS[i],S[i+1])
    ANSA = LS[N-2]

    
    LJ = []
    for i in range(N-1):
        if LIS[i] != LIS[i+1]:
            LJ.append(i+1)

    LK = []
    for j in range(len(LJ)):
        U = copy.copy(T)
        U.pop(LJ[j])
        print(U)
        LS = [0]*(N-1)
        LS[0] += U[0]
        for i in range(N-2):
            LS[i+1] += gcd(LS[i],S[i+1])
        LK.append(LS[N-2])
    ANSB = max(LK)
    ANS = max(ANSA,ANSB)
print(ANS)


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

N = int(input())
T = list(map(int,input().split()))
LIS = []
for i in range(N-1):
    A = gcd(T[i],T[i+1])
    LIS.append(A)
F = LIS.index(min(LIS))
T.pop(F+1)
LIS = []
for i in range(N-2):
    A = gcd(T[i],T[i+1])
    LIS.append(A)
print(min(LIS))

import functools
import fractions

N = int(input())
T = list(map(int,input().split()))
T.sort()
ANSL = []
for i in range(len(T)):
    S = []
    for j in range(len(T)):
        S.append(T[j])
    S.pop(i)
    ANS = functools.reduce(fractions.gcd, S)
    ANSL.append(ANS)
print(max(ANSL))

import copy 

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

N = int(input())
T = list(map(int,input().split()))
T.sort()
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
GCD = 0
GCD += LIS[N-1]
if N == 2:
    ANS = max(T[0],T[1])
else:
    
    S = copy.copy(T)
    S.pop(0)
    LS = [0]*(N-1)
    LS[0] += S[0]
    for i in range(N-2):
        LS[i+1] += gcd(LS[i],S[i+1])
    ANSA = LS[N-2]

    
    LJ = []
    for i in range(N-1):
        if LIS[i] != LIS[i+1]:
            LJ.append(i+1)
    if LJ == []:
        ANS =max(ANSA,LIS[0])
    else:
        LK = []
        for j in range(len(LJ)):
            U = copy.copy(T)
            U.pop(LJ[j])
            LS = [0]*(N-1)
            LS[0] += U[0]
            for i in range(N-2):
                LS[i+1] += gcd(LS[i],U[i+1])
            LK.append(LS[N-2])
        ANSB = max(LK)
        ANS = max(ANSA,ANSB)
print(ANS)

Verdicts: Runtime Error

Runtime Error

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):
def gcd(a, b):  # a>b
    a, b = max(a, b), min(a, b)
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


N = int(input())
A = list(map(int, input().split()))
R = [0 for i in range(N - 1)]
L = [0 for i in range(N - 1)]
R[0] = A[0]
L[0] = A[-1]
for i in range(1, N - 1):
    R[i] = gcd(R[i - 1], A[i])
for j in range(1, N - 1):
    L[j] = gcd(L[j - 1], A[-1 - j])
    # print(L[j])
t = 0
for i in range(N - 2):
    print(R[i], L[N - 3 - i])
    t = max(t, gcd(R[i], L[N - 3 - i]))
print(max(t, R[-1], L[-1]))


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


N = int(input())
A = list(map(int, input().split()))
R = [0 for i in range(N - 1)]
L = [0 for i in range(N - 1)]
R[0] = A[0]
L[0] = A[-1]
for i in range(1, N - 1):
    R[i] = gcd(R[i - 1], A[i])
for j in range(1, N - 1):
    L[j] = gcd(L[j - 1], A[-1 - j])
    # print(L[j])
t = 0
for i in range(N - 2):
    # print(R[i], L[N - 3 - i])
    t = max(t, gcd(R[i], L[N - 3 - i]))
print(max(t, R[-1], L[-1]))


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

kosuu = int(input())
nums = list(map(int,input().split()))

L = []
R = []
for temp in range(kosuu-1):
    if temp == 0:
        L.append(nums[0])
    else:
        L.append(gcd(L[temp-1],nums[temp]))

for temp in range(kosuu-1):
    if temp == 0:
        R.append(nums[kosuu-1])
    else:
        R.append(gcd(R[temp-1],nums[len(nums)-temp-1]))

print(L,R)
saidai=[]
for i in range(kosuu):
    if i == 0:
        saidai.append(L[-1])
    elif i == kosuu-1:
        saidai.append(R[-1])
    else:
        saidai.append(gcd(L[i-1],R[-1-i]))

print(max(saidai))

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

kosuu = int(input())
nums = list(map(int,input().split()))

L = []
R = []
for temp in range(kosuu-1):
    if temp == 0:
        L.append(nums[0])
    else:
        L.append(gcd(L[temp-1],nums[temp]))

for temp in range(kosuu-1):
    if temp == 0:
        R.append(nums[kosuu-1])
    else:
        R.append(gcd(R[temp-1],nums[len(nums)-temp-1]))

saidai=[]
for i in range(kosuu):
    if i == 0:
        saidai.append(L[-1])
    elif i == kosuu-1:
        saidai.append(R[-1])
    else:
        saidai.append(gcd(L[i-1],R[-1-i]))

print(max(saidai))

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

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

res = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if j-1 == i:
            B = [A[j],A[j-2]]
        else:
            B = [A[j],A[j-1]]
        res = max(res,gcd(max(B),min(B)))
    print(B)
    print(res)

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

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

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

res = 0
for i in range(N):
    if i == 0:
        res = max(res,R[-3])
    elif i == N-1:
        res = max(res,L[-3])
    else:
        res = max(res,gcd(L[i-1],R[-i-3]))
        
print(res)

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):
def gcd(a,b):
  if a>b:
    a,b = b,a
  if a==1:
    return a
  else:
    return gcd(b%a,a)

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

ans = A[1]
g = A[0]

for i in range(N):
  g = gcd(g,A[i])
  ans = max(ans,g)
print(ans)

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

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

from collections import defaultdict

L = defaultdict(lambda :1)
R = defaultdict(lambda :1)
L[1] = A[0]
R[1] = A[N-1]

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

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

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 functools
import copy

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

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

def gcd_l(l):
    return functools.reduce(lambda x, y: gcd(x, y), l)


l = [0] * N  
for i in range(N):
    if i == 0:
        continue
    else:
        l[i] = gcd_l(l[i-1] + A[i-1])

r = [0] * N 
for j in range(N):
    if j == 0:
        continue
    else:
        r[N-j] = gcd_l(r[N-j] + A[N-j-1])

m = [0] * N
for i in range(N):
    m[i] = gcd(l[i], r[i])

print(max(m))


import functools
import copy

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

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

gcds = []
if N == 2:
    n = max(A)
else:
    for i in range(N-1):
        if i == 0:
            continue
        l = A[0:i]
        r = A[i+1:N]

        l_gcd = functools.reduce(lambda x, y: gcd(x, y), l)
        r_gcd = functools.reduce(lambda x, y: gcd(x, y), r)
        gcds.append(gcd(l_gcd, r_gcd))

print(max(gcds))


import functools
import copy

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

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

gcds = []
if N == 2:
    gcds.append(max(A))
else:
    for i in range(N-1):
        if i == 0:
            continue
        l = A[0:i]
        r = A[i+1:N]

        l_gcd = functools.reduce(lambda x, y: gcd(x, y), l)
        r_gcd = functools.reduce(lambda x, y: gcd(x, y), r)
        gcds.append(gcd(l_gcd, r_gcd))

print(max(gcds))


import functools
import copy

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

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

l = [0] * N  
for i in range(N):
    if i == 0:
        continue
    else:
        l[i] = gcd(l[i-1], A[i-1])

r = [0] * N 
for j in range(N):
    if j == 0:
        continue
    else:
        r[N-j-1] = gcd(r[N-j], A[N-j])

m = [0] * N
for i in range(N):
    m[i] = gcd(l[i], r[i])

print(max(m))


Verdicts: Runtime Error

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 functools
import fractions
import copy

n = int(input())
a = list(map(int, input().split()))
cleana = copy.deepcopy(a)

def GCD(values):
    g = functools.reduce(fractions.gcd, values)
    return g

ans = 0
for i in range(n):
    a.remove(cleana[i])
    ans = max(ans, GCD(a))
    # print("a:",a)
    # print("GCD:",GCD(a))
    a = copy.deepcopy(cleana)

print(ans)


import functools
import fractions
import copy

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

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

l = [a[0]]
for i in range(1,n):
    l.append(gcd(l[-1],a[i]))
l = [0]+l

a.reverse()
r = [a[0]]
for i in range(1,n):
    r.append(gcd(r[-1],a[i]))
r = [0]+r
r.reverse()

# print(l)
# print(r)

ans = 1
for i in range(n):
    ans = max(ans, gcd(l[i],r[i+1]))

print(ans)


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):
    a, b = max(a, b), min(a, b)
    if b == 0:
        return a
    if a % b == 0:
        return b
    return gcd(b, a%b)

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

maxGCD = 1
for j in range(N):
    maxGCD = max(maxGCD, gcd(L[i], R[N-i-1]))
print(maxGCD)


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

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

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

maxGCD = 1
for j in range(N):
    maxGCD = max(maxGCD, gcd(L[j], R[N-j-1]))
print(maxGCD)


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):
print(1)

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


def cul(n,x):
    l=len(x)
    b=[x[i] for i in range(l)]
    b.pop(n)
    tmp=b[0]
    for i in range(1,l-1):
        tmp=gcd(tmp,b[i])
    return tmp

import sys
import math
p=10
N=int(input())
a=list(map(int,input().split()))
if N<=p:
    ans=0
    
    for i in range(N):
        tmp=cul(i,a)        
        if tmp>ans: ans=tmp
    print(ans)
    sys.exit()
        
M=a[0]
for i in range(1,p):
    M=gcd(M,a[i])

ans=0
for i in range(1,math.ceil(M**0.5)+1 ):
    if M%i==0:
        cnt=0
        for j in range(p,N):
            if a[j]%i!=0:
                cnt+=1
                if cnt==2: break
            elif j==N-1 and i>ans: ans=i
        
        x=M//i
        cnt=0
        for j in range(p,N):
            if a[j]%x!=0:
                cnt+=1
                if cnt==2: break
            elif j==N-1 and x>ans: ans=x

R=a[p]
for i in range(p+1,N):
    R=gcd(R,a[i])

if R>ans:
    for i in range(p):
        s=gcd(cul(i,a[:p]),R)
        if s>ans: ans=s

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):
N = int(input())
nums = [int(i) for i in input().split()]
nums = list((set(nums)))
def compute_divs(n):
    divs = []
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            divs.append(i)
            if i != n // i:
                divs.append(n//i)
    divs.append(n)
    return divs

if len(nums) == 1: ans = nums[0]
else:
    divs1 = compute_divs(nums[0])
    divs2 = compute_divs(nums[1])
    divs = sorted(list(set(divs1+divs2)))
    print(divs)
    for i in reversed(divs):
        c= 0
        for j in range(len(nums)):
            if nums[j] % i != 0:
                c += 1
                if c == 2:
                    break
        if c <= 1:
            ans = i
            break
print(ans)

N = int(input())
nums = [int(i) for i in input().split()]
from fractions import gcd
from functools import reduce
def compute_gcd(numbers):
    return reduce(gcd, numbers)
from copy import copy
gcds = []
for i in range(len(nums)):
    n = copy(nums)
    n.pop(i)
    gcds.append(compute_gcd(n))
print(max(gcds))

N = int(input())
nums = [int(i) for i in input().split()]
from fractions import gcd
from functools import reduce
def compute_gcd(numbers):
    return reduce(gcd, numbers)
from copy import copy
gcds = []
for i in range(len(nums)):
    n = copy(nums)
    n.pop(i)
    gcds.append(compute_gcd(n))
gcds = list(set(gcds))
print(gcds[-1])

N = int(input())
nums = [int(i) for i in input().split()]
from fraction import gcd
from functools import reduce
def compute_gcd(numbers):
    return reduce(gcd, numbers)
from copy import copy
gcds = []
for i in range(len(nums)):
    n = copy(nums)
    n.pop(i)
    gcds.append(compute_gcd(n))
gcds = list(set(gcds))
print(gcds[-1])

N = int(input())
nums = [int(i) for i in input().split()]
nums_sorted = sorted(list((set(nums))), reverse=True)
def compute_divs(n):
    divs = []
    if n == 1: return [1]
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            divs.append(i)
            if i != n // i:
                divs.append(n//i)
    divs.append(n)
    return divs
ans = 1
if len(nums_sorted) == 1: ans = nums[0]
else:
    divs1 = compute_divs(nums_sorted[0])
    divs2 = compute_divs(nums_sorted[1])
    divs = sorted(list(set(divs1+divs2)))
    for i in reversed(divs):
        c= 0
        for j in nums:
            if j % i != 0:
                c += 1
                if c == 2:
                    break
        if c <= 1:
            ans = i
            break
print(ans)

Verdicts: Runtime Error

Time Limit Exceeded

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

def list_gcd(l):
    if len(l) == 0:
      return 0
    elif len(l) == 1:
      return l[0]
    elif len(l) == 2:
      return fractions.gcd(l[0], l[1])
    else:
      m = l[1:]
      return fractions.gcd(l[0],list_gcd(m))

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

if N == 2:
  print(max(A))
else:
  m = -1
  for i in range(N):
    L = [A[j] for j in range(0, i)]
    R = [A[j] for j in range(i+1, N)]
    m = max(m, fractions.gcd(list_gcd(L),list_gcd(R)))
  print(m)



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(map(int, input().split()))

if N == 2:
  print(max(A))
else:
  l = []
  for i in range(0,N-1):
      l.append(gcd(A[i], A[i+1]))
  m = 1000000000
  for i in l:
    if l.count(i) > 1:
      m = min(m, i)
  print(m)


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


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

if N == 2:
  print(max(A))
else:

  L = [0 for j in range(N+1)]
  R = [0 for j in range(N+1)]
  
  for j in range(N):
    L[j+1] = gcd(L[j], A[j])
  for j in reversed(range(N)):
    R[j] = gcd(R[j+1], A[j])

    m = -1
  for j in range(N):
    m = max(m, gcd(L[j], R[j+1]))
  print(m)

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 math
from functools import reduce
import fraction

result = 0

n = int(input())
A = list(map(int, input().split()))
for i in range(n):
    result = max(result, reduce(fraction.gcd, A[:i]+A[i+1:]))

print(result)

from functools import reduce

result = 0

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

n = int(input())
A = list(map(int, input().split()))
X = [0 for i in range n]
Y = [0 for i in range n]
for i in range(1, N):
    X[i] = gcd(X[i-1], A[i-1])
for i in range(n-1)[::-1]:
    Y[i] = gcd(Y[i+1], A[i+1])
print(max(gcd(X[i], Y[i]) for i in range(n)))


from functools import reduce

result = 0

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

n = int(input())
A = list(map(int, input().split()))
X = [0 for i in range(n)]
Y = [0 for i in range(n)]
for i in range(1, n):
    X[i] = gcd(X[i-1], A[i-1])
for i in range(n-1)[::-1]:
    Y[i] = gcd(Y[i+1], A[i+1])
print(max(gcd(X[i], Y[i]) for i in range(n)))


Verdicts: Runtime Error

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(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)
n = int(input())
A = input().split()
B = sorted(list(set([int(a) for a in A])))
print(B)
ans = 0
if len(B) <= 2:
    ans = max(B)
else:
    # B = list(set(m[:]))
    # B = sorted(B)
    
    B = B[:3]
    gcm = gcd(B[0], B[1])
    if gcm > ans:
            ans = gcm
    gcm = gcd(B[1], B[2])
    if gcm > ans:
            ans = gcm
    gcm = gcd(B[0], B[2])
    if gcm > ans:
            ans = gcm
print(ans)

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

N=int(input())
A=[int(i) for i in input().split()]
X=[0 for i in range(N)]
Y=[0 for i in range(N)]
for i in range(1,N):
    X[i]=gcd(X[i-1],A[i-1])
for i in range(N-1)[::-1]:
    Y[i]=gcd(Y[i+1],A[i+1])
Z=[gcd(X[i],Y[i]) for i in range(N)]
print(max(Z))

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):
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,a,b=int(input()),list(map(int,input().split())),[]
#no,mi=a[0],a[0]
for i in range(1,n):
  b.append(gcd(a[i-1],a[i]))
b.sort()
if n==2:print(gcd(a[0],a[1]))
elif n==3:print(min(gcd(a[0],a[2]),b[1]))
else:print(b[2])

def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,a=int(input()),list(map(int,input().split()))
if n==2:print(max(a));exit()
if n==3:print(max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])));exit()
ans=ans2=a[0]
for i in range(1,n):
  g=gcd(ans,a[i])
  if g!=ans:
    ans=max(g,ans2)
    ans2=gcd(g,ans2)
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):
for i in range(sorted(A)[1],1,-1):
	if(np.sum(A%i==0)>=N-1):
		print(i)
		exit()
print(1)



#import numpy as np

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

#A=np.array(A)







for i in range(sorted(A)[1],1,-1):
#	if(np.sum(A%i==0)>=N-1):
	
	#check
	b=0
	j=0
	while(b<2):
		if(j==N):
			print(i)
			exit()
		if(A[j]%i!=0):
			b+=1
		j+=1
print(1)


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
from functools import reduce
N = int(input())
A = list(map(int,input().split()))
result = [0]*N
tmp = 0
for i in range(N):
  tmp = A.pop(i)
  result[i] = reduce(fractions.gcd, A)
  A.insert(i,tmp)

print(max(result))

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

left = [0]
right = [0]
for i in range(N):
  left.append(fractions.gcd(left[i],A[i]))
  right.insert(0,fractions.gcd(right[0],A[N-1-i]))

ans = 0
for i in range(N):
  ans = max(ans,fractions.gcd(left[i],right[i + 1]))
print(ans)

import math
N = int(input())
A = list(map(int,input().split()))
dp_left=[0]*(N+1)
dp_right=[0]*(N+1)
for i in range(N):
  dp_left[i+1]=math.gcd(dp_left[i],A[i])
  dp_right[N-i-1]=math.gcd(dp_right[N-i],A[N-1-i])

print(dp_left)
print(dp_right)


ans = 0
for i in range(N):
  ans = max(ans,math.gcd(dp_left[i],dp_right[i+1]))
print(ans)

import math
N = int(input())
A = list(map(int,input().split()))
dp_left=[0]*(N+1)
dp_right=[0]*(N+1)
for i in range(N):
  dp_left[i+1]=math.gcd(dp_left[i],A[i])
  dp_right[N-i-1]=math.gcd(dp_right[N-i],A[N-1-i])

ans = 0
for i in range(N):
  ans = max(ans,math.gcd(dp_left[i],dp_right[i+1]))
print(ans)

Verdicts: Time Limit Exceeded

Time Limit Exceeded

Wrong Answer

Accepted