ZhenlongDai/ACPR huggingface dataset:
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 = gcd(R[i+1], L[i-1])
    mx = max(v, mx)
print(mx)

Failing test case input:
2
1111101100 1100101000

Expected output:
1111101100


Actual output:
1100101000


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


Failing test case input:
2
1110001110 1011000101

Expected output:
1110001110


Actual output:
1110001110
1110001110


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):
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 = 0
for i in range(n-1):
    ans = max(ans,gcd(l[i],r[i+1]))
print(ans)

Failing test case input:
2
1111101000 1100000100

Expected output:
1111101000


Actual output:
1100000100


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


def gcd(a,b):
  x = max([a,b])
  y = min([a,b])
  while y:
    x, y = y, x % y
  return x

L = [0]
R = [0]

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

R = list(reversed(R))


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

ans = max(ans, R[1])

print(ans)

Failing test case input:
2
0111001101 0001101010

Expected output:
111001101


Actual output:
1101010


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


def gcd(a,b):
  x = max([a,b])
  y = min([a,b])
  while y:
    x, y = y, x % y
  return x

L = [0]
R = [0]

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

R = list(reversed(R))


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

ans = max(ans, R[1])
ans = max(ans, L[-2])

print(ans)

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


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


Failing test case input:
2
0000101100 0011100010

Expected output:
11100010


Actual output:
11100010
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):
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-1):
  t = gcd(gcd_l[i], gcd_r[i])
  mi = max(mi,t)


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

Failing test case input:
2
0000010111 0101001100

Expected output:
101001100


Actual output:
10111


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


N = int(input())
A = list(map(int, input().split()))
AF = [1] * (N - 1)
AB = [1] * (N - 1)

AF[0] = A[0]
AB[0] = A[-1]
if N == 2:
    print(max(A))
else:
    for i in range(1, N - 1):
        AF[i] = m(A[i - 1], A[i])
        AB[i] = m(A[i - 1], A[- (i + 1)])

    L = max(AF[-1], AB[-1], max([m(AF[i], AB[N - 3 - i]) for i in range(N - 2)]))

    print(L)

Failing test case input:
3
114 36 12

Expected output:
12


Actual output:
6


Fixed submission (verdict: Accepted):
def m(a, b):
    if a > b:
        a, b = b, a
    while b % a:
        a, b = b % a, a
    return a


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

if N == 2:
    print(max(A))
else:
    AF = [1] * (N - 1)
    AB = [1] * (N - 1)

    AF[0] = A[0]
    AB[0] = A[-1]

    for i in range(1, N - 1):
        AF[i] = m(AF[i - 1], A[i])
        AB[i] = m(AB[i - 1], A[- (i + 1)])
    L = max(AF[-1], AB[-1], max([m(AF[i], AB[N - 3 - i]) for i in range(N - 2)]))

    print(L)

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(n,m):
  a=max(n,m)
  b=min(n,m)
  while b!=0:
    a,b=b,a%b
  return a
n=int(input())
l=list(map(int,input().split()))
l1=[]
l1.append(l[0])
for i in range(1,n):
  l1.append(gcd(l1[-1],l[i]))
l2=[]
l2.append(l[-1])
for i in range(n-2,-1,-1):
  l2.append(gcd(l2[-1],l[i]))
l3=[]
for i in range(2,n-1):
  l3.append(gcd(l1[i-2],l2[-(i+1)]))
l3.append(l2[-n+1])
l3.append(l1[n-2])
print(max(l3))
            
                



Failing test case input:
3
9 28 18

Expected output:
9


Actual output:
2


Fixed submission (verdict: Accepted):
def gcd(n,m):
  a=max(n,m)
  b=min(n,m)
  while b!=0:
    a,b=b,a%b
  return a
n=int(input())
l=list(map(int,input().split()))
l1=[]
l1.append(l[0])
for i in range(1,n):
  l1.append(gcd(l1[-1],l[i]))
l2=[]
l2.append(l[-1])
for i in range(n-2,-1,-1):
  l2.append(gcd(l2[-1],l[i]))
l3=[]
for i in range(2,n):
  l3.append(gcd(l1[i-2],l2[n-i-1]))
l3.append(l2[n-2])
l3.append(l1[n-2])
print(max(l3))
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
    m = a % b
    while m != 0:
        a = b
        b = m
        m = a % b
    return b

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

if N < 2 and 1e5 < N: raise()
for v in A:
    if v < 1 and v < 1e9: raise()

result = []
l = 0
for skip in range(1, N+1):
    l = GCD(l, A[skip-1])
    r = 0
    for i in range(skip+1, N):
        r = GCD(r, A[i])
    n = GCD(l, r)

    result.append(n)
print(max(result))

Failing test case input:
2
0010110100 1111100011

Expected output:
1111100011


Actual output:
10110100


Fixed submission (verdict: Accepted):
def GCD(a, b):
    
    if a < b: (a, b) = (b, a)
    if b == 0: return a
    m = a % b
    while m != 0:
        a = b
        b = m
        m = a % b
    return b

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

if N < 2 and 1e5 < N: raise()
for v in A:
    if v < 1 and v < 1e9: raise()


l_list = []
l = 0
for i in range(0, N):
    l = GCD(l, A[i])
    l_list.append( l )

r_list = []
r = 0
for i in range(-1, -(N+1), -1):
    r = GCD(r, A[i])
    r_list.append( r )

n = []    
for i in range(0, N):
    if i-1 < 0:
        l = 0
    else:
        l = l_list[i-1]
    if N-i-2 < 0:
        r = 0
    else:
        r = r_list[N-i-2]
    n.append(GCD(l, r))
print(max(n))

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(a):
    b = sorted(a)
    c = []
    t=0
    for i in range(len(b)):
        if b[i]%b[0]==0:
            t += 1
        else:
            c.append(b[i]%b[0])
    if len(c)==0:
        return b[0]
    else:
        return gcd(c)
n = int(input())
a = list(map(int,input().split()))
e = [0 for i in range(n)]
for i in range(n):
    e[i] = gcd(a[:i]+a[i+1:])
print(max(e))


Failing test case input:
3
9 28 18

Expected output:
9


Actual output:
10


Fixed submission (verdict: Accepted):
def gcd(a,b):
    if b==0:
        return max(a,b)
    else:
        if a%b == 0:
            return(b)
        else:
            return gcd(b,a%b)
n = int(input())
a = list(map(int,input().split()))
l=[0 for i in range(n)]
r=[0 for i in range(n)]
e=[0 for i in range(n)]
for i in range(1,n):
    l[i]=gcd(l[i-1],a[i-1])
    r[i]=gcd(r[i-1],a[n-i])
for i in range(n):
    e[i] = gcd(l[i],r[n-1-i])
print(max(e))
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]
R_gcd = [0]

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

ans = [max(L_gcd[-2],R_gcd[1])]
for i in range(N-2):
    ans.append(gcd(L_gcd[i],R_gcd[i+2]))
print(max(ans))

Failing test case input:
2
1001101001 0101101111

Expected output:
1001101001


Actual output:
0


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.8.2), verdict: Wrong Answer):
n = int(input())
data = list(map(int, input().split()))

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

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

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

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

print( left_ )
print( right_ )

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

print( max(ans) )


Failing test case input:
2
0001111001 1011000101

Expected output:
1011000101


Actual output:
[1111001, 1, 0]
[0, 1011000101, 0]
1011000101


Fixed submission (verdict: Accepted):
n = int(input())
data = list(map(int, input().split()))

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

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

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

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

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

print( max(ans) )
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
    return gcd(b, a % b)


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


if __name__ == "__main__":
    main()


Failing test case input:
3
53 36 11

Expected output:
1


Actual output:
53


Fixed submission (verdict: Accepted):



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


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


if __name__ == "__main__":
    main()

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
    c = a % b
    return gcd(b, c)
n = int(input())
a = list(map(int,input().split()))
li = []
li2 = []
for i in range(n-1):
    li.append(gcd(a[i],a[i+1]))
for i in range(n-2):
    li2.append(gcd(a[i],a[i+2]))
li = set(li)  | set(li2)
ans = max(li)
print(ans)

Failing test case input:
2
1001101000 0110101101

Expected output:
1001101000


Actual output:
1


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

n = int(input())
a = list(map(int, input().split()))
rs, ls = [0], [0]
for i in range(n-1):
    rs.append(gcd(rs[i], a[i]))
    ls.append(gcd(ls[i], a[-i-1]))
gcd_list = [gcd(r,l) for r, l in zip(rs, ls[::-1])]
print(max(gcd_list))
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(x, y):
    while y!=0:
        x, y = y, x % y 
    return x

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

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


l = [-1] * n
r = [-1] * n
l[0] = a[0]  
r[-1] = a[-1] 



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




ans = max(r[1], l[-2]) 


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

Failing test case input:
2
1101101000 0110101101

Expected output:
1101101000


Actual output:
1101101000
1101101000


Fixed submission (verdict: Accepted):
def gcd(x, y):
    while y!=0:
        x, y = y, x % y 
    return x

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

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

elif n>=3:
    l = [-1] * n
    r = [-1] * n
    l[0] = a[0]  
    r[-1] = a[-1] 



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

        
        

    ans = max(r[1], l[-2]) 
        

    for i in range(1, n-1): 
        g = gcd(l[i-1], r[i+1]) 
        ans = max(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 != 0:
    m, n = n, m % n
  return m
gl = [A[0]]
gr = [A[N-1]]
x, y = A[0], A[N-1]
for i in range(1, N):
  x = gcd(x, A[i])
  gl.append(x)
  y = gcd(y, A[N-i-1])
  gr.append(y)
gg = [gr[N-2]]
for i in range(1, N):
  gg.append(gcd(gl[i-1], gr[N-i-2]))
print(max(gg))

Failing test case input:
2
1110001110 1011000101

Expected output:
1110001110


Actual output:
1011000101


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
def gcd(m, n):
  while n != 0:
    m, n = n, m % n
  return m
gl = [A[0]]
gr = [A[N-1]]
x, y = A[0], A[N-1]
for i in range(1, N):
  x = gcd(x, A[i])
  gl.append(x)
  y = gcd(y, A[N-i-1])
  gr.append(y)
gg = [gr[N-2]]
for i in range(1, N-1):
  gg.append(gcd(gl[i-1], gr[N-i-2]))
gg.append(gl[N-2])
if N != 2:
  print(max(gg))
else:
  print(max(A[0], A[1]))

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

for i in range(min(A),1,-1):
    c = 0

    for j in A:
        if j % i != 0:
            c = c + 1
            if c >= 2:
                break
    else:
        print(i)
        break


Failing test case input:
2
0101101100 0110101101

Expected output:
110101101


Actual output:
101101100


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

w_min = A[1]

for i in range(w_min,0,-1):
    count = 0
    for j in A:
        if j%i != 0:
            count = count + 1
            if count > 1:
                break
    if count < 2:
        print(i)
        break
Problem: p03061
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def larger(x, y):
	if x > y: return x
	return y

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

N = int(input())
A = list(map(int, input().split()))
left = [A[0]]
for i in range(1, N):
	left.append(euc(left[-1], A[i]))
right = [A[-1]]
for i in range(1, N):
	right.append(euc(right[-1], A[-1-i]))
right.reverse()

max = larger(left[N-2], right[N-2])
for i in range(1, N-1):
	max = larger(max, euc(left[i-1], right[i+1]))
print(max)

Failing test case input:
2
0010110100 1111100011

Expected output:
1111100011


Actual output:
10110100


Fixed submission (verdict: Accepted):
def larger(x, y):
	if x > y: return x
	return y

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

N = int(input())
A = list(map(int, input().split()))
left = [A[0]]
for i in range(1, N):
	left.append(euc(left[-1], A[i]))
right = [A[-1]]
for i in range(1, N):
	right.append(euc(right[-1], A[-1-i]))
right.reverse()

max = larger(left[N-2], right[1])
for i in range(1, N-1):
	max = larger(max, euc(left[i-1], right[i+1]))
print(max)

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

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

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

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

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

print(l)
print(r)

ans = 0
for i in range(n):
    lr = gcd(l[i], r[i])
    print (lr)
    ans = max(ans, lr)

print(ans)


Failing test case input:
3
7 6 8

Expected output:
2

Actual output:
[0, 7, 1]
[2, 8, 1]
2
1
1
2


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

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

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

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

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

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

print(ans)

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

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

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

z=[gcd(l[i-1],r[i]) for i in range(1,n)]

print(max(z))


Failing test case input:
2
1110100101 1101101101

Expected output:
1110100101


Actual output:
1101101101


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

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

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

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

print(max(z))
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys


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


def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A)

    if N == 2:
        return A[1]

    a0 = A[0]
    a1 = A[1]

    gcd0 = 10**5
    gcd1 = 10**5
    for i in range(2, N):
        a = A[i]
        gcd0 = min(gcd0, gcd(a0, a))
        gcd1 = min(gcd1, gcd(a1, a))

    return max(gcd0, gcd1)


if __name__ == '__main__':
    print(main())


Failing test case input:
3
4 2 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import sys


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


def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A)

    if N == 2:
        return A[1]

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

    g = A[0]
    B = []
    for a in A:
        g = gcd(a, g)
        B.append(g)

    i = B.index(g)
    A.pop(i)

    g = A[0]
    for a in A:
        g = gcd(g, a)

    return max(g, g0)


if __name__ == '__main__':
    print(main())

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

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

x = 0
for i in range(1, N-1):
    if gcd(x, A[i]) <= gcd(x, A[i+1]):
        y = i
    else:
        y = i + 1

    if gcd(A[i], A[i+1]) <= gcd(A[x], A[y]):
        x = y

w = A[1 if x == 0 else 0]
for i in range(N):
    if i != x:
        w = gcd(w, A[i])

print(w)


Failing test case input:
2
0011001101 0001101010

Expected output:
11001101


Actual output:
1101010


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

def gcd(x, y):
    if x == 0 or y == 0:
        return max(x, y)
    g = x % y
    if g == 0:
        return y
    return gcd(y, g)

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

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

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

print(w)
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 a<=b:
    a,b=b,a
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)
L,R=[],[]
ld,rd=A[0],A[n-1]
for i in range(n):
  ld=gcd(ld,A[i])
  rd=gcd(rd,A[n-1-i])
  L.append(ld)
  R.append(rd)
ans=max(L[-2],R[1])
for i in range(1,n-1):
  ans=max(ans,gcd(L[i-1],R[n-i-2]))
print(ans)

Failing test case input:
2
1011101100 1100111101

Expected output:
1100111101


Actual output:
1011101100


Fixed submission (verdict: Accepted):
n=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
  if a<=b:
    a,b=b,a
  if a%b==0:
    return b
  else:
    return gcd(b,a%b)
L,R=[],[]
ld,rd=A[0],A[n-1]
for i in range(n):
  ld=gcd(ld,A[i])
  rd=gcd(rd,A[n-1-i])
  L.append(ld)
  R.append(rd)
ans=max(L[-2],R[-2])
for i in range(1,n-1):
  ans=max(ans,gcd(L[i-1],R[n-i-2]))
print(ans if n!=2 else max(A))

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

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

  res = []
  k = max(A)
  ind = A.index(k)
  for i in range(N):
    if i != ind:
      res.append(gcd(A[i], k))
  print(max(res))

ans()

Failing test case input:
2
1011101011 1100101101

Expected output:
1100101101


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):
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
        if i == 0:
            check3 = A[0]
        else:
            check3 = gcd(check3, A[i])
    ans = max(check2, check3)

print(ans)

Failing test case input:
2
0000010111 0101001100

Expected output:
101001100


Actual output:
10111


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):
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 ==1:
    print(arr[0])
else:
    print(ans)


Failing test case input:
2
1101101000 0110101101

Expected output:
1101101000


Actual output:
110101101


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


def g():
  n = int(input())
  vs = list(map(int, input().split()))
  
  ss = 0
  tt = 0
  for i, v in enumerate(vs):
    if ss:
      s = gcd(ss, v)
      if tt > s:
        tt = s
      else:
        ss = s
    else:
      ss = v
      tt = v
      mi = i
  from functools import reduce
  r = reduce(gcd, vs[1:])
  return max(r, ss)
  
print(g())


Failing test case input:
3
4 2 5

Expected output:
2


Actual output:
4


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


def g():
  from functools import reduce
  n = int(input())
  vs = list(map(int, input().split()))
  
  while True:
    n = len(vs)
    
    if n < 10:
      mrr = 0
      for i, v in enumerate(vs):
        rr = reduce(gcd, vs[:i]+vs[i+1:])
        mrr = max(rr, mrr)
      return mrr
    
    v1 = vs[:n
    v2 = vs[n
    
    r1 = reduce(gcd, v1)
    r2 = reduce(gcd, v2)
    if r1 == r2:
      return r1
    if r1 > r2:
      vs = v2
    else:
      vs = v1
  
  
print(g())
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



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

def gcd(x, y):
    if x == 0:
        return y
    if y == 0:
        return x
        
    if y > x:
        temp = y
        y = x
        x = temp
    amari = x % y
    if amari == 0:
        return y
    else:
        return gcd(y, amari)
        
L = [0]
for i in range(N):
    l = L[-1]
    L.append(gcd(l, A[i]))
    
R = [0]
for i in reversed(range(N)):
    r = R[0]
    R.insert(0, gcd(r, A[i]))

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

print(L)
print(R)
print(M)

print(max(M))


Failing test case input:
2
1010110100 1110100111

Expected output:
1110100111


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


Fixed submission (verdict: Accepted):



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

def gcd(x, y):
    if x == 0:
        return y
    if y == 0:
        return x
        
    if y > x:
        temp = y
        y = x
        x = temp
    amari = x % y
    if amari == 0:
        return y
    else:
        return gcd(y, amari)
        
L = list(range(N))
L[0] = 0
for i in range(N-1):
    L[i+1] = gcd(L[i], A[i])
    
R = list(range(N))
R.append(0)
for i in reversed(range(N)):
    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):
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=[]

for i in range(n):
    temp1=0
    for j in range(i):
        temp1=gcd(temp1,a[j])
    temp2=a[i+1]
    for k in range(i+1,n):
        temp2=gcd(temp2,a[k])
    ans.append(gcd(temp1,temp2))

print(max(ans))


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

print(max(list_gcd))


Failing test case input:
2
0011101011 1000101001

Expected output:
1000101001


Actual output:
11101011


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

def gcd(a, b):
	if not a % b:
		return b
	return gcd(b, a % b)

ll, rl = [A[0]], [A[-1]]

for a in A[1:]:
	ll += [gcd(ll[-1], a)]
for a in A[::-1][1:]:
	rl += [gcd(rl[-1], a)]
rl = rl[::-1]




gcd_max = max(ll[-2], rl[-2])
for n in range(2, len(ll)):
	gcd_max = max(gcd_max, gcd(ll[n - 2], rl[n]))

print(gcd_max)


Failing test case input:
2
1010110100 1110100111

Expected output:
1110100111


Actual output:
1010110100


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

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

ans = 0
L = [0]*(n+1)
R = [0]*(n+1)
for i in range(n):
    L[i+1] = gcd(L[i], A[i])
    R[i+1] = gcd(R[i], A[-i])
for l, r in zip(L,R[::-1]):
    ans = max(ans, gcd(l, r))
print(ans)

Failing test case input:
2
0011101011 1100101001

Expected output:
1100101001


Actual output:
11101011


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)

ans = 0
L = [0]*(n)
R = [0]*(n+1)
for i in range(n-1):
    L[i+1] = gcd(L[i], A[i])
    R[i+1] = gcd(R[i], A[-i-1])
for l, r in zip(L[::-1],R):
    ans = max(ans, gcd(l, r))
print(ans)
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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

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

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

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

LN = [0] + LN + [0]
RN = [0] + RN + [0]
ans = 0
for i in range(1, N):
    ans = max(ans, gcd(LN[i - 1], RN[i + 1]))
print(ans)


Failing test case input:
2
1001000011 0101001100

Expected output:
1001000011


Actual output:
101001100


Fixed submission (verdict: Accepted):

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

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

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

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


LN = [0] + LN + [0]
RN = [0] + RN + [0]
ans = 0
for i in range(1, N + 1):
    ans = max(ans, gcd(LN[i - 1], RN[i + 1]))
print(ans)

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

import math
l_gcd = []
r_gcd = []

c = a[0]
for i in a[::-1]:
  c = math.gcd(c, i)
  l_gcd.append(c)
  
c = a[-1]
for j in a[1:][::-1]:
  c = math.gcd(c, j)
  r_gcd.append(c)
  
ans = max(r_gcd[-1], l_gcd[-1])
for r, l in zip(r_gcd[:-1], l_gcd[:-1][::-1]):
  c = math.gcd(r, l)
  ans = max(ans, c)
print(ans)

Failing test case input:
3
9 28 30

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

import math
l_gcd = []
r_gcd = []

c = a[0]
for i in a[:-1]:
  c = math.gcd(c, i)
  l_gcd.append(c)
  
c = a[-1]
for j in a[1:][::-1]:
  c = math.gcd(c, j)
  r_gcd.append(c)
  
ans = max(r_gcd[-1], l_gcd[-1])
for r, l in zip(r_gcd[:-1], l_gcd[:-1][::-1]):
  c = math.gcd(r, l)
  ans = max(ans, c)
print(ans)

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 = 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(2,N):
  D.append(gcd(B[j],C[N-j]))
D.append(B[N-2])
print(max(D))

Failing test case input:
3
12 15 18

Expected output:
6

Actual output:
3


Fixed submission (verdict: Accepted):
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))
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 not a % b:
		return b
	return gcd(b, a % b)

ll, rl = [A[0]], [A[-1]]

for a in A[1:]:
	ll += [gcd(ll[-1], a)]
for a in A[::-1][1:]:
	rl += [gcd(rl[-1], a)]
rl = rl[::-1]




gcd_max = max(ll[-2], rl[-2])
for n in range(2, N):
	gcd_max = max(gcd_max, gcd(ll[n - 2], rl[n]))

print(gcd_max)


Failing test case input:
2
1010111000 1111101111

Expected output:
1111101111


Actual output:
1010111000


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

N=int(input())
A=[int(s)for s in input().split()]
A=sorted(A)
if N==2:
  print(A[1])
  exit()
r=[]
for i in range(1,N):
  r.append(gcdf(A[i],A[0]))
gcd=r[1]
gcd2=A[1]
for i in range(2,N):
  gcd2=gcdf(A[i],gcd2)
print(max((gcd,gcd2)))
    

Failing test case input:
3
4 2 5

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
def gcdf(x,y):
  if y==0:return x
  if y>x:return gcdf(y,x)
  else:return gcdf(y,x%y)

N=int(input())
A=[int(s)for s in input().split()]
A=sorted(A)
if N==2:
  print(A[1])
  exit()
r=[]
for i in range(1,N):
  r.append(gcdf(A[i],A[0]))
r=sorted(r)
gcd=r[1]
for i in range(2,N-1):
  gcd=gcdf(r[i],gcd)
  
gcd2=A[1]
for i in range(2,N):
  gcd2=gcdf(A[i],gcd2)
print(max((gcd,gcd2)))

Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def gcd(x, y):
    while y!=0:
        x, y = y, x % y 
    return x

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

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


l = [-1] * n
r = [-1] * n
l[0] = a[0]  
r[-1] = a[-1] 
print(l)
print(r)

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

print("l",l) 
print("r",r)

ans = max(r[1], l[-2]) 


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

Failing test case input:
2
1110101001 1101101111

Expected output:
1110101001


Actual output:
1110101001
[1110101001, -1]
[-1, 1101101111]
l [1110101001, 1]
r [1, 1101101111]
1110101001


Fixed submission (verdict: Accepted):
def gcd(x, y):
    while y!=0:
        x, y = y, x % y 
    return x

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

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

elif n>=3:
    l = [-1] * n
    r = [-1] * n
    l[0] = a[0]  
    r[-1] = a[-1] 



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

        
        

    ans = max(r[1], l[-2]) 
        

    for i in range(1, n-1): 
        g = gcd(l[i-1], r[i+1]) 
        ans = max(ans, g)
        
    print(ans)
Problem: p03061
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)


Failing test case input:
2
1000100111 0101011110

Expected output:
1000100111


Actual output:
101011110


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

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

print(max(g))    
  
  


Failing test case input:
2
1001010111 0100001100

Expected output:
1001010111


Actual output:
100001100


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


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

left = A.copy()
right = A.copy()

for i in range(1, N):
    left[i] = gcd(left[i-1], left[i])

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

print((left, right))

ans = max(right[1], left[-2])

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

print(ans)

Failing test case input:
2
1111001110 0011000101

Expected output:
1111001110


Actual output:
([1111001110, 1], [1, 11000101])
1111001110


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


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

left = A.copy()
right = A.copy()

for i in range(1, N):
    left[i] = gcd(left[i-1], left[i])

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

ans = max(right[1], left[-2])

for i in range(1, N-1):
    ans = max(ans, gcd(left[i-1], right[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
    c = a % b
    return gcd(b, c)


def list_gcd(a):
    a_gcd = a[0]
    for i in range(n-1):
        a_gcd = gcd(a_gcd, a[i+1])
    return a_gcd


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

ans = list_gcd(a)

for i in range(n):
    b = a[:]
    if b[i] % 2 != 0:
        b[i] = b[i-1]
        ans = max(ans, list_gcd(b))

print(ans)


Failing test case input:
2
0000101100 0010100000

Expected output:
10100000


Actual output:
100


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


n = int(input())
a = list(map(int, input().split()))
a = [0]+a[:]+[0]

l = [0]*len(a)
r = [0]*len(a)

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

ans = [0]*n

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

print(max(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):
    while b:
        a, b = b, a % b
    return a
g=[]
l=[a[0]]
r=[a[n-1]]
for i in range(1,n):
    l.append(gcd(l[i-1], a[i]))
    r.append(gcd(r[i-1], a[n-i-1]))
r.reverse()
g.append(r[1])
for i in range(n-1):
    g.append(gcd(l[i], r[n-i-1]))
print(max(g))

Failing test case input:
2
1001101001 0101101111

Expected output:
1001101001


Actual output:
101101111


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int, input().split()))
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
g=[]
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.reverse()
for i in range(n):
    g.append(gcd(l[i], r[i+1]))
print(max(g))
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
  else:
    return gcd(b,a%b)

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

Failing test case input:
2
1111101101 1100101000

Expected output:
1111101101


Actual output:
1100101000


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)

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

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

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

def gcd(m,n):
  x=max(m,n)
  y=min(m,n)
  while y!=0:
    x,y=y,x%y
  return x
 
a=int(input())
li=list(map(int,input().split()))
left_gcd=[0]

right_gcd=[0]


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


print(right_gcd)
print(left_gcd)
num_li=[]



for i in range(a):
    ans=gcd(left_gcd[(a-1)-i],right_gcd[i])
    
  
    
    num_li.append(ans)
    

print(max(num_li))


Failing test case input:
2
1010010111 0110000101

Expected output:
1010010111


Actual output:
[0, 110000101, 1]
[0, 1010010111, 1]
1010010111


Fixed submission (verdict: Accepted):
 

def gcd(m,n):
  x=max(m,n)
  y=min(m,n)
  while y!=0:
    x,y=y,x%y
  return x
 
a=int(input())
li=list(map(int,input().split()))
left_gcd=[0]

right_gcd=[0]


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




num_li=[]



for i in range(a):
    ans=gcd(left_gcd[(a-1)-i],right_gcd[i])
    
  
    
    num_li.append(ans)
    

print(max(num_li))

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[0])
    for i in range(2, N-2):
        res = max(gcd(left[i-1],right[i+1]), res)
    return res


print(m())


Failing test case input:
2
1000000111 0111001101

Expected output:
1000000111


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