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):
# C
import functools import reduce
import math

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

for i in range(n):
    values = a[:i] + a[i+1:]
    gcd = reduce(math.gcd, values)
    ans = max(ans, gcd)
print(ans)

# C
import functools
def gcd(a,b):
    if a<b:a,b=b,a
    if a%b==0:return b
    return gcd(b,a%b)

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

for i in range(n):
    values = a[:i] + a[i+1:]
    gcd = functools.reduce(gcd, values)
    ans = max(ans, gcd)
print(ans)

# C
import functools
def gcd(a,b):
    if a<b:a,b=b,a
    if a%b==0:return b
    return gcd(b,a%b)

n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
pre_a = -1

for i in range(n):
    if pre_a != a[i]:
        if len(a[:i]) >= 1 and len(a[i+1:] >= 1):
            res = gcd(functools.reduce(gcd, a[:i]), functools.reduce(gcd, a[i+1:]))
        else:
            values = a[:i] + a[i+1:]
            res = functools.reduce(gcd, values)
        ans = max(ans, res)
    pre_a = a[i]
print(ans)


# C
import functools

# from fractions import gcd
def gcd(a,b):
    if a<b:a,b=b,a
    if a%b==0:return b
    return gcd(b,a%b)


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

gcd_left = [a[0]]
gcd_right = [a[-1]]
for i in range(1,n):
    if gcd_left[i-1] != 1:
        res = gcd(gcd_left[i-1], a[i])
    else:
        res = 1
    gcd_left.append(res)

for i in range(1,n):
    if gcd_right[i-1] != 1:
        res = gcd(gcd_right[i-1], a[-(i+1)])
    else:
        res = 1
    gcd_right.append(res)
gcd_right = gcd_right[::-1]


ans = 0
for i in range(n):
    if i == 0:
        res = gcd_right[1]
    elif i == n-1:
        res = gcd_left[-2]
    else:
        res = gcd(gcd_right[i+1], gcd_left[i-1])
    ans = max(res, ans)
print(ans)


Verdicts: 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):
n=int(input())
l=list(map(int,input().split()))
s=[[0]for _ in range(n)]
#print(s)

import math
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
    
for i in range(n):
    if i==0:
        s[0]=l[1:]
    
    else:
        s[i]=l[:i]+l[i+1:]
ans=1
for i in s:
    ans=max(gcd_list(i),ans)
print(ans)

n=int(input())
l=list(map(int,input().split()))
s=[[0]for _ in range(n)]
#print(s)
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)

    divisors.sort(reverse=True)
    return divisors

l.sort()
ans=1

b=l[1]
bl=make_divisors(b)
for i in bl:
    check=True
    for j in range(1,n):
        if l[j]%i!=0:
            check=False
            break
    if check:
        ans=max(ans,i)
        break
a=min(l)
al=make_divisors(a)
#print(al)
for i in al:
    cnt=0
    for j in range(n):
        if l[j]%i!=0:
            cnt+=1
        if cnt>1:
            break
    if cnt==0 or cnt==1:
        ans=max(ans,i)
        break
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):
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc125_a
import fractions, functools, itertools

# input
n = int(input())
A = [int(s) for s in input().split()]

def search_booby(B):
    b0 = [fractions.gcd(B[0], a) for a in B[1:]]
    b0.sort()
    return b0[1]
def gcd_list(l):
    return functools.reduce(fractions.gcd, l)
B = itertools.cycle(A)
Bs = itertools.tee(B, 2)
Bs = (list(itertools.islice(B, i, i+n)) for i, B in enumerate(Bs))
Bs = map(search_booby, Bs)
ans = max(Bs)
# output
print(ans)



#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc125_a
import fractions, functools, itertools

# input
n = int(input())
A = [int(s) for s in input().split()]

b0 = [fractions.gcd(A[0], a) for a in A]
b1 = [fractions.gcd(A[1], a) for a in A]
b0.sort()
b1.sort()
ans = max(b0[1], b1[1])
# output
print(ans)



#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc125_c
import fractions, functools, itertools

# input
n = int(input())
A = [int(s) for s in input().split()]

x = A[0]
y = A[1]
def divisors(n):
     for i in range(2, n):
        if n%i == 0:
            yield i
ds = set(divisors(x)) + set(divisors(y))
def condition(d):
    not_div = (a%d != 0 for a in A)
    not_div = (1 if b else 0 for b in not_div)
    return sum(not_div) <= 1
ans = max(filter(condition, ds))
# output
print(ans)



#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-
 
# abc125_c
import fractions, functools, itertools
 
# input
n = int(input())
A = [int(s) for s in input().split()]

x = A[0]
y = A[1]
def divisors(n):
     for i in range(1, n+1):
        if i*i > n:
            break
        if n%i == 0:
            yield i
            yield n//i
ds = set(divisors(x)) | set(divisors(y))
def condition(d):
    not_div = (a%d != 0 for a in A)
    not_div = (1 if b else 0 for b in not_div)
    return sum(not_div) <= 1
ans = max(filter(condition, ds))
# output
print(ans)
 

Verdicts: Runtime Error

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):
import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


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


def gcd_m(*args):
    if len(args) == 0:
        return 0
    if len(args) == 1:
        return args[0]
    if len(args) >= 2:
        ret = gcd(args[0], args[1])

    for value in args[2:]:
        ret = gcd(ret, value)
    return ret


def solve(inputs):
    [N] = string_to_int(inputs[0])
    
    A = string_to_int(inputs[1])

    if N == 2:
        return max(A)

    left_gcd_memo = deque([0])
    right_gcd_memo = deque([0])

    for v in A:
        left_gcd_memo.append(gcd(left_gcd_memo[-1], v))
    for v in reversed(A):
        right_gcd_memo.appendleft(gcd(right_gcd_memo[0], v))

    max_gcd = 0
    for i in range(0, len(A)-1):
        g = gcd(left_gcd_memo[i], right_gcd_memo[N-i])
        max_gcd = g if g > max_gcd else max_gcd

    return max_gcd


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)


import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


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


def gcd_m(*args):
    if len(args) == 0:
        return 0
    if len(args) == 1:
        return args[0]
    if len(args) >= 2:
        ret = gcd(args[0], args[1])

    for value in args[2:]:
        ret = gcd(ret, value)
    return ret


def solve(inputs):
    [N] = string_to_int(inputs[0])
    
    A = string_to_int(inputs[1])

    if N == 2:
        return max(A)

    left_gcd_memo = deque([0])
    right_gcd_memo = deque([0])

    for v in A:
        left_gcd_memo.append(gcd(left_gcd_memo[-1], v))
    left_gcd_memo.append(0)
    for v in reversed(A):
        right_gcd_memo.appendleft(gcd(right_gcd_memo[0], v))
    right_gcd_memo.appendleft(0)

    max_gcd = 0
    for i in range(0, len(A)):
        left = left_gcd_memo[i]
        right = right_gcd_memo[i+2]
        g = gcd(left_gcd_memo[i], right_gcd_memo[i+2])
        max_gcd = g if g > max_gcd else max_gcd

    return max_gcd


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)


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())
v = [int(i) for i in input().split()]
if n == 2:
    print(max(v))

l = [0 for i in range(n)]
r = l[:]
l[1] = v[0]
r[-2] = v[-1]


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


for i in range(1, n-1):
    l[i + 1] = gcd(l[i], v[i])
    r[-i-2] = gcd(r[-i-1], v[-i-1])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))


import math
n = int(input())
v = [int(i) for i in input().split()]
if n == 2:
    print(max(v))


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


l = [0 for i in range(n)]
Y = [0 for i in range(n)]

for i in range(1, n):
    l[i] = gcd(l[i - 1], v[i - 1])
for i in range(n - 1)[::-1]:
    r[i] = gcd(r[i+1], v[i+1])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))


import math
n = int(input())
v = [int(i) for i in input().split()]
if n == 2:
    print(max(v))


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


l = [0 for i in range(n)]
r = l[:]

for i in range(1, n):
    l[i] = gcd(l[i - 1], v[i - 1])
for i in range(n - 1)[::-1]:
    r[i] = gcd(r[i+1], v[i+1])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))


import math
n = int(input())
v = [int(i) for i in input().split()]
if n == 2:
    print(max(v))


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


l = [0 for i in range(n)]
r = l[:]

for i in range(1, n):
    l[i] = gcd(l[i - 1], v[i - 1])
for i in range(n - 1)[::-1]:
    r[i] = gcd(r[i-1], v[i-1])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))


import math
n = int(input())
v = [int(i) for i in input().split()]
if n == 2:
    print(max(v))

l = [0 for i in range(n)]
r = l[:]


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


for i in range(n):
    l[i+1] = gcd(l[i], v[i])
    r[-i] = gcd(r[-i-1], v[-i-1])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))


n = int(input())
v = [int(i) for i in input().split()]


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


l = [0 for i in range(n)]
r = l[:]

for i in range(1, n):
    l[i] = gcd(l[i - 1], v[i - 1])
    r[-i-1] = gcd(r[-i], v[-i])
m = [gcd(l[i], r[i]) for i in range(n)]
print(max(m))


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

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

n = int(input())
data = list(map(int, input().split()))
array = data
L = []
L.append(data[0])
R = []
R.append(data[n - 1])
m = []
for i in range(n):
    L.append(euclid(L[i], data[i]))
data.reverse()
for i in range(n):
    R.append(euclid(R[i], data[i]))
R.reverse()
for i in range(1,n):
    m.append(euclid(L[i] , R[n - i]))
print(max(m))

def euclid(x, y):
    while x % y != 0:
        temp = x
        x = y
        y = temp % y
    return y

n = int(input())
data = list(map(int, input().split()))
max = 0
array = data
for j in range(n):
    array = data
    array[j] = array[(j + 1) % n]
    x = data[0]
    for i in array:
        if(x > i):
            x = euclid(x, i)
        else:
            x = euclid(i, x)
        if(x > max):
            max = x
print(max)


def euclid(x, y):
    if x == 0:
        return y
    if y == 0:
        return x
    while x % y != 0:
        temp = x
        x = y
        y = temp % y
    return y

n = int(input())
data = list(map(int, input().split()))
array = data
L = []
L.append(0)
R = []
R.append(0)
m = []
for i in range(n):
    L.append(euclid(L[i], data[i]))
data.reverse()
for i in range(n):
    R.append(euclid(R[i], data[i]))
R.reverse()
for i in range(0,n):
    m.append(euclid(L[i] , R[i + 1]))
print(max(m))


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):
import fractions

n=int(input())
al=input().split()
al_i = [int(s) for s in al]
m = max(al_i)
gm = 0

for x in range(n):
   t = al_i[x]
   al_i[x] = m
   g = al_i[0]
   for y in range(n):
      g = fractions.gcd(g,al_i[y]) 
   al_i[x] = t
   if g>gm:
      gm = g
print(gm)


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

n=int(input())
al=input().split()
al_i = [int(s) for s in al]

if (n == 2):
   print(gcd(al_i[0],al_i[1])
　 return
         
fg = [0] * n
bg = [0] * n

for x in range(n):
   if (x == 0):
       fg[0] = al_i[0]
       y = 1
   else:
      while y <= x:
         fg[y] = gcd(fg[y-1], al_i[y])
         y += 1

for x in range(n):
   if (x == 0):
      bg[0] = al_i[n-1]
      y = 1
   else:
      while y <= x:
         bg[y] = gcd(bg[y-1], al_i[n-1-y])
         y += 1

m = 0
gm = 0

for x in range(n):
   if (x == 0):
      g = bg[n-2]
   elif (x == n):
      g = fg[n-2]
   else:
      g = gcd(fg[x-1],bg[n-2-x])
   if (g > gm):
      gm = g

print(gm)


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

n=int(input())
al=input().split()
al_i = [int(s) for s in al]

for x in range(n):
   if (x == 0):
       fg[0] = al_i[0]
       y = 1
   else:
      while y <= x:
         fg[y] = gcd(fg[y-1], al_i[y])
         y += 1
for x in range(n):
   if (x == 0):
      bg[0] = al_i[n-1]
      y = 1
   else:
      while y <= x:
         bg[y] = gcd(bg[y-1], al_i[n-1-y])
         y += 1

m = 0
gm = 0

for x in range(n):
   if (x == 0):
      g = bg[n-2]
   elif (x == n):
      g = fg[n-2]
   else:
      g = fg[x-1] + bg[n-2-x]
   if (g > gm):
      g = gm

print(gm)


import fractions
from functools import reduce

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

n=int(input())
al=input().split()
al_i = [int(s) for s in al]
m = max(al_i)
gm = 0

for x in range(n):
   t = al_i[x]
   al_i[x] = m
   g = gcd(*al_i)
   al_i[x] = t
   if g>gm:
      gm = g
print(gm)


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

n=int(input())
al=[int(x) for x in input().split()]

fg = [0] * n
bg = [0] * n

fg[0] = al[0]
bg[0] = al[n-1]

for x in range(1,n):
    fg[x] = gcd(fg[x-1], al[x])
    bg[x] = gcd(bg[x-1], al[n-1-x])

gm = max(bg[n-2], fg[n-2])

for x in range(1,n-1):
   g = gcd(fg[x-1],bg[n-2-x])
   if (g > gm):
      gm = g

print(gm)

Verdicts: Time Limit Exceeded

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

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

for i in range(N):
        M = [A[i-1]]
        hoge = A[i]
        A[i] = A[i-1]
        for k in range(N):
                M.append(gcd(M[k],A[k]))
                print(M)

        if M[N] >= output:
                output = M[N]
        A[i]=hoge

print(output)

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

N = int(input())
A= list(map(int,input().split()))
output=0
KA=[0 for i in range(N)]
LA=[0 for i in range(N)]
GCD = []

for k in range(1,N):
        LA[k]=gcd(A[k-1],LA[k-1])

for k in range(1,N):
        KA[k]=gcd(A[N-k],KA[k-1])


for k in range(N):
        GCD.append(gcd(LA[k],KA[N-k-1]))
output = max(GCD)
print(output)

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 gcd(x,y):
    if y>x:
        a=y
        y=x
        x=a
    a=1
    while a*y:
        a=x%y
        x=y
        y=a
    return x

a=input()
b=list(map(int,input().split()))
l=[0]
r=[0]
g=[]
for a in range(len(b)-1):
    l.append(gcd(l[-1],b[a]))
    r.append(gcd(r[-1],b[-1-a]))
print(l)
print(r)
for a in range(len(l)):
    g.append(gcd(l[a],r[-1-a]))
print(max(g))

def gcd(x,y):
    if y>x:
        a=y
        y=x
        x=a
    a=1
    while a*y:
        a=x%y
        x=y
        y=a
    return x

a=input()
b=list(map(int,input().split()))
l=[0]
r=[0]
g=[]
for a in range(len(b)-1):
    l.append(gcd(l[-1],b[a]))
    r.append(gcd(r[-1],b[-1-a]))
for a in range(len(l)):
    g.append(gcd(l[a],r[-1-a]))
print(max(g))

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):
from math import gcd

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

if N==2:
    print(max(A))
else:
    L=[0 for _ in range(N)]
    R=[0 for _ in range(N)]
    L[0]=A[0]
    R[-1]=A[-1]
    for i in range(1,N):
        L[i]=gcd(A[i-1],L[i-1])
        R[N-1-i]=gcd(A[N-i],R[N-i])
    print(L)
    print(R)
    ans=max(L[-1],R[0])
    for j in range(1,N-1):
        ans=max(ans,gcd(L[j],R[j]))
    print(ans)

from math import gcd

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

if N==2:
    print(max(A))
else:
    L=[0 for _ in range(N)]
    R=[0 for _ in range(N)]
    L[0]=A[0]
    R[-1]=A[-1]
    for i in range(1,N):
        L[i]=gcd(A[i-1],L[i-1])
        R[N-1-i]=gcd(A[N-i],R[N-i])
    ans=max(L[-1],R[0])
    for j in range(1,N-1):
        ans=max(ans,gcd(L[j],R[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):
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m


N = int(input())
A = list(map(int, input().split()))
# gcd_list = []
# hoge = gcd(A[0], A[1])

#     gcd_list.append(gcd(hoge, A[i]))
# gcd_list.sort()
# print(gcd_list[len(gcd_list)-2])
A.sort()
max_A = max(A)
gcd_list = []
for i in range(int(N/2):
    tmp = A[i]
    A[i] = max_A
    hoge = gcd(A[0], A[1])
    for j in range(2, int(N/2):
        hoge = gcd(A[j], hoge)
    gcd_list.append(hoge)
    A[i] = tmp

print(max(gcd_list))



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



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


max_A = max(A)
gcd_list = []
if N == 1:
    print(A[0])
else:
    element = gcd(A[0], A[1])
    if N == 2:
        print(element)
        exit()
    else:
        for i in range(N):
            tmp = A[i]
            A[i] = max_A
            for j in range(2, N):
                element = gcd(element, A[i])
            gcd_list.append(element)
            A[i] = tmp
print(max(gcd_list))



def gcd(m, n):
    while n:
        m, n = n, m % n
    return m


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

"順方向累積GCD"
forward_gcd = [0]

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

"逆方向累積GCD"
reverse_gcd = [0]
for i in range(N-1, -1, -1):
    reverse_gcd.append(gcd(reverse_gcd[-1], A[i]))

reverse_gcd.reverse()

ans = 0
for i in range(N):
    ans = max(ans, gcd(forward_gcd[i], reverse_gcd[i+1]))

print(ans)


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

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

L=[a[0]]
gcdl = a[0]
R=[a[n-1]]
gcdr = a[n-1]
for xi in range(1,n):
    gcdl = math.gcd(gcdl,a[xi])
    L.append(gcdl)

for xi in range(n-2,-1,-1):
    gcdr = math.gcd(gcdr,a[xi])
    R.append(gcdr)

R.reverse()

print(R)
print(L)
m = []
m.append(R[1])
m.append(L[n-1])
# print(m)

if n>2:
    for xi in range(1,n-1):
        m.append(math.gcd(L[xi-1],R[xi+1]))
        print(xi, L[xi-1],R[xi+1])

print(m)
print(max(m))


import math

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

L=[a[0]]
gcdl = a[0]
R=[a[n-1]]
gcdr = a[n-1]
for xi in range(1,n):
    gcdl = math.gcd(gcdl,a[xi])
    L.append(gcdl)

for xi in range(n-2,-1,-1):
    gcdr = math.gcd(gcdr,a[xi])
    R.append(gcdr)

R.reverse()

# print("R", R)
# print("L", L)
m = []
m.append(R[1])
m.append(L[n-2])
# print(m)

if n>2:
    for xi in range(1,n-1):
        m.append(math.gcd(L[xi-1],R[xi+1]))
        # print(xi, R[xi+1],L[xi-1])

# print(m)
print(max(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):
def main():
    from fractions import gcd
    def update(k,x):
        k+=N0-1
        data[k]=x
        while k+1:
            k=~-k//2
            data[k]=gcd(data[2*k+1],data[2*k+2])
    def query(l,r):
        L,R=l+N0,r+N0
        s=0
        while L<R:
            if R&1:
                R-=1
                s=gcd(s,data[R-1])
            if L&1:
                s=gcd(s,data[L-1])
                L+=1
            L>>=1
            R>>=1
        return s
    n,*a=map(int,open(0).read().split())
    N0=2**(n-1).bit_length()
    data=[0]*2*N0
    for i in range(n):
        update(i,a[i])
    print(max(gcd(query(0,i),query(i+1,n))for i in range(n)))
if __name__=='__main__':
    main()

from fractions import*
n,*a=map(int,open(0).read().split())
*b,=c=[0]
for i in range(n):b+=gcd(b[i],a[i]),;c+=gcd(c[i],a[~i]),
print(max(gcd(b[i],c[i+2])for i in range(n-1)))

from fractions import*
def update(k,x):
    k+=N0-1
    data[k]=x
    while k+1:
        k=~-k//2
        data[k]=gcd(data[2*k+1],data[2*k+2])
def query(l,r):
    L,R=l+N0,r+N0
    s=0
    while L<R:
        if R&1:
            R-=1
            s=gcd(s,data[R-1])
        if L&1:
            s=gcd(s,data[L-1])
            L+=1
        L>>=1
        R>>=1
    return s
n,*a=map(int,open(0).read().split())
N0=2**(n-1).bit_length()
data=[0]*2*N0
for i in range(n):
    update(i,a[i])
print(max(gcd(query(0,i),query(i+1,n))for i in range(n-1)))

from math import*
n,*a=map(int,open(0).read().split())
b=[0]
for i in a:b+=gcd(b[-1],i),
w=m=0
for i in range(n):m=max(m,gcd(w,b[-i-2]));w=gcd(w,a[~i])
print(m)

Verdicts: Time Limit Exceeded

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

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

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

M = [gcd(L[i], R[i+1]) for i in range(N)]

print(max(M))

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

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

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

for i in range(N-1):
    gcd1 = 0
    A2 = A[:i] + A[i+1:]
    for j in range(N-2):
        gcd1 = gcd(A2[j], A2[j+1])
        A2[j+1] = gcd1
    L.append(gcd1)

print(max(L))

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

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

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

M = [gcd(L[i], R[i+1]) for i in range(N)]

print(max(M))

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

N = int(input())
A = list(map(int, input().split()))
A.sort()
B = []
C = []
for i in range(1,N):
  B.append(gcd(A[0],A[i]))
  C.append(gcd(A[1],A[i]))
B.sort()
C.sort()
print(B[1],C[1])


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

N = int(input())
A = list(map(int, input().split()))
B = [A[0]]
C = [A[N-1]]
for i in range(1,N):
  B.append(gcd(A[i],B[i-1]))
  C.append(gcd(A[N-i-1],C[i-1]))
D = [C[N-2]]
for j in range(N-2):
  D.append(gcd(B[j],C[N-j-3]))
D.append(B[N-2])
print(max(D))

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 as np
N = int(input())
A = sorted(list(map(int,input().split())))
ans = []

for n in range(N):
  B = A[:n]+A[n+1:]
  ans+=[np.gcd.reduce(B)]

print(min(ans))

from math import *
N = int(input())
A = list(map(int,input().split()))
L = (N+1)*[0]
R = (N+1)*[0]
ans = []

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

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

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

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


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

left = [0]
right = [0]

for i in range(N):
    left.append(gcd(left[-1], integers[i]))
    right.append(gcd(right[-1], integers[-i-1]))

# left[0] = 0
# right[0] = 0
right.reverse()

lr = []
for i in range(N-1):
    lr.append(gcd(left[i+1], right[i+2]))

print(max(lr))


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


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

left = [0]
right = [0]

for i in range(N):
    left.append(gcd(left[-1], integers[i]))
    right.append(gcd(right[-1], integers[-i-1]))

# right.reverse()

lr = []
for i in range(N):
    lr.append(gcd(left[i], right[-i-2]))

print(max(lr))


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 fractions import*
N＝int(input())
a  = list(map(int,input().split()))
B=[0]
a=range(N)
for x in a:B+=[gcd(B[-1],A[x])]
w=M=0
for x in a[::-1]:M=max(M,gcd(w,B[x]));w=gcd(w,A[x])
print(M)

n=int(input())
a=list(map(int,input().split()))
L=[0]
R=[0]
def gcd(x,y):
    if x==0:return y
    else:return gcd(y%x,x)
for i in range(n-1):
    L.append(gcd(L[i],a[i]))
    R.append(gcd(R[i],a[-1-i]))
MAX=0
for i in range(n):
    MAX=max(MAX,gcd(L[i],R[-1-i]))
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):
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

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

temp=a[0]
ans=[]
for i in range(1,n):
    g=gcd(a[i],temp)
    ans.append(g)
ans=sorted(ans)

try:
    print(ans[1])
except:
    print(ans[0])


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

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

temp=a[0]
ans=[1]
for i in range(1,n):
    g=gcd(a[i],temp)
    ans.append(g)
ans=sorted(ans)

print(ans[1])


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

n=int(input())
a=list(map(int,input().split()))
a.append(a[-1])

ans=[]

gcd_left=[0]*n
gcd_right=[0]*n
for i in range(1,n):
    gcd_left[i]=gcd(gcd_left[i-1],a[i-1])
    gcd_right[n-i-1]=gcd(gcd_right[n-i],a[n-i])

print(gcd_left)
print(gcd_right)

ans=[]
for i in range(n):
    ans.append(gcd(gcd_left[i],gcd_right[i]))

print(max(ans))

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

n=int(input())
a=list(map(int,input().split()))
a.append(a[-1])

ans=[]

gcd_left=[0]*n
gcd_right=[0]*n
for i in range(1,n):
    gcd_left[i]=gcd(gcd_left[i-1],a[i-1])
    gcd_right[n-i-1]=gcd(gcd_right[n-i],a[n-i])

ans=[]
for i in range(n):
    ans.append(gcd(gcd_left[i],gcd_right[i]))

print(max(ans))


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

n = int(input())
a = list(map(int, input().split()))
L = [0]
R = [0]
now1 = 0
now2 = 0
ans = 0

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

    now2 = gcd(now2,a[-i-1])
    R.append(now2)

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

print(ans)

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

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

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

M = [gcd(L[i], R[i+1]) for i in range(N)]

print(max(M))

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
inf = 10**10
import sys
input = sys.stdin.readline
def gcd_list(numbers):
    return reduce(math.gcd,numbers)
n = int(input())
a = list(map(int,input().split()))
index = inf
if n == 2:
    print(max(a))
else:
    a.sort()
    if math.gcd(a[0],a[n-1]) == 1:
        print(max(gcd_list(a[1:n]),gcd_list(a[0:n-1])))
    else:
        for i in range(1,n-1):
            ans = math.gcd(a[0],a[n-1])
            if math.gcd(a[i]-a[0],a[n-1]-a[i]) <= ans:
                index = i
                ans = math.gcd(a[i]-a[0],a[n-1]-a[i])
        print(gcd_list(a[0:i]+a[i+1:n]))

from functools import reduce
inf = 10**10
import sys
input = sys.stdin.readline


def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
def gcd_list(numbers):
    return reduce(gcd,numbers)
n = int(input())
a = list(map(int,input().split()))
index = inf
if n == 2:
    print(max(a))
else:
    a.sort()
    if gcd(a[0],a[n-1]) == 1:
        print(max(gcd_list(a[1:n]),gcd_list(a[0:n-1])))
    else:
        ans = gcd(a[0],a[n-1])
        for i in range(1,n-1):
            if gcd(a[i]-a[0],a[n-1]-a[i]) <= ans:
                index = i
                ans = gcd(a[i]-a[0],a[n-1]-a[i])
        print(max(gcd_list(a[0:index]+a[index+1:n]),gcd_list(a[1:n]),gcd_list(a[0:n-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):
# from math import gcd

def gcd(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x 

def cR(A, i):
    if i == len(A):
        return 0
    else:
        g = 0
        for i in range(i, len(A)):
            g = gcd(g, A[i])
        return g

def cL(A, i):
    if i == 1:
        return 0
    else:
        g = 0
        for i in range(i+1):
            g = gcd(g, A[i])
        return g


n = int(input())
A = list(map(int, input().split()))
A.append(0)
R = [0] * (n+2)
L = [0] * (n+2)
M = [0] * (n+2)

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

g = A[0]
for i in range(1,n+1):
    L[i] = gcd(g, A[i-1])

for i in range(1,n+1):
    M[i] = gcd(L[i], R[i+1])

# print(L, R, M)
print(max(M))

# from math import gcd

def gcd(x, y): 
    while(y): 
        x, y = y, x % y 
    return x 

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

R = [0] + list(A) + [0]
L = [0] + list(A) + [0]
M = [0] * (n+2)


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


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

for i in range(1,n+1):
    M[i] = gcd(L[i-1], R[i+1])

# print("A   ", A, " ")
# print("L", L)
# print("R", R)
# print("M", M)
print(max(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
from itertools import accumulate

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

fromright = list(accumulate(a, math.gcd))
a.reverse()
fromleft = list(accumulate(a, math.gcd))
fromleft.reverse()

gcd = []

gcd.append(fromleft[1])

for i in range(1, n-1):
  gcd.append(math.gcd(fromright[i-1], fromleft[i+1]))

gcd.append(fromright[1])

if n == 2:
  print(max(a))

import math
from itertools import accumulate

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

fromleft = list(accumulate(a, math.gcd))
fromright = list(accumulate(a[::-1], math.gcd))[::-1]

gcd = []

gcd.append(fromright[1])
for i in range(1, n-1):
    gcd.append(math.gcd(fromleft[i-1], fromright[i+1]))
gcd.append(fromleft[n-2])

print(max(gcd))

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
class segment_tree:
    
    def __init__(self, init_val, Input):
        
        n=len(Input)
        self.init_val = init_val
        self.num = 2 ** (n - 1).bit_length()
        self.seg = [init_val] * 2 * self.num
        for i in range(n):
            self.seg[i + self.num - 1] = Input[i]
        for i in range(self.num - 2, -1, -1):
            self.seg[i]=self._segfunc(self.seg[2*i+1],self.seg[2*i+2])
    def _segfunc(self, left, right):
        
        res=fractions.gcd(left,right)
        return res
    def update(self, k, x):
        
        k += self.num - 1
        self.seg[k] = x
        while k > 0:
            k = (k - 1) // 2
            self.seg[k] = self._segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
    def query(self, p, q):
        
        if q <= p:
            return self.init_val
        p += self.num - 1
        q += self.num - 2
        res = self.init_val
        while q - p > 1:
            if p % 2 == 0: 
                res = self._segfunc(res, self.seg[p])
            if q % 2 == 1:
                res = self._segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        res = self._segfunc(res, self.seg[p])
        res = self._segfunc(res, self.seg[q])
        return res
INF = 10 ** 10
n=int(input())
a=list(map(int,input().split()))

# a = [randint(0,N*2) for _ in range(N)]
dp = segment_tree(0, a)
ans=-1
for i in range(n):
  ans=max(ans,fractions.gcd(dp.query(0,i),dp.query(i+1,n)))
print(ans)

import fractions
from functools import reduce
import copy
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
n=int(input())
a_o=list(map(int,input().split()))
g=[1]*n
for i in range(n):
  a=copy.copy(a_o)
  a.pop(i)
  g[i]=gcd_list(a)
print(max(g))

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

Verdicts: Time Limit Exceeded

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

    


from math import gcd as g

def segfunc(x, y):
    return g(x,y)
#################

#####ide_ele#####
ide_ele =0
#################

class SegTree:
    
    def __init__(self, init_val, segfunc, ide_ele):
        
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

n=int(input())
a=list(map(int,input().split()))
seg=SegTree(a,segfunc,ide_ele)
ans=1
for i in range(n):
    p=seg.query(0,i)
    q=seg.query(i+1,n)
    ans=max(ans,g(p,q))
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 fractions
from functools import reduce

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

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

    tmp = gcd_list(a)
    ans = 0
    for i in range(n):
        a_ = a.copy()
        a_.pop(i)
        res = gcd_list(a_)
        if  tmp != res:
            print(res)
            break

if __name__ == '__main__':
    main()

import fractions
from functools import reduce

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

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()

    tmp = gcd_list(a)
    tmp2 = tmp
    ans = 0
    for i in range(n):
        a_ = a.copy()
        a_.pop(i)
        res = gcd_list(a_)
        if tmp != res:
            print(res)
            break
    if tmp2 == tmp:
        print(tmp)
if __name__ == '__main__':
    main()


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] * (n+1)
r = [0] * (n+1)

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

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

m = []
for i in range(n):
    m.append(gcd(l[i],r[i+1]))
print(max(m))

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

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

res = [0] * N
l = [0] * (N + 1)
r = [0] * (N + 1)

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

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

for i in range(N):
    res[i] = gcd(l[i], r[i+1])

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

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

res = [0] * N
l = [0] * (N + 1)
r = [0] * (N + 1)

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

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

for i in range(N):
    res[i] = gcd(l[i], r[i+1])

print(max(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):
import numpy as np
def gcd(a, b):
	if a > b:
		a, b = b, a
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
n = int(input())
a = np.array([int(x) for x in input().split()])
np.sort(a)
l = np.zeros(n + 1)
r = np.zeros(n + 1)
m = np.zeros(n)
for i in range(n):
	l[i + 1] = gcd(l[i], a[i])
for i in reversed(range(n)):
	r[i] = gcd(r[i + 1], a[i])
for i in range(n):
	m[i] = gcd(l[i], r[i + 1])
print(int(np.max(m)))


import numpy as np
def gcd(a, b):
	if a < b:
		a, b = b, a
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
n = int(input())
a = np.array([int(x) for x in input().split()])
np.sort(a)
l = np.zeros(n + 1)
r = np.zeros(n + 1)
m = np.zeros(n)
for i in range(n):
	l[i + 1] = gcd(l[i], a[i])
for i in reversed(range(n)):
	r[i] = gcd(r[i + 1], a[i])
for i in range(n):
	m[i] = gcd(l[i], r[i + 1])
print(int(np.max(m)))


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

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

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

max_gcd = 1
i_gcd = gcd_list(A[1:])
for i in range(1, N):
    if max_gcd < i_gcd:
        max_gcd = i_gcd
    i_gcd =  gcd_list(A[:(i-1)] + A[i:])

print(max_gcd)

from fractions import gcd
from functools import reduce

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

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

max_gcd = 1
for i in range(N):
    i_gcd =  gcd_list(A[:(i-1)] + A[i:])
    if max_gcd < i_gcd:
        max_gcd = i_gcd

print(max_gcd)

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

N = int(input()) 
A = [0] + list(map(int, input().split()))

# L[i]: gcd(A1,...,Ai)
# R[i]: gcd(Ai,...,AN)
L = [0]*(N+2)
R = [0]*(N+2)

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

res = 0
for i in range(1, N+1):
    rm_i = gcd(L[i-1], R[i+1])
    if res < rm_i:
        res = rm_i
print(res)

Verdicts: Wrong Answer

Wrong Answer

Accepted