ZhenlongDai/ACPR huggingface dataset:
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(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])
    
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]))


Failing test case input:
3
32 24 1

Expected output:
8


Actual output:
32 1
8


Fixed submission (verdict: Accepted):
def gcd(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])
    
t = 0
for i in range(N - 2):
    
    t = max(t, gcd(R[i], L[N - 3 - i]))
print(max(t, R[-1], L[-1]))

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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

N=int(input())
A=list(map(int,input().split()))
if N==2:
    print(max(A))
    exit()

org_A=A[:]

A=A[::-1]
l=[A.pop(-1)]
while A:
    l.append(euclid(l[-1],A.pop(-1)))

A=org_A
r=[A.pop(-1)]
while A:
    r.append(euclid(r[-1],A.pop(-1)))
r=r[::-1]

ans=0
for i in range(N-1):
    temp=euclid(l[i-1] if i!=0 else r[i+1],r[i+1] if i!=N-1 else l[i-1])
    ans=max(ans,temp)

print(ans)


Failing test case input:
3
36 36 10

Expected output:
36


Actual output:
2


Fixed submission (verdict: Accepted):


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

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

org_A=A[:]

A=A[::-1]
l=[A.pop(-1)]
while A:
    l.append(euclid(l[-1],A.pop(-1)))

A=org_A
r=[A.pop(-1)]
while A:
    r.append(euclid(r[-1],A.pop(-1)))
r=r[::-1]

ans=0

for i in range(N):
    temp=euclid(l[i-1] if i!=0 else r[i+1],r[i+1] if i!=N-1 else l[i-1])
    
    ans=max(ans,temp)

print(ans)
Problem: p03061
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import functools

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

def gcd(nums):
    return functools.reduce(euclid, nums)

N = int(input())
A = list(map(int,(input().split())))
L = [0]*N
R = [0]*N

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

p = []

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

print(max(p))

Failing test case input:
2
0001010111 0100001100

Expected output:
100001100


Actual output:
1


Fixed submission (verdict: Accepted):
import functools

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

def gcd(nums):
    return functools.reduce(euclid, nums)

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

p = []

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

print(max(p))

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

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

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

list_gcd = [l[-2], r[-2]]
for n in range(N - 2):
	list_gcd += [gcd(l[n], r[n + 2])]





print(max(list_gcd))


Failing test case input:
2
0001111011 1011100101

Expected output:
1011100101


Actual output:
1111011


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))

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

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

list_gcd = [l[-2], r[1]]
for n in range(N - 2):
	list_gcd += [gcd(l[n], r[n + 2])]





print(max(list_gcd))
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
A = list(map(int,input().split()))
A.sort()
def find(inte):
    re = []
    for i in range(1,int(inte**0.5)+1):
        if inte%i==0:
            re.append(i)
            if i != inte/i:
                re.append(int(inte/i))
    return set(re)
flag =True
if n==2:
    intersection = find(A[0]) & find(A[1]) 
    print(max(intersection))
else:
    a1 = find(A[0])
    a2 = find(A[1])
    a3 = find(A[2])
    max1 = max(a1&a2)
    max2 = max(a1&a3)
    max3 = max(a2&a3)
    ans = max(max1,max2,max3)
    for a in A[3:]:
        if a%ans != 0:
            print(1)
            flag = False
            break
    if flag:
        print(ans)
        

Failing test case input:
2
1011101111 1101111101

Expected output:
1101111101


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
A = list(map(int,input().split()))
A.sort()
def find(inte):
    re = []
    for i in range(1,int(inte**0.5)+1):
        if inte%i==0:
            re.append(i)
            if i != inte/i:
                re.append(int(inte/i))
    return set(re)
if n==2:
    print(A[1])
else:
    a1 = find(A[0])
    a2 = find(A[1])
    a3 = find(A[2])
    t1 = a1 & a2
    t2 = a2 & a3
    t3 = a1 & a3
    cond = t1 | t2 |t3
    maxi = 0
    for con in cond:
        count = 0
        flag = True
        for a in A:
            if a%con != 0:
                count +=1
            if count >= 2:
                
                flag = False
                break
        if flag and maxi < con:
            maxi = con
    print(maxi)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
def divi(a, b):
    rem = b % a
    if rem == 0:
        return a
    else:
        return divi(rem, a)
A.sort()
all_d = A[0]
max_d = 1
for i in range(1,N):
    d = divi(all_d, A[i])
    max_d = divi(max_d, A[i])
    if max_d < all_d:
        max_d = all_d
    all_d = d
print(max_d)

Failing test case input:
2
0001000110 0001001100

Expected output:
1001100


Actual output:
1000110


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
def divi(a, b):
    rem = b % a
    if rem == 0:
        return a
    else:
        return divi(rem, a)
A.sort()
all_d = divi(A[0], A[1])
max_d = max(all_d, max(divi(A[1],A[2]), divi(A[0],A[2]))) if N > 2 else A[1]
for i in range(2,N):
    d = divi(all_d, A[i])
    max_d = divi(max_d, A[i])
    if max_d < all_d:
        max_d = all_d
    all_d = d
print(max_d)
Problem: p03061
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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))

Failing test case input:
3
114 36 12

Expected output:
12


Actual output:

Fixed submission (verdict: Accepted):
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))

Problem: p03061
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

left_gcd = [0] + [0] * n + [-1]
right_gcd = [-1] + [0] * n + [0]

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

ans = 1
for i in range(1, n):
    ans = max(ans, gcd(left_gcd[i-1], right_gcd[i+1]))
print(ans)


Failing test case input:
2
0110101100 0110101001

Expected output:
110101100


Actual output:
110101001


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

left_gcd = [0] + [0] * n + [-1]
right_gcd = [-1] + [0] * n + [0]

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

ans = 1
for i in range(1, n+1):
    ans = max(ans, gcd(left_gcd[i-1], right_gcd[i+1]))
print(ans)
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input()) 
def gcd(m, n):
  a = max(m,n)
  b = min(m,n)
  if a%b==0:
    return b
  while not a % b == 0:
      a, b = b, a % b
  return b

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


Failing test case input:
2
1010110100 1110100111

Expected output:
1110100111


Actual output:
[1010110100, 1] [1110100111, 1]
1110100111


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

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

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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]))
  r.append(gcd(r[i],a[n-1-i]))
  
  
for j in range(0,n):
  g.append(gcd(l[i+1],r[n-i-1]))

print(max(g))    
  
  


Failing test case input:
2
1000010111 0101001100

Expected output:
1000010111


Actual output:
101001100


Fixed submission (verdict: Accepted):
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))

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
gcd1 = [0] * (N - 1)
gcd1[0] = A[0]
gcd2 = [0] * (N - 1)
gcd2[-1] = A[-1]
for i in range(N - 2):
    a, b = gcd1[i], A[i + 1]
    while b:
        a, b = b, a % b
    gcd1[i + 1] = a
    a, b = gcd2[-i-1], A[-i-2]
    while b:
        a, b = b, a % b
    gcd1[-i-2] = a
ans = max(gcd1[-1], gcd2[0])
for i in range(N - 2):
    a, b = gcd1[i], gcd2[i + 1]
    while b:
        a, b = b, a % b
    ans = max(a, ans)
print(ans)

Failing test case input:
3
12 29 18

Expected output:
6


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
gcd1 = [0] * (N - 1)
gcd1[0] = A[0]
gcd2 = [0] * (N - 1)
gcd2[-1] = A[-1]
for i in range(N - 2):
    a, b = gcd1[i], A[i + 1]
    while b:
        a, b = b, a % b
    gcd1[i + 1] = a
    a, b = gcd2[-i-1], A[-i-2]
    while b:
        a, b = b, a % b
    gcd2[-i-2] = a
ans = max(gcd1[-1], gcd2[0])
for i in range(N - 2):
    a, b = gcd1[i], gcd2[i + 1]
    while b:
        a, b = b, a % b
    ans = max(a, ans)
print(ans)
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a_ls = [int(i) for i in input().split()]

def gcd(ls):
    while True:
        _min = min(ls)
        ls = [i % _min for i in ls if i % _min != 0]
        if len(ls) == 0:
            return _min

if __name__ == "__main__":
    res = 1
    for i in range(N):
        if i == 0:
            res = max(res, gcd(a_ls[1:]))
        elif i == N - 1:
            res = max(res, gcd(a_ls[:-1]))
        else:
            res = max(res, gcd(a_ls[:i] + a_ls[i+1:]))
    print(res)

Failing test case input:
3
53 36 11

Expected output:
1


Actual output:
17


Fixed submission (verdict: Accepted):
import math
N = int(input())
a_ls = [int(i) for i in input().split()]


def gcd(ls):
    ls = [i for i in ls if i > 0]
    while True:
        _min = min(ls)
        ls = [i % _min for i in ls if i % _min != 0]
        if len(ls) == 0:
            return _min
        ls.append(_min)

l_ls = [0]
r_ls = [0]
for i in range(N):
    l_ls.append(gcd([l_ls[i], a_ls[i]]))
    r_ls.append(gcd([r_ls[i], a_ls[-i-1]]))
r_ls = r_ls[::-1]
sum_ls = [gcd([l_ls[i], r_ls[i+1]]) for i in range(N)]
print(max(sum_ls))

Problem: p03061
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))

left = [A[0]] * N
right = [A[-1]] * N

import math

for i in range(1, N):
  left[i] = math.gcd(left[i - 1], A[i])
  
for i in range(N - 2,-1,-1):
  right[i] = math.gcd(right[i + 1], A[i])
  
ans = max(right[N - 2],left[1])
for i in range(1,N - 1):
  g = math.gcd(left[i - 1],right[i + 1])
  if ans < g:
    ans = g
print(ans)

Failing test case input:
2
1011101011 1101101101

Expected output:
1101101101


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))

left = [A[0]] * N
right = [A[-1]] * N

import math

for i in range(1, N):
  left[i] = math.gcd(left[i - 1], A[i])
  
for i in range(N - 2,-1,-1):
  right[i] = math.gcd(right[i + 1], A[i])
  
ans = 0
for i in range(N):
  if i == 0:
    if ans < right[1]:
      ans = right[1]
  elif i == N - 1:
    if ans < left[-2]:
      ans = left[-2]
  else:
    g = math.gcd(left[i - 1],right[i + 1])
    if ans < g:
      ans = g
print(ans)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))

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

res = set()
for i in range(N):
  for j in range(i+1, N):
    res.add(gcd(A[i], A[j]))
print(max(res))

Failing test case input:
2
0001011001 1101101111

Expected output:
1101101111


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))

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

L = [0]
R = [0]
for i in range(N):
  L.append(gcd(L[i], A[i]))
  R.append(gcd(R[i], A[-(i+1)]))
R = R[::-1]
ans = 0
for i in range(N):
  ans = max(ans, gcd(L[i], R[i+1]))
print(ans)
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

from sys import stdin




s_in = lambda: stdin.readline()[:-1]  
d_in = lambda: int(stdin.readline())  
ds_in = lambda: list(map(int, stdin.readline().split()))  


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


N = d_in()
A_list = ds_in()

cum_gcd = [A_list[0]]
for a in A_list[1:]:
    pre = cum_gcd[-1]
    cum_gcd.append(gcd(a, pre))

reverse = [A_list[-1]]
for a in A_list[-2::-1]:
    pre = reverse[-1]
    reverse.append(gcd(a, pre))

ans = max(reverse[1], cum_gcd[-2])
for i in range(1, N-1):
    
    ans = max(ans, gcd(cum_gcd[i-1], reverse[N-2-i]))

print(ans)


Failing test case input:
2
0010110100 1110100011

Expected output:
1110100011


Actual output:
10110100


Fixed submission (verdict: Accepted):

from sys import stdin




s_in = lambda: stdin.readline()[:-1]  
d_in = lambda: int(stdin.readline())  
ds_in = lambda: list(map(int, stdin.readline().split()))  


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


N = d_in()
A_list = ds_in()

cum_gcd = [A_list[0]]
for a in A_list[1:]:
    pre = cum_gcd[-1]
    cum_gcd.append(gcd(a, pre))

reverse = [A_list[-1]]
for a in A_list[-2::-1]:
    pre = reverse[-1]
    reverse.append(gcd(a, pre))

ans = max(reverse[-2], cum_gcd[-2])
for i in range(1, N-1):
    
    ans = max(ans, gcd(cum_gcd[i-1], reverse[N-2-i]))

print(ans)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))


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


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

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

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


print(m())


Failing test case input:
2
1011000100 0111000101

Expected output:
1011000100


Actual output:
111000101


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))


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


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

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

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


print(m())
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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

N=int(input())
A=list(map(int,input().split()))
org_A=A[:]

A=A[::-1]
l=[A.pop(-1)]
while A:
    l.append(euclid(l[-1],A.pop(-1)))

A=org_A
r=[A.pop(-1)]
while A:
    r.append(euclid(r[-1],A.pop(-1)))
r=r[::-1]

ans=0
for i in range(N-1):
    temp=euclid(l[i-1] if i!=0 else r[i+1],r[i+1] if i!=N-1 else l[i-1])
    ans=max(ans,temp)

print(ans)


Failing test case input:
2
1010000111 0110001101

Expected output:
1010000111


Actual output:
110001101


Fixed submission (verdict: Accepted):


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

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

org_A=A[:]

A=A[::-1]
l=[A.pop(-1)]
while A:
    l.append(euclid(l[-1],A.pop(-1)))

A=org_A
r=[A.pop(-1)]
while A:
    r.append(euclid(r[-1],A.pop(-1)))
r=r[::-1]

ans=0

for i in range(N):
    temp=euclid(l[i-1] if i!=0 else r[i+1],r[i+1] if i!=N-1 else l[i-1])
    
    ans=max(ans,temp)

print(ans)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[int(i) for i in input().split()]
a.sort()

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

check=a[0]
for i in range(2,n):
    check=gcd(check,a[i])

check2=a[1]
for i in range(2,n):
    check2=gcd(check2,a[i])

if n==2:
    print(max(a))
else:
    print(max(check,check2))


Failing test case input:
3
4 2 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n=int(input())
a=[int(i) for i in input().split()]

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

left=[0]*n
right=[0]*n

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

ans=0
for i,j in zip(left,right):
    ans=max(ans,gcd(i,j))
print(ans)

Problem: p03061
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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

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

Right = [A[N-1]]
for i in range(N-1):
    Right.append(gcd(Right[i], A[N-2-i]))
Right.reverse()

ans_list = []
ans_list.append(Right[1])
for i in range(1, N-1):
    ans_list.append(gcd(Left[i-1], Right[i+1]))
ans_list.append(Left[N-1])

print(max(ans_list))

Failing test case input:
2
1001101001 0101101111

Expected output:
1001101001


Actual output:
101101111


Fixed submission (verdict: Accepted):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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

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

Right = [A[N-1]]
for i in range(N-1):
    Right.append(gcd(Right[i], A[N-2-i]))
Right.reverse()

ans_list = []
ans_list.append(Right[1])
for i in range(1, N-1):
    ans_list.append(gcd(Left[i-1], Right[i+1]))
ans_list.append(Left[N-2])

print(max(ans_list))
Problem: p03061
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

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

n = int(input())
a = list(map(int,input().split()))
l = [0]
r = [0]
for i in range(n):
    l.append(gcd(a[i],l[-1]))
    r.append(gcd(a[(n-1)-i],r[-1]))
r = r[::-1]
ans = r[0]
for i in range(n-1):
    ans = max(ans,gcd(l[i],r[i+1]))
print(ans)

Failing test case input:
2
0011011001 0001101010

Expected output:
11011001


Actual output:
1101010


Fixed submission (verdict: Accepted):
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

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

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

Problem: p03061
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from math import gcd
n = int(input())
l = list(map(int,input().split()))
mi = 1
gcd_l = [l[0]]
gcd_r = [l[-1]]
for i in range(1,n):
  gcd_l.append(gcd(l[i],gcd_l[-1]))
for i in range(n-2,-1,-1):
  gcd_r.append(gcd(l[i],gcd_r[-1]))
for i in range(0,n-3):
  t = gcd(gcd_l[i], gcd_r[i+2])
  mi = max(mi,t)
mi = max(mi,gcd_r[-2])
mi = max(mi,gcd_l[-2])
print(mi)

Failing test case input:
3
9 28 18

Expected output:
9


Actual output:
2


Fixed submission (verdict: Accepted):
from math import gcd
n = int(input())
l = list(map(int,input().split()))
mi = 1
gcd_l = [l[0]]
gcd_r = [l[-1]]
for i in range(1,n):
  gcd_l.append(gcd(l[i],gcd_l[-1]))
for i in range(n-2,-1,-1):
  gcd_r.append(gcd(l[i],gcd_r[-1]))
  
for i in range(0,n-2):
  t = gcd(gcd_l[i], gcd_r[n-3-i])
 
  mi = max(mi,t)


mi = max(mi,gcd_r[-2])
mi = max(mi,gcd_l[-2])
print(mi)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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

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








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

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

mx = 0
for i in range(N):
    if i == 0:
        v = R[1]
    elif i == N-1:
        v = L[N-1]
    else:
        v = R[i+1] + L[i-1]
    mx = max(v, mx)
print(mx)

Failing test case input:
2
1110101001 1101101111

Expected output:
1110101001


Actual output:
1101101111


Fixed submission (verdict: Accepted):


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

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








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

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

mx = 0
for i in range(N):
    if i == N-1:
        v = L[N-2]
    elif i == 0:
        v = R[1]
    else:
        v = gcd(R[i+1], L[i-1])
    mx = max(v, mx)
print(mx)
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
def divi(a, b):
    rem = b % a
    if rem == 0:
        return a
    else:
        return divi(rem, a)
A.sort()
all_d = A[0]
max_d = max(divi(A[0],A[1]), divi(A[0],A[2])) if N > 2 else A[1]
for i in range(1,N):
    all_d = divi(all_d, A[i])
    if max_d < all_d:
        max_d = all_d
print(max_d)

Failing test case input:
3
7 6 7

Expected output:
7


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
def divi(a, b):
    rem = b % a
    if rem == 0:
        return a
    else:
        return divi(rem, a)
A.sort()
all_d = divi(A[0], A[1])
max_d = max(all_d, max(divi(A[1],A[2]), divi(A[0],A[2]))) if N > 2 else A[1]
for i in range(2,N):
    d = divi(all_d, A[i])
    max_d = divi(max_d, A[i])
    if max_d < all_d:
        max_d = all_d
    all_d = d
print(max_d)

Problem: p03061
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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])


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


Failing test case input:
2
0010101100 0110101001

Expected output:
110101001


Actual output:
[1, 110101001]
[10101100, 1]
[110101001, 1]
110101001


Fixed submission (verdict: Accepted):
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()



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


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


print(max(m))
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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 


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


Failing test case input:
2
0001111001 1011000101

Expected output:
1011000101


Actual output:
0


Fixed submission (verdict: Accepted):
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 


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

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



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

N=int(input())
A=list(map(int,input().split()))
org_A=A[:]

temp=10**9
index=0
for i in range(N-1):
    A[i+1]=euclid(A[i],A[i+1])
    if A[i+1]<temp:
        index=i

X=org_A[:]
X.pop(index-1)
for i in range(N-2):
    X[i+1]=euclid(X[i],X[i+1])

Y=org_A[:]
Y.pop(index)
for i in range(N-2):
    Y[i+1]=euclid(Y[i],Y[i+1])

print(max(min(X),min(Y)))


Failing test case input:
3
36 36 10

Expected output:
36


Actual output:
2


Fixed submission (verdict: Accepted):


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

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

org_A=A[:]

A=A[::-1]
l=[A.pop(-1)]
while A:
    l.append(euclid(l[-1],A.pop(-1)))

A=org_A
r=[A.pop(-1)]
while A:
    r.append(euclid(r[-1],A.pop(-1)))
r=r[::-1]

ans=0

for i in range(N):
    temp=euclid(l[i-1] if i!=0 else r[i+1],r[i+1] if i!=N-1 else l[i-1])
    
    ans=max(ans,temp)

print(ans)
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)


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

g_left = [a[0]]
g_right = [a[-1]]

for i in range(N):
    g_left.append(gcd(g_left[-1], a[i]))

for i in range(N - 1, -1, -1):
    g_right.append(gcd(g_right[-1], a[i]))

g_right.reverse()





g_left = g_left[1:]
g_right = g_right[:-1]

g = 1


for i in range(1, N-1):
    g = max(g, gcd(g_left[i-1], g_right[i+1]))
g = max(g, g_left[N - 1])
g = max(g, g_right[1])

print(g)


Failing test case input:
3
4 2 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)


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

g_left = []
g_right = []

t = a[0]
for i in range(N):
    t = gcd(t, a[i])
    g_left.append(t)

t = a[-1]
for i in range(N - 1, -1, -1):
    t = gcd(t, a[i])
    g_right.append(t)

g_right.reverse()

g = 1
for i in range(1, N - 1):
    g = max(g, gcd(g_left[i - 1], g_right[i + 1]))
g = max(g, g_left[N - 2])
g = max(g, g_right[1])

print(g)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

inf = int(2e9)

m = inf
check = 0
for i in range(N):
    check1 = gcd(A[0], A[i])
    if check1 < m:
        m = check1
        check = i


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

ans = check2


if check != 0:
    check3 = A[0]
    for i in range(N):
        if i == check:
            continue
        check3 = gcd(check3, A[i])
    ans = max(check2, check3)

print(ans)

Failing test case input:
2
0010110100 1111100011

Expected output:
1111100011


Actual output:
10110100


Fixed submission (verdict: Accepted):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

A.sort()

inf = int(2e9)

m = inf
check = 0
for i in range(N):
    check1 = gcd(A[0], A[i])
    if check1 < m:
        m = check1
        check = i


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

ans = check2


if check != 0:
    check3 = A[0]
    for i in range(N):
        if i == check:
            continue
        check3 = gcd(check3, A[i])
    ans = max(check2, check3)

print(ans)
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



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

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

log=10**9
place=0
for i in range(N-1):
    temp=euclid(A[i],A[i+1])
    log=min(log,temp)
    if log==temp:
        place=i

A.pop(place)
log=A[0]
for i in range(N-2):
    temp=euclid(A[i],A[i+1])
    log=min(log,temp)

print(log)

Failing test case input:
2
1001101001 0101101111

Expected output:
1001101001


Actual output:
101101111


Fixed submission (verdict: Accepted):


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

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

org_A=A[:]

A=A[::-1]
l=[A.pop(-1)]
while A:
    l.append(euclid(l[-1],A.pop(-1)))

A=org_A
r=[A.pop(-1)]
while A:
    r.append(euclid(r[-1],A.pop(-1)))
r=r[::-1]

ans=0

for i in range(N):
    temp=euclid(l[i-1] if i!=0 else r[i+1],r[i+1] if i!=N-1 else l[i-1])
    
    ans=max(ans,temp)

print(ans)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split(" ")))

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

l = [0]*N
r = [0]*N

l[0] = A[0]
r[-1] = A[-1]

for x in range(1,N):
    l[x] = gcd(A[x],l[x-1])

for x in range(N-2,-1,-1):
    r[x] = gcd(A[x],r[x+1])

l.insert(0,0)
l.append(0)
r.insert(0,0)
r.append(0)

o = []

for x in range(N):
    o.append(gcd(l[x-1],r[x+1]))

print(max(o))

Failing test case input:
2
1111000110 0011000101

Expected output:
1111000110


Actual output:
11000101


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split(" ")))

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

l = [0]*N
r = [0]*N

l[0] = A[0]
r[-1] = A[-1]

for x in range(1,N):
    y = N - 1 - x
    l[x] = gcd(A[x],l[x-1])
    r[y] = gcd(A[y],r[y+1])

l.insert(0,0)
l.append(0)
r.insert(0,0)
r.append(0)

o = 1

for x in range(N):
    o = max(o,gcd(l[x],r[x+2]))

print(o)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
2
0001011001 1001101111

Expected output:
1001101111


Actual output:
1


Fixed submission (verdict: Accepted):
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))
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))

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

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

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

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

Failing test case input:
2
1001101000 0110101101

Expected output:
1001101000


Actual output:
110101101


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))

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

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

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a,b):
    if a <= b:
        a,b = b,a
    if b == 0:
        return a
    if a%b == 0:
        return b
    else:
        return gcd(b,a%b)

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

L_gcd = [0]*(N)
R_gcd = [0]*(N)

for i in range(N):
    L_gcd[i] = gcd(L_gcd[i-1],A[i])
for i in reversed(range(N)):   
    R_gcd[i] = gcd(R_gcd[i-1],A[i])

ans = max(L_gcd[-1],R_gcd[0])
for i in range(N):
    if gcd(L_gcd[i],R_gcd[N-i-1])>ans:
        ans = gcd(L_gcd[i],R_gcd[N-i-1])
print(ans)

Failing test case input:
2
0110101100 0110101001

Expected output:
110101100


Actual output:
1


Fixed submission (verdict: Accepted):
def gcd(a,b):
    if a <= b:
        a,b = b,a
    if b == 0:
        return a
    if a%b == 0:
        return b
    else:
        return gcd(b,a%b)

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

L_gcd = [0]*(N+1)
R_gcd = [0]*(N+1)

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

ans = 0
for i in range(N):
    if gcd(L_gcd[i],R_gcd[i+1])>ans:
        ans = gcd(L_gcd[i],R_gcd[i+1])
    
print(ans)
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
arr = list(map(int,input().split()))
left = []
l = arr[0]
right = []
r = arr[-1]
ans = 0
left = [0 for _ in range(n)]
right =  [0 for _ in range(n)]


def gcd(x, y):
    while (y):
        x, y = y, x % y
    return x
for i in range(n-1):
    l = gcd(l,arr[i])
    left[i]= l
    r = gcd(r,arr[-(i+1)])
    right[-(i+1)] = r
for i in range(n-1):
    if i-1 <0:
        a = arr[-1]
    else:
        a = left[i-1]
    if i+1>n-1:
        b = arr[0]
    else:
        b = right[i+1]
    ans = max(gcd(a,b),ans)


if n == 2:
    print(gcd(arr[0],arr[1]))
else:
    print(ans)


Failing test case input:
2
1000000111 0111001101

Expected output:
1000000111


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
arr = list(map(int,input().split()))
left = []
l = arr[0]
right = []
r = arr[-1]
ans = 0
left = [0 for _ in range(n)]
right =  [0 for _ in range(n)]

def gcd(x, y):
    while (y):
        x, y = y, x % y
    return x
for i in range(n):
    l = gcd(l,arr[i])
    left[i]= l
    r = gcd(r,arr[-(i+1)])
    right[-(i+1)] = r
for i in range(n):
    if i-1 <0:
        a = arr[-1]
    else:
        a = left[i-1]
    if i+1>n-1:
        b = arr[0]
    else:
        b = right[i+1]
    
    ans = max(gcd(a,b),ans)


if n == 2:
    print(max(arr))
else:
    print(ans)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [x for x in map(int,input().split(" "))]

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

l = [x for x in range(N)]
r = [x for x in range(N)]

l[0] = A[0]
r[-1] = A[-1]

for x in range(1,N):
    l[x] = gcd(A[x],l[x-1])

for x in range(N-2,-1,-1):
    r[x] = gcd(A[x],r[x+1])

l.insert(0,0)
l.append(0)
r.insert(0,0)
r.append(0)

o = []

for x in range(N):
    o.append(gcd(l[x-1],r[x+1]))

print(max(o))

Failing test case input:
2
1001000111 0111001101

Expected output:
1001000111


Actual output:
111001101


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split(" ")))

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

l = [0]*N
r = [0]*N

l[0] = A[0]
r[-1] = A[-1]

for x in range(1,N):
    y = N - 1 - x
    l[x] = gcd(A[x],l[x-1])
    r[y] = gcd(A[y],r[y+1])

l.insert(0,0)
l.append(0)
r.insert(0,0)
r.append(0)

o = 1

for x in range(N):
    o = max(o,gcd(l[x],r[x+2]))

print(o)
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))


Failing test case input:
2
1101101000 0110101101

Expected output:
1101101000


Actual output:
1101101000
0


Fixed submission (verdict: Accepted):
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 = [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))

Problem: p03061
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))
A=[0]+A
import math

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

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

Failing test case input:
2
1111101100 1100101000

Expected output:
1111101100


Actual output:
1100101000


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int,input().split()))
A=[0]+A
import math

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

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

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a: int, b: int) -> int:
    return gcd(b % a, a) if a != 0 else b


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

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

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

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

print(ret)


Failing test case input:
2
0110101100 0110101001

Expected output:
110101100


Actual output:
110101001


Fixed submission (verdict: Accepted):
def gcd(a: int, b: int) -> int:
    return gcd(b % a, a) if a != 0 else b


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

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

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

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

print(ret)
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from functools import reduce


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


N = int(input())
a_list = list(map(int, input().split()))
gcd_list = []
for idx in range(1, N):
    gcd_list.append(reduce(gcd, a_list[1:idx], a_list[idx]))
max_gcd_a = gcd_list[-1]
gcd_list.append(a_list[-1])

for idx in range(1, N):
    if idx != 1:
        left_gcd = gcd(left_gcd, a_list[idx])
    else:
        left_gcd = a_list[0]
    right_gcd = gcd_list[idx]

    gcd_a = gcd(left_gcd, right_gcd)
    if max_gcd_a < gcd_a:
        max_gcd_a = gcd_a

print(max_gcd_a)




Failing test case input:
2
1111001110 0011000101

Expected output:
1111001110


Actual output:
11000101


Fixed submission (verdict: Accepted):
from functools import reduce


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


N = int(input())
a_list = list(map(int, input().split()))
gcd_list = [a_list[-1]]
for idx in range(N - 2, 0, -1):
    gcd_list.append(gcd(gcd_list[N - 2 - idx], a_list[idx]))
max_gcd_a = gcd_list[-1]
gcd_list.append(1)
gcd_list.reverse()

for idx in range(1, N):
    if idx != 1:
        left_gcd = gcd(left_gcd, a_list[idx - 1])
    else:
        left_gcd = a_list[0]
    if idx < N - 1:
        right_gcd = gcd_list[idx + 1]
    else:
        right_gcd = left_gcd

    gcd_a = gcd(left_gcd, right_gcd)
    if max_gcd_a < gcd_a:
        max_gcd_a = gcd_a

print(max_gcd_a)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_reverse = list(reversed(A))
    left = [0]
    right = [0]
    answer = []
    for n in range(N-1):
        left.append(gcd(left[n], A[n]))
        right.append(gcd(right[n], A_reverse[n]))
    right.reverse()
    for n in range(N-1):
        answer.append(gcd(left[n], right[n]))
    print(max(answer))


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


if __name__ == "__main__":
    main()


Failing test case input:
2
1111001110 0011000101

Expected output:
1111001110


Actual output:
11000101


Fixed submission (verdict: Accepted):

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_reverse = list(reversed(A))
    left = [0]
    right = [0]
    answer = []
    for n in range(N):
        left.append(gcd(left[n], A[n]))
        right.append(gcd(right[n], A_reverse[n]))
    del left[N]
    del right[N]
    right.reverse()
    for n in range(N):
        answer.append(gcd(left[n], right[n]))
    print(max(answer))


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


if __name__ == "__main__":
    main()
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

A.sort()
inf = int(2e9)

m = inf
check = 0
for i in range(N):
    check1 = gcd(A[0], A[i])
    if check1 < m:
        m = check1
        check = i


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

ans = check2


if check != 0:
    check3 = A[0]
    for i in range(N):
        if i == check:
            continue
        check3 = gcd(check3, A[i])
    ans = max(check2, check3)

print(ans)

Failing test case input:
2
0001011001 1001101111

Expected output:
1001101111


Actual output:
1011001


Fixed submission (verdict: Accepted):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

A.sort()

inf = int(2e9)

m = inf
check = 0
for i in range(N):
    check1 = gcd(A[0], A[i])
    if check1 < m:
        m = check1
        check = i


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

ans = check2


if check != 0:
    check3 = A[0]
    for i in range(N):
        if i == check:
            continue
        check3 = gcd(check3, A[i])
    ans = max(check2, check3)

print(ans)

Problem: p03061
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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 = []

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

if n == 2:
  print(math.gcd(a[1], a[0]))
else:
  print(max(gcd))

Failing test case input:
2
0111101101 1100101000

Expected output:
1100101000


Actual output:
1


Fixed submission (verdict: Accepted):
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[n-2])

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