t=int(input())
for _ in range(t):
    x,y,a,b=map(int,input().split())
    i=0
    while(x<y):
        x+=a
        y-=b
        i+=1
    if(x==y):
        print(i)
    else:
        print(-1)


t=int(input())
for _ in range(t):
    x,y,a,b=map(int,input().split())
    i=0
    while(x<y):
        x+=a
        y-=b
        i+=1
    if(x==y)
        print(i)
    else:
        print(-1)


t=int(input())
for _ in range(t):
    x,y,a,b=map(int,input().split())
    speed=a+b
    if((y-x)%speed!=0):
        print(-1)
    else:
        print((y-x)//speed)


n=int(input())

for i in range(n):
    x=int(input())
    y=int(input())
    a=int(input())
    b=int(input())
    if (x-y)%(a+b)==0:
        print((y-x)/(a+b))
    else:
        print(-1)


n=int(input())

for i in range(n):
    x,y,a,b=map(int,input().split())
    if (x-y)%(a+b)==0:
        print((y-x)//(a+b))
    else:
        print(-1)


# -*- coding: utf-8 -*-
"""
Created on Thu Oct  1 23:47:08 2020

@author: SAIGANESH
"""

t=int(input())
for _ in range(t):
    x,y,a,b=map(int,input().split())
    for i in range(y):
        x+=a
        y-=b
        if(x==y):
            print(i-1)
            break
    else:
        print(-1)


# -*- coding: utf-8 -*-
"""
Created on Thu Oct  1 23:47:08 2020

@author: SAIGANESH
"""

t=int(input())
for _ in range(t):
    x,y,a,b=map(int,input().split())
    for i in range(y):
        x+=a
        y-=b
        if(x==y):
            print(i+1)
            break
    else:
        print(-1)


# -*- coding: utf-8 -*-
"""
Created on Thu Oct  1 23:47:08 2020

@author: SAIGANESH
"""

t=int(input())
for _ in range(t):
    x,y,a,b=map(int,input().split())

    for i in range(y):
        x+=a
        y-=b
        if(x==y):
            print(i)
            break
    else:
        print(-1)


# -*- coding: utf-8 -*-
"""
Created on Thu Oct  1 23:47:08 2020

@author: SAIGANESH
"""

t=int(input())
for _ in range(t):
    x,y,a,b=map(int,input().split())
    for i in range(y):
        x+=a
        y-=b
        if(x==y):
            print(i)
            break
    else:
        print(-1)


# -*- coding: utf-8 -*-
"""
Created on Thu Oct  1 23:47:08 2020

@author: SAIGANESH
"""

t=int(input())
for _ in range(t):
    x,y,a,b=map(int,input().split())
    y-=x
    a+=b
    print((y//a,-1)[y%a>0])


def main(x, y, a, b):
    t = 0
    while x < y:
        x += a
        y -= b
        t += 1
    return t if x == y else -1

if __name__ == '__main__':
    n = int(input())
    for _ in range(n):
        print(
            main(
                *map(int, input().split())
            )
        )


def main(x, y, a, b):
    t = 0
    while x < y:
        x += a
        y -= b
        t += 1
    return t if x == y else -1

if __name__ == '__main__':
    n = int(input())
    results = []
    for _ in range(n):
        results.append(
            main(
                *map(int, input().split())
            )
        )
    for r in results:
        print(r)


def main(x, y, a, b):
    t = (y - x) / (a + b)
    return int(t) if t.is_integer() else -1

if __name__ == '__main__':
    n = int(input())
    for _ in range(n):
        print(
            main(
                *map(int, input().split())
            )
        )

'''
x + t * a = y - t * b
t * a + t * b = y - x
t * (a + b) = y - x
t = (y - x) / (a + b)
'''


for _ in range(int(input())):
    x,y,a,b = map(int,input().split())
    A = x-y
    B = a+b
    if A%B == 0:
        print(A//B)
    else:
        print('-1')


for _ in range(int(input())):
    x,y,a,b = map(int,input().split())
    i =0
    while x < y:
        x +=a
        y -=b
        i +=1
    if x == y:
        print('x:',x,'y:',y)
        print(i)
    else:
        print('-1')


for _ in range(int(input())):
    x,y,a,b = map(int,input().split())
    i =0
    while x < y:
        x +=a
        y -=b
        i +=1
    if x == y:
        print(i)
    else:
        print('-1')


for _ in range(int(input())):
    x,y,a,b = map(int,input().split())
    v = y-x
    u = a+b
    if v % u !=0:
        print(-1);
    else:
        print((v)//(u))


n_test_cases = input()

for i in range(int(n_test_cases)):
    x, y, a, b = input().split()
    x, y, a, b = int(x), int(y), int(a), int(b)
    t = (y-x)//(b+a)
    if x+a*t == y-b*t:
        print(t)
    else:
        print(-1)


n_test_cases = input()

for i in range(int(n_test_cases)):
    x, y, a, b = input().split()
    x, y, a, b = int(x), int(y), int(a), int(b)
    t = (y-x)//(b+a)
    print(x,y,a,b,t)
    if x+a*t == y-b*t:
        print(t)
    else:
        print(-1)


num = int(input())
for i in range(num):
    p1,p2,s1,s2 = map(int,input().split())
    t = (p2-p1)/(s2+s1)
    if t!=round(t):
        print(-1)
    else:
        print(int(t))


n = int(input())
w1 = 0
w2 = 0
wt = 0
for i in range(0, n):
    x, y, a, b = map(int,input().split())
    w1 = a + b #v
    w2 = abs(y - x) #d
    wt = w2 / w1  #t
    if wt % 2 > 0 and wt < 1:
        print(-1)
    elif wt % 2 > 1 and wt < 2:
        print(-1)
    elif wt % 2 == 0:
        print(int(wt))
    elif wt % 2 == 1:
        print(int(wt))


n = int(input())
w1 = 0
w2 = 0
wt = 0
a = 0
b = 0
x = 0
y = 0
for i in range(0, n):
    x, y, a, b = map(int,input().split())
    w1 = a + b #v
    w2 = abs(y - x) #d
    wt = w2 / w1  #t
    if wt % 2 > 0 and wt < 1:
        print(-1)
    elif wt % 2 > 1 and wt < 2:
        print(-1)
    elif wt % 2 == 0:
        print(int(wt))
    elif wt % 2 == 1:
        print(int(wt))


n = int(input())
for i in range(0,n):
    x, y, a, b = map(int,input().split())
    v = a + b
    d = y - x
    output = d/v
    if output %2 > 0 and output %2 < 1:
        print(-1)
    elif output %2 >1 and output%2 <2:
        print(-1)
    else:
        print(int(output))


n = int(input())
for n in range( 0 , n , 1):
    x, y, a, b = map(int, input().split())
    w1 = a + b #v
    w2 = y - x #d
    wt = w2 / w1  #t
    if wt % 2 > 0 and wt < 1:
        print(-1)
    if wt % 2 > 1 and wt < 2:
        print(-1)
    else:
        print(int(wt))


n = int(input())
w1 = 0
w2 = 0
wt = 0
a = 0
b = 0
x = 0
y = 0
for i in range(0, n):
    x, y, a, b = map(int,input().split())
    w1 = a + b #v
    w2 = abs(y - x) #d
    wt = w2 / w1  #t
    if wt % 2 > 0 and wt < 1:
        print(-1)
    elif wt % 2 > 1 and wt < 2:
        print(-1)
    else:
        print(int(wt))


x,y,a,b=map(int,input().split())
c=0
while x<y:
  x+=a
  y-=b
  c+=1
if x==y:
  print(c)
else:
  print(-1)


t=int(input())
for e in range(t):
  x,y,a,b=map(int,input().split())
  c=0
  while x<y:
    x+=a
    y-=b
    c+=1
  if x==y:
    print(c)
  else:
    print(-1)


t=int(input())
for e in range(t):
  x,y,a,b=map(int,input().split())
  if (y-x)%(a+b)==0:
    print((y-x)//(a+b))
  else:
    print(-1)


for i in range(int(input())):
	m=list(map(int,input().split()))
	x=m[0]
	y=m[1]
	a=m[2]
	b=m[3]
	n=0
	while(x<y):
		x+=a;
		y-=b;
		n+=1
	if(x!=y):
		print(int('-1'))
	else:
		print(n)


for i in range(int(input())):
	m=list(map(int,input().split()))
	p=m[0]+m[1]
	q=m[2]+m[3]

	print(p//q if p%q==0 else -1)


for i in range(int(input())):
	m=list(map(int,input().split()))
	p=m[0]+m[1]
	q=m[2]+m[3]

	print(p/q if p%q==0 else -1)


for i in range(int(input())):
	m=list(map(int,input().split()))
	p=m[1]-m[0]
	q=m[2]+m[3]

	print(p//q if p%q==0 else -1)


n=int(input())
ll=[]
for i in range(n):
    n=[]
    s=input()
    m=s.split(" ")
    for i in m:
        n.append(int(i))
    ll.append(n)
for l in ll:
    for n in range(10^(3)):
        t=0
        if l[0]+(n*l[2])==l[1]-(n*l[3]):
            t+=1
            print(n)
            break;
    if t==0:
        print(-1)


n=int(input())
ll=[]
for i in range(n):
    n=[]
    s=input()
    m=s.split(" ")
    for i in m:
        n.append(int(i))
    ll.append(n)
for l in ll:
    for n in range(20):
        t=0
        if l[0]+(n*l[2])==l[1]-(n*l[3]):
            t+=1
            print(n)
            break;
    if t==0:
        print(-1)


n=int(input())
ll=[]
for i in range(n):
    n=[]
    s=input()
    m=s.split(" ")
    for i in m:
        n.append(int(i))
    ll.append(n)
for l in ll:
    t=0
    while l[0]<=l[1] :
         l[0]=l[0]+l[2]
         l[1]=l[1]-l[3]
         t+=1
         if l[0]==l[1]:
             break;
         continue;
    if l[0]==l[1]:
        print(t)
    else:
        print("-1")


n=int(input())
m=[]
for i in range(n):
    l=[]
    s=input()
    ss=s.split(" ")
    s="".join(ss)
    for i in s:
        l.append(int(i))
    m.append(l)
for l in m:
    t=0
    while l[0]<=l[1] :
         l[0]=l[0]+l[2]
         l[1]=l[1]-l[3]
         t+=1
         if l[0]==l[1]:
             break;
    if l[0]==l[1]:
        print(t)
    else:
        print("-1")


n=int(input())
ll=[]
for i in range(n):
    n=[]
    s=input()
    m=s.split(" ")
    for i in m:
        n.append(int(i))
    ll.append(n)
for l in ll:
    for n in range(1,1001):
        t=0
        if l[0]+(n*l[2])==l[1]-(n*l[3]):
            t+=1
            print(n)
            break;
    if t==0:
        print(-1)


n=int(input())
ll=[]
for i in range(n):
    n=[]
    s=input()
    m=s.split(" ")
    for i in m:
        n.append(int(i))
    ll.append(n)
for l in ll:
    for n in range(1,1000):
        t=0
        if l[0]+(n*l[2])==l[1]-(n*l[3]):
            t+=1
            print(n)
            break;
    if t==0:
        print(-1)


n=int(input())
m=[]
for i in range(n):
    s=[]
    for i in range(4):
        x=int(input())
        s.append(x)
    m.append(s)
for l in m:
    t=0
    while l[0]<=l[1] :
         l[0]=l[0]+l[2]
         l[1]=l[1]-l[3]
         t+=1
         if l[0]==l[1]:
             break;
    if l[0]==l[1]:
        print(t)
    else:
        print("-1")


n=int(input())
ll=[]
for i in range(n):
    n=[]
    s=input()
    m=s.split(" ")
    for i in m:
        n.append(int(i))
    ll.append(n)
for l in ll:
    t=0
    while l[0]<=l[1] :
         l[0]=l[0]+l[2]
         l[1]=l[1]-l[3]
         t+=1
         if l[0]==l[1]:
             break;
    if l[0]==l[1]:
         print(t)
    else:
        print("-1")


x = int(input())
l =[]
for i in range(x):
    s = input ()
    l.append(s)
for i in l:
    ll = i.split(" ")
    x = int(ll[0])
    y = int(ll[1])
    a = int(ll[2])
    b = int(ll[3])
    z =  y - x
    su = a + b
    if z%su==0:
        print(int(z/su))
    else:
        print(-1)


n=int(input())
ll=[]
for i in range(n):
    n=[]
    s=input()
    m=s.split(" ")
    for i in m:
        n.append(int(i))
    ll.append(n)
for l in ll:
    for n in range(1000):
        t=0
        if l[0]+(n*l[2])==l[1]-(n*l[3]):
            t+=1
            print(n)
            break;
    if t==0:
        print(-1)


n=int(input())
ll=[]
for i in range(n):
    n=[]
    s=input()
    m=s.split(" ")
    for i in m:
        n.append(int(i))
    ll.append(n)
for l in ll:
    t=0
    while l[0]<=l[1] :
         l[0]=l[0]+l[2]
         l[1]=l[1]-l[3]
         t+=1
         if l[0]==l[1]:
             break;
    if l[0]==l[1]:
        print(t)
    else:
        print("-1")


n=int(input())
m=[]
for i in range(n):
    l=[]
    s=input()
    l.append(int(s[0]))
    l.append(int(s[2]))
    l.append(int(s[4]))
    l.append(int(s[6]))
    m.append(l)
for l in m:
    t=0
    while l[0]<=l[1] :
         l[0]=l[0]+l[2]
         l[1]=l[1]-l[3]
         t+=1
         if l[0]==l[1]:
             break;
    if l[0]==l[1]:
        print(t)
    else:
        print("-1")


n=int(input())
ll=[]
for i in range(n):
    n=[]
    s=input()
    m=s.split(" ")
    for i in m:
        n.append(int(i))
    ll.append(n)
for l in ll:
    t=0
    while l[0]<=l[1] :
         l[0]=l[0]+l[2]
         l[1]=l[1]-l[3]
         t+=1
         if l[0]==l[1]:
             print(t)
             break;
    if l[0]!=l[1]:
        print("-1")


for _ in range(int(input())):
    x, y, a, b = map(int, input().split())

    time = 0

    while True:
        time += 1
        x += a
        y -= b

        if x == y:
            print(time)
            break
        elif x > y:
            print("-1")
            break


for _ in range(int(input())):
    x, y, a, b = map(int, input().split())

    time = (y-x) // (a+b)

    if ((y-x) % (a+b)) is 0:
        print(time)
    else:
        print("-1")


for _ in range(int(input())):
    x, y, a, b = map(int, input().split())

    time = (y-x) // (a+b)

    if ((y-x) % (a+b)) == 0:
        print(time)
    else:
        print("-1")


q=int(input())
for i in range(q):
    s=input().split()
    x=int(s[0])
    y=int(s[1])
    a=int(s[2])
    b=int(s[3])
    if (y-x)%(a+b)==0:
        print(int((y-x)/(a+b)))
    else:
        print(-1)


q=int(input())
for i in range(q):
    s=input().split()
    x=int(s[0])
    y=int(s[1])
    a=int(s[2])
    b=int(s[3])
    c=0
    while y-x>0:
        x+=a
        y-=b
        c+=1
    if x-y==0:
        print(c)
    else:
        print(-1)


q=int(input())
for i in range(q):
    s=input().split()
    x=int(s[0])
    y=int(s[1])
    a=int(s[2])
    b=int(s[3])
    if (y-x)%(a+b)==0:
        print((y-x)/(a+b))
    else:
        print(-1)


def check(a,i,j):
    while(a[0] != a[1]):
        if(a[0] <= a[1]):
            a[0]+= a[2]
            a[1]-= a[3]
            i+=1
        else:
            j=1
            break
    return i,j

t = int(input())
while(t != 0):
    a = list(map(int,input().split()))
    i=0
    j=0
    i,j = check(a,i,j)
    if(j != 1):
        print(i)
    else:
        print(-1)
    t-=1


t=int(input())
for _ in range(t):
    x=int(input())
    y=int(input())
    a=int(input())
    b=int(input())
    d=0
    if((y-x)%(a+b)==0):
        print((y-x)//(a+b))
    else:
        print(-1)


t=int(input())
for _ in range(t):
    x,y,a,b=input().split()
    x=int(x)
    y=int(y)
    a=int(a)
    b=int(b)
    d=0
    while(x!=y):
         y=y-b
         x=x+a
         d+=1
         if(y<=x):
            break
    if(x==y):
        print(d)
    else:
        print('-1')


t=int(input())
for _ in range(t):
    x=int(input())
    y=int(input())
    a=int(input())
    b=int(input())
    d=0
    if((y-x)%(a+b)==0):
        print((y-x)/(a+b))
    else:
        print(-1)


t=int(input())
for _ in range(t):
    x=int(input())
    y=int(input())
    a=int(input())
    b=int(input())
    d=0
    while(x!=y):
         y=y-b
         x=x+a
         d+=1
         if(y<=x):
            break
    if(x==y):
        print(d)
    else:
        print(-1)


t=int(input())
for _ in range(t):
    x=int(input())
    y=int(input())
    a=int(input())
    b=int(input())
    d=0
    if((y-x)%(a+b)==0):
        print(int((y-x)/(a+b)))
    else:
        print(-1)


t=int(input())
for _ in range(t):
    x,y,a,b=input().split()
    x=int(x)
    y=int(y)
    a=int(a)
    b=int(b)
    d=0
    while(x!=y):
        if(y>x):
            y=y-b
            x=x+a
            d+=1
        else:
            break
    if(d>0 and x==y):
        print(d)
    else:
        print('-1')


t=int(input())
for _ in range(t):
    x,y,a,b=input().split()
    x=int(x)
    y=int(y)
    a=int(a)
    b=int(b)
    d=0
    while(x!=y):
         y=y-b
         x=x+a
         d+=1
         if(y<=x):
            break
    if(x==y):
        print(d)
    else:
        print(-1)


t=int(input())
for _ in range(t):
    x,y,a,b=map(int,input().split())
    if((y-x)%(a+b)==0):
        print((y-x)//(a+b))
    else:
        print(-1)


t=int(input())
for _ in range(t):
    x,y,a,b=input().split()
    x=int(x)
    y=int(y)
    a=int(a)
    b=int(b)
    d=0
    while(x!=y):
        if(y>x):
            y=y-b
            x=x+a
            d+=1
        else:
            break
    if(x==y):
        print(d)
    else:
        print('-1')


t=int(input())
for _ in range(t):
    x,y,a,b=input().split()
    x=int(x)
    y=int(y)
    a=int(a)
    b=int(b)
    d=0
    while(x!=y):
            y=y-b
            x=x+a
            d+=1
    if(x==y):
        print(d)
    else:
        print('-1')


t=int(input())
for i in range(t):
	x,y,a,b=map(int,input().split())
	if((x+y)%(a+b)==0):
		print(abs(x-y)//(a+b))
	else:
		print(-1)


t=int(input())
for i in range(t):
	x,y,a,b=map(int,input().split())
	s=0
	for j in range(10000):
		x=x+a
		y=y-b
		s=s+1
		if(x==y):
			print(s)
			break
	else:
		print(-1)


t=int(input())
for i in range(t):
	x,y,a,b=map(int,input().split())
	if((abs(y-x))%(a+b)==0):
		print((y-x)//(a+b))
	else:
		print(-1)


t=int(input())
for i in range(t):
	x,y,a,b=map(int,input().split())
	s=0
	for j in range(1000):
		x=x+a
		y=y-b
		s=s+1
		if(x==y):
			print(s)
			break
	else:
		print(-1)


for i in range(int(input())):
    x, y, a, b = list(map(int, input().split()))
    ans = (y-x)//(a+b)
    if (ans == 0):
        print(-1)
    else:
        print(ans)


for i in range(int(input())):
    x, y, a, b = list(map(int, input().split()))
    ans = (y-x)/(a+b)
    if (ans < 1.0 or (1.0 < ans and ans < 2.0)):
        print(-1)
    else:
        print(int(ans))


x, y, a, b = list(map(int, input().split()))
ans = (y-x)//(a+b)
if (ans == 0):
    print(-1)
else:
    print(ans)


for i in range(int(input())):
    x, y, a, b = list(map(int, input().split()))
    ans = (y-x)//(a+b)
    if (ans <= 1):
        print(-1)
    else:
        print(ans)


for i in range(int(input())):
    x, y, a, b = list(map(int, input().split()))
    t = 0
    for i in range(x, y):
        x += a
        y -= b
        t += 1
        if (x == y):
            print(t)
            break
    else:
        print(-1)


for i in range(int(input())):
    x, y, a, b = list(map(int, input().split()))
    ans = (y-x)//(a+b)
    if ((y-x) % (a+b) != 0):
        print(-1)
    else:
        print(ans)


x, y, a, b = list(map(int, input().split()))
ans = (y-x)//(a+b)
if (ans <= 1):
    print(-1)
else:
    print(ans)


x, y, a, b = list(map(int, input().split()))
ans = (y-x)/(a+b)
if (ans < 1.0 or (1.0 < ans and ans < 2.0)):
    print(-1)
else:
    print(int(ans))


for _ in range(int(input())):

    x,y,a,b =map(int,input().split())
    if (y-x)%a+b ==0:
        print((y-x)//(a+b))
    else:
        print(-1)


t=(int)input()
x,y,a,b =map(int.input().split())
if (y-x)%a+b ==0:
    print((y-x)//(a+b))
else:
    print("-1")


for _ in range(int(input())):
  x,y,a,b =map(int,input().split())
  if (y-x)%a+b ==0:
      print((y-x)//(a+b))
  else:
      print("-1")


for _ in range(int(input())):

    x,y,a,b =map(int,input().split())
    if (y-x)%(a+b)==0:
        print((y-x)//(a+b))
    else:
        print(-1)


t=int(input())
x,y,a,b =map(int,input().split())
if (y-x)%a+b ==0:
    print((y-x)//(a+b))
else:
    print("-1")


test = int(input())
for _ in range(test):
	x, y, a, b = map(int, input().split())
	c = 0
	while x<y:
		x+=a;y-=b
		c+=1
	else:
		if x>y:
			print(-1)
		elif x==y:
			print(c)


test = int(input())
for _ in range(test):
	x, y, a, b = map(int, input().split())
	d=y-x;s=a+b
	if not d%s:
		print(d//s)
	else:
		print(-1)


test = int(input())
for _ in range(test):
	x, y, a, b = map(int, input().split())
	c = 0
	while x<y:
		x+=a;y-=b
		c+=1
		if x>y:
			print(-1)
			break
		elif x==y:
			print(c)
			break


test = int(input())
for _ in range(test):
	x, y, a, b = map(int, input().split())
	c = 0
	while True:
		x+=a;y-=b
		c+=1
		if x==y:
			print(c)
			break
		elif x>y:
			print(-1)
			break


for _ in range(int(input())):
    x,y,a,b = list(map(int,input().split()))
    t = (y-x)/(a+b)
    if(t==int(t)):
        print(t)
    else:
        print("-1")


for _ in range(int(input())):
    x,y,a,b = list(map(int,input().split()))
    t = (y-x)/(a+b)
    if(t==int(t)):
        print(int(t))
    else:
        print("-1")


for _ in range(int(input())):
    x,y,a,b = list(map(int,input().split()))
    count=0
    t=0
    while(x<=y):
        x+=a
        y-=b
        count+=1
        if(x==y):
            print(count)
            t=1
            break
    if(t==0):
        print("-1")


x=int(input())
for i in range(0,x):
    m=list(map(int,input().split()))[:4]
    k=m[0]
    p=m[1]
    f=0
    while((p-k)>0):
        k=k+m[2]
        p=p-m[3]
        f=f+1
    if (k==p):
        print(f)
    else:
        print("-1")


#include <bits/stdc++.h>

using namespace std;

int abs(int a)
{
    if (a<0)
        return -a;
    return a;
}

int main()
{
    int n; //А если вообще убрать массив...
    cin >> n;
    vector<int>null;

    for (int i=0; i<n; i++)
    {
        int e;
        cin >> e;
        if (!e)
            null.push_back(i);
    }

    for (int i=0; i<n; i++)
    {
        int second = lower_bound(null.begin(), null.end(), i)-null.begin(), first;
        if (second>0)
        {
            first = null[second-1];
            second = null[second];
        }
        else
        {
            first = 1e9;
            second = null[second];
        }
        cout << min(abs(i-first), abs(i-second)) << " ";

    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int abs(int a)
{
    if (a<0)
        return -a;
    return a;
}

vector<int>null;
int n;

//Окей
int lower_bound(int a)
{
    int l=0, r=null.size();
    while (l<r)
    {
        int m=(l+r)/2;
        if (null[m]>=a)
            r=m;
        else
            l=m+1;
    }
    return l;
}

int main()
{
    cin >> n;
    for (int i=0; i<n; i++)
    {
        int e;
        cin >> e;
        if (e==0)
            null.push_back(i);
    }
    for (int i=0; i<n; i++)
    {
        int second = lower_bound(i), first;
        if (second>0)
        {
            first = null[second-1];
            second = null[second];
        }
        else
        {
            first = 1e9;
            second = null[second];
        }
        cout << min(abs(i-first), abs(i-second)) << " ";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, a[200055];
    cin >> n;
    vector<int>null;

    for (int i=0; i<n; i++)
    {
        cin >> a[i];
        if (!a[i])
            null.push_back(i);
    }

    for (int i=0; i<n; i++)
    {
        int second = lower_bound(null.begin(), null.end(), i)-null.begin(), first;
        if (second>0)
        {
            first = null[second-1];
            second = null[second];
        }
        else
        {
            first = 1e9;
            second = null[second];
        }
        cout << min(abs(i-first), abs(i-second)) << " ";

    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int abs(int a)
{
    if (a<0)
        return -a;
    return a;
}

vector<int>null;

int main()
{
    int n; //Ещё один неправильный ответ - и я начинаю писать бинпоиск
    cin >> n;

    for (int i=0; i<n; i++)
    {
        int e;
        cin >> e;
        if (e==0)
            null.push_back(i);
    }

    for (int i=0; i<n; i++)
    {
        int second = lower_bound(null.begin(), null.end(), i)-null.begin(), first;
        if (second>0)
        {
            first = null[second-1];
            second = null[second];
        }
        else
        {
            first = 1e9;
            second = null[second];
        }
        cout << min(abs(i-first), abs(i-second)) << " ";

    }
    return 0;
}


#include <fstream>

using namespace std;

int abs(int a)
{
    if (a<0)
        return -a;
    return a;
}

vector<int>null;

int main()
{
    int n; //Ещё один неправильный ответ - и я начинаю писать бинпоиск
    cin >> n;

    for (int i=0; i<n; i++)
    {
        int e;
        cin >> e;
        if (e==0)
            null.push_back(i);
    }

    for (int i=0; i<n; i++)
    {
        int second = lower_bound(null.begin(), null.end(), i)-null.begin(), first;
        if (second>0)
        {
            first = null[second-1];
            second = null[second];
        }
        else
        {
            first = 1e9;
            second = null[second];
        }
        cout << min(abs(i-first), abs(i-second)) << " ";

    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, a[200000];
    cin >> n;
    vector<int>null;

    for (int i=0; i<n; i++)
    {
        cin >> a[i];
        if (!a[i])
            null.push_back(i);
    }

    for (int i=0; i<n; i++)
    {
        int second = lower_bound(null.begin(), null.end(), i)-null.begin(), first;
        if (second>0)
        {
            first = null[second-1];
            second = null[second];
        }
        else
        {
            first = 1e9;
            second = null[second];
        }
        cout << min(abs(i-first), abs(i-second)) << " ";

    }
    return 0;
}


#include <iostream>
using namespace std;
int a[200001],q[200001];
int main(){
	int n,e=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]!=0){
			a[i]=1;
		}
		else{
			e++;
			q[e]=i;
		}
	}
	for(int i=1;i<q[e];i++){
		for(int j=1;j<e;j++){
			if(q[j]>=i){
				a[i]=q[j]-i;
				break;
			}
		}
	}
	for(int i=q[e];i<=n;i++){
		a[i]=i-q[e];
	}
	for(int i=1;i<=n;i++){
		cout<<a[i]<<" ";
	}
	return 0;
}


#include <iostream>
using namespace std;
int a[200001],q[200001];
int main(){
	int n,e=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]!=0){
			a[i]=1;
		}
		else{
			e++;
			q[e]=i;
		}
	}
	for(int i=1;i<q[e];i++){
		for(int j=1;j<=e;j++){
			if(q[j]>=i){
				a[i]=q[j]-i;
				break;
			}
		}
	}
	for(int i=q[e];i<=n;i++){
		a[i]=i-q[e];
	}
	for(int i=1;i<=n;i++){
		cout<<a[i]<<" ";
	}
	return 0;
}


#include <iostream>
#include <stdio.h>
using namespace std;
int a[200001],q[200001];
int main(){
	int n,c=0,e=0;
	scanf("%d", &n);
	for(int i=1;i<=n;i++){
		scanf("%d", &a[i]);
		if(a[i]==0){
			e=i;
		}
		else if(e!=0){
			a[i]=i-e;
		}
	}
	for(int i=1;i<=n;i++){
		if(a[i]==0){
			e=i;
			break;
		}
	}
	for(int i=1;i<=e;i++){
		a[i]=e-i;
	}
	for(int i=n;i>=e;i--){
		if(a[i]==0){
			c=i;
		}
		else if(c!=0){
			a[i]=min(a[i],c-i);
		}
	}
	for(int i=1;i<=n;i++){
		printf("%d ", a[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define F(i, l,r) for(long long i =l; i<=r; ++i)
#define Fr(i, l,r) for(long long i =l; i>=r; --i)
using namespace std;
typedef long long ll;
ll n, k, a[111][111];
int main()
{
        cin >> n >> k;

 if(k<=n)
    {F(i, 1, n)
  {F(j, 1, n)

          {if (i==j && k >0) { cout<<1<<" "; --k; continue;}
          cout<<0<<" ";}
          cout<<endl;
  }}
  else
  {
          F(i,1, n) a[i][i] = 1;
          k -=n; bool ok =true;
          F(i, 1, n)
          if(ok)
          Fr(j, n, 1)
          if(i!=j)
          {
             a[i][j] = a[j][i] = 1;
             k-=2;
             if(k == 0) { ok =false; break;}
          }
          else break;
          if(k!=0) {cout<<-1; return 0;}
         F(i, 1, n)
         {
                 F(j, 1, n)
                 cout<<a[i][j]<<" ";
                 cout<<endl;
         }

  }

    return 0;
}


#include <bits/stdc++.h>
#define F(i, l,r) for(long long i =l; i<=r; ++i)
#define Fr(i, l,r) for(long long i =l; i>=r; --i)
using namespace std;
typedef long long ll;
ll n, a[200200], d[200200], z[200200];
int main()
{
 cin >> n;
 F(i, 1, n)
 {
         scanf("%I64d", &a[i]);
         if(a[i] == 0) z[i] = 1;
         d[i] = 1000000009;
 }

 F(i, 1, n)
 if(z[i] == 1)
 {  d[i] = 0;
         F(j, 1, n)

   d[j] = min(d[j], abs(i-j));

 }
F(i, 1, n) cout<<d[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>
#define F(i, l,r) for(long long i =l; i<=r; ++i)
#define Fr(i, l,r) for(long long i =l; i>=r; --i)
using namespace std;
typedef long long ll;
ll n, a[200200], d[200200], z[200200], k, h, m;
int main()
{
 cin >> n;
 F(i, 1, n)
 {
         scanf("%I64d", &a[i]);
         if(a[i] == 0) {
                         if(m>=1)  z[h] =i ;
                        z[i] = 1; ++m; h = i;

          }

         d[i] = 1000000009;
 }
 m = 1;
 F(i, 1, n)
 if(z[i] !=0)
 {  d[i] = 0;
 ll k ;
 if(z[i] == 1) k = n; else  k = (z[i] + i)/2;
         F(j, m,  k )

   d[j] = min(d[j], abs(i-j));
   m = k;

 }
F(i, 1, n) cout<<d[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>
#define F(i, l,r) for(long long i =l; i<=r; ++i)
#define Fr(i, l,r) for(long long i =l; i>=r; --i)
using namespace std;
typedef long long ll;
ll n, a[200200], d[200200], z[200200];
int main()
{
 cin >> n;
 F(i, 1, n)
 {
         scanf("%I64d", &a[i]);
         if(a[i] == 0) z[i] = 1;
 }
 F(i, 0, n) d[i] = 1000000009;
 F(i, 1, n)
 if(z[i] == 1)
 {  d[i] = 0;
         F(j, 1, n)
   d[j] = min(d[j], abs(i-j));

 }
F(i, 1, n) cout<<d[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>
#define F(i, l,r) for(long long i =l; i<=r; ++i)
#define Fr(i, l,r) for(long long i =l; i>=r; --i)
using namespace std;
typedef long long ll;
ll n, a[20020], d[20020], z[20020];
int main()
{
 cin >> n;
 F(i, 1, n)
 {
         scanf("%I64d", &a[i]);
         if(a[i] == 0) z[i] = 1;
 }
 F(i, 0, n) d[i] = 1000000009;
 F(i, 1, n)
 if(z[i] == 1)
 {  d[i] = 0;
         F(j, 1, n)
   d[j] = min(d[j], abs(i-j));

 }
F(i, 1, n) cout<<d[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int ans[200002]={0};
void fill(){
	for(int i=0;i<200002;i++) ans[i] = 1e7;
}
int main() {fill();
	int n;cin>>n;
	int arr[200002];

	queue<int>q;
	stack<int>st;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		if(arr[i] == 0) q.push(i), st.push(i);
	}
	for(int i=0;i<n;i++){
		if(q.size() != 0){
		if(q.front() >= i ) ans[i] = q.front()-i;
		else {
			q.pop();
			if(q.size() !=0)
			ans[i] = q.front()-i;
			}
		}
	}

	for(int i=n-1;i>=0;i--){
		if(st.size() != 0){
		if(st.top() <= i ) ans[i] = min(ans[i],i-st.top());
		else {
			st.pop();
			if(st.size() !=0)
			ans[i] = min(ans[i],i-st.top());
			}
		}
	}

	for(int i=0;i<n;i++)
	cout<<ans[i]<<" ";

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;cin>>n;
	int arr[200002];
	set<int>st;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		if(arr[i] == 0) st.insert(i+1);
	}
	for(int i=0;i<n;i++){
		int mn = 1e7;
		for(set<int> :: iterator j = st.begin();j!= st.end();j++){
			mn = min(abs(i+1- *j),mn);
		}
		cout<<mn<<" ";

	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;cin>>n;
	int arr[200002];
	set<int>st;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		if(arr[i] == 0) st.insert(i+1);
	}
	for(int i=0;i<n;i++){
		int mn = 1e7;
		if(arr[i] == 0) {cout<<0;continue;}
		for(set<int> :: iterator j = st.begin();j!= st.end();j++){
			mn = min(abs(i+1- *j),mn);
		}
		cout<<mn<<" ";

	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;cin>>n;
	int arr[200002];
	set<int>st;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		if(arr[i] == 0) st.insert(i+1);
	}
	for(int i=0;i<n;i++){
		int mn = 1e7;
		if(arr[i] == 0) {cout<<0<<" ";continue;}
		for(set<int> :: iterator j = st.begin();j!= st.end();j++){
			mn = min(abs(i+1- *j),mn);
		}
		cout<<mn<<" ";

	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int ans[200002]={0};
void fill(){
	for(int i=0;i<100;i++) ans[i] = 1e7;
}
int main() {fill();
	int n;cin>>n;
	int arr[200002];

	queue<int>q;
	stack<int>st;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		if(arr[i] == 0) q.push(i), st.push(i);
	}
	for(int i=0;i<n;i++){
		if(q.size() != 0){
		if(q.front() >= i ) ans[i] = q.front()-i;
		else {
			q.pop();
			if(q.size() !=0)
			ans[i] = q.front()-i;
			}
		}
	}

	for(int i=n-1;i>=0;i--){
		if(st.size() != 0){
		if(st.top() <= i ) ans[i] = min(ans[i],i-st.top());
		else {
			st.pop();
			if(st.size() !=0)
			ans[i] = min(ans[i],i-st.top());
			}
		}
	}

	for(int i=0;i<n;i++)
	cout<<ans[i]<<"  ";

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;cin>>n;
	int arr[200002];
	set<int>st;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		if(arr[i] == 0) st.insert(i+1);
	}
	for(int i=0;i<n;i++){
		int mn = 1e7;
		if(arr[i] == 0) {cout<<0<<" ";continue;}
		for(set<int> :: iterator j = st.begin();j!= st.end();j++){
			mn = min(abs(i+1- *j),mn);
		}
		cout<<mn<<" ";

	}

	return 0;
}


#include "cstdio"
#include "iostream"
#include "sstream"
#include "algorithm"
#include "string"
#include "cstring"
#include "queue"
#include "cmath"
#include "vector"
#define inf 0x3f3f3f
#define mj
#define db double
#define ll long long
using  namespace std;
const int N=2e6+5;
const int mod=1e9+7;
int a[N],f[N];
int main()
{
    int n;
    int p=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]==0) f[p++]=i;
    }
    int v=0;
    for(int i=0;i<n;i++){
        if(a[i]!=0) {
            a[i]=abs(f[v]-i);
            if(v+1<p) a[i]=min(a[i],abs(f[v+1]-i));
            if(v-1>=0) a[i]=min(a[i],abs(f[v-1]-i));
        }
        else v++;
    }
    printf("%d",a[0]);
    for(int i=1;i<n;i++){
        printf(" %d",a[i]);
    }
    return 0;
}


#include "cstdio"
#include "iostream"
#include "sstream"
#include "algorithm"
#include "string"
#include "cstring"
#include "queue"
#include "cmath"
#include "vector"
#define inf 0x3f3f3f
#define mj
#define db double
#define ll long long
using  namespace std;
const int N=1e5+5;
const int mod=1e9+7;
int a[N],f[N];
int main()
{
    int n;
    int p=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]==0) f[p++]=i;
    }
    int v=0;
    for(int i=0;i<n;i++){
        if(a[i]!=0) {
            if(v+1<p) a[i]=min(abs(f[v]-i),abs(f[v+1]-i));
            if(v-1>=0) a[i]=min(abs(f[v]-i),abs(f[v-1]-i));
            a[i]=min(abs(f[v]-i),a[i]);
        }
        else v++;
    }
    printf("%d",a[0]);
    for(int i=1;i<n;i++){
        printf(" %d",a[i]);
    }
    return 0;
}


#include "cstdio"
#include "iostream"
#include "sstream"
#include "algorithm"
#include "string"
#include "cstring"
#include "queue"
#include "cmath"
#include "vector"
#define inf 0x3f3f3f
#define mj
#define db double
#define ll long long
using  namespace std;
const int N=1e5+5;
const int mod=1e9+7;
int a[N],f[N];
int main()
{
    int n;
    int p=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]==0) f[p++]=i;
    }
    int v=0;
    for(int i=0;i<n;i++){
        if(a[i]!=0) {
            if(v+1<p&&v-1>=0){
                a[i]=min(min(abs(f[v]-i),abs(f[v+1]-i)),abs(f[v-1]-i));
            }
            else
            {
                if(v+1<p) a[i]=min(abs(f[v]-i),abs(f[v+1]-i));
                else if(v-1>=0) a[i]=min(abs(f[v]-i),abs(f[v-1]-i));
                else  a[i]=abs(f[v]-i);
            }
        }
        else v++;
    }
    printf("%d",a[0]);
    for(int i=1;i<n;i++){
        printf(" %d",a[i]);
    }
    return 0;
}


#include "cstdio"
#include "iostream"
#include "sstream"
#include "algorithm"
#include "string"
#include "cstring"
#include "queue"
#include "cmath"
#include "vector"
#define inf 0x3f3f3f
#define mj
#define db double
#define ll long long
using  namespace std;
const int N=1e5+5;
const int mod=1e9+7;
int a[N],f[N];
int main()
{
    int n;
    int p=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]==0) f[p++]=i;
    }
    int v=0;
    for(int i=0;i<n;i++){
        if(a[i]!=0) {
            if(v+1<p) a[i]=min(abs(f[v]-i),abs(f[v+1]-i));
            else if(v-1>=0) a[i]=min(abs(f[v]-i),abs(f[v-1]-i));
            else  a[i]=abs(f[v]-i);
        }
        else v++;
    }
    printf("%d",a[0]);
    for(int i=1;i<n;i++){
        printf(" %d",a[i]);
    }
    return 0;
}


#include "cstdio"
#include "iostream"
#include "sstream"
#include "algorithm"
#include "string"
#include "cstring"
#include "queue"
#include "cmath"
#include "vector"
#define inf 0x3f3f3f
#define mj
#define db double
#define ll long long
using  namespace std;
const int N=1e5+5;
const int mod=1e9+7;
int a[N],f[N];
int main()
{
    int n;
    int p=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]==0) f[p++]=i;
    }
    int v=0;
    for(int i=0;i<n;i++){
        if(a[i]!=0) {
            if(v+1<p&&v-1>=0) a[i]=min(min(abs(f[v]-i),abs(f[v+1]-i)),abs(f[v-1]-i));
            else if(v+1<p) a[i]=min(abs(f[v]-i),abs(f[v+1]-i));
            else if(v-1>=0) a[i]=min(abs(f[v]-i),abs(f[v-1]-i));
            else  a[i]=abs(f[v]-i);
        }
        else v++;
    }
    printf("%d",a[0]);
    for(int i=1;i<n;i++){
        printf(" %d",a[i]);
    }
    return 0;
}


#include "cstdio"
#include "iostream"
#include "sstream"
#include "algorithm"
#include "string"
#include "cstring"
#include "queue"
#include "cmath"
#include "vector"
#define inf 0x3f3f3f
#define mj
#define db double
#define ll long long
using  namespace std;
const int N=1e5+5;
const int mod=1e9+7;
int a[N],f[N];
int main()
{
    int n;
    int p=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]==0) f[p++]=i;
    }
    int v=0;
    for(int i=0;i<n;i++){
        if(a[i]!=0) {
            a[i]=abs(f[v]-i);
            if(v+1<p) a[i]=min(a[i],abs(f[v+1]-i));
            if(v-1>=0) a[i]=min(a[i],abs(f[v-1]-i));
        }
        else v++;
    }
    printf("%d",a[0]);
    for(int i=1;i<n;i++){
        printf(" %d",a[i]);
    }
    return 0;
}


#include<iostream>
using namespace std;

int a;
int tab[((int)(2e5))+1];
int out[((int)(2e5))+1];
int zeropos=-1;
int firstzero=-1;

int main()
{
    cin>>a;
    for(int i=0;i<a;i++)
    {
        cin>>tab[i];
        if(tab[i]==0)
        {
            zeropos = i;
        }

        if(firstzero == -1)
        {
            if(tab[i]==0)
            {
                firstzero = i+1;
            }
        }

        if(zeropos!=-1)
        {
            out[i] = i-zeropos;
        }
    }
    for(int i=0;i<firstzero;i++)
    {
        out[i] = (firstzero-1)-i;
    }
    for(int i=0;i<a;i++)
    {
        cout<<out[i]<<" ";
    }
    return 0;
}


#include<iostream>
using namespace std;

int a;
int tab[((int)(2e5))+1];
int out[((int)(2e5))+1];
int zeropos=-1;
int firstzero=-1;

int main()
{
    cin>>a;
    for(int i=0;i<a;i++)
    {
        cin>>tab[i];
    }
    for(int i=0;i<a;i++)
    {
        if(tab[i]==0)
        {
            zeropos = i;
        }

        if(zeropos != -1)
        {
            out[i] = i - zeropos;
        }
    }
    zeropos = -1;
    for(int i=a;i>0;i--)
    {
        if(tab[i]==0)
        {
            zeropos = i;
        }

        if(zeropos != -1)
        {
            if(i - zeropos < out[i])
            {
                out[i] = zeropos - i;
            }
        }
    }
    for(int i=0;i<a;i++)
    {
        cout<<out[i]<<" ";
    }
    return 0;
}


#include<iostream>
#include<cmath>
using namespace std;

int a;
int tab[((int)(2e5))+1];
int out[((int)(2e5))+1];
int zeropos=-1;
int firstzero=-1;

int main()
{
    cin>>a;
    for(int i=0;i<a;i++)
    {
        cin>>tab[i];
    }
    for(int i=0;i<a;i++)
    {
        if(tab[i]==0)
        {
            zeropos = i;
        }

        if(zeropos != -1)
        {
            out[i] = i - zeropos;
        }
    }
    for(int i=zeropos;i>=0;i--)
    {
        if(tab[i]==0)
        {
            zeropos = i;
        }

        if(zeropos != -1)
        {
            if(i - zeropos < out[i])
            {
                out[i] = zeropos - i;
            }
        }
    }
    for(int i=0;i<a;i++)
    {
        if(tab[i]==0)
        {
            zeropos = i;
        }

        if(zeropos != -1)
        {
            if(i - zeropos < out[i])
            {
                out[i] = abs(zeropos - i);
            }
        }
    }
    for(int i=0;i<a;i++)
    {
        cout<<out[i]<<" ";
    }
    return 0;
}


#include<iostream>
using namespace std;

int a;
int tab[((int)(2e5))+1];
int out[((int)(2e5))+1];
int zeropos=-1;
int firstzero=-1;

int main()
{
    cin>>a;
    for(int i=0;i<a;i++)
    {
        cin>>tab[i];
    }
    for(int i=0;i<a;i++)
    {
        if(tab[i]==0)
        {
            zeropos = i;
        }

        if(zeropos != -1)
        {
            out[i] = i - zeropos;
        }
    }
    zeropos = -1;
    for(int i=a;i>=0;i--)
    {
        if(tab[i]==0)
        {
            zeropos = i;
        }

        if(zeropos != -1)
        {
            if(i - zeropos < out[i])
            {
                out[i] = zeropos - i;
            }
        }
    }
    for(int i=0;i<a;i++)
    {
        cout<<out[i]<<" ";
    }
    return 0;
}


#include<iostream>
using namespace std;

int a;
int tab[((int)(2e5))+1];
int out[((int)(2e5))+1];
int zeropos=-1;
int firstzero=-1;

int main()
{
    cin>>a;
    for(int i=0;i<a;i++)
    {
        cin>>tab[i];
    }
    for(int i=0;i<a;i++)
    {
        if(tab[i]==0)
        {
            zeropos = i;
        }

        if(zeropos != -1)
        {
            out[i] = i - zeropos;
        }
    }
    for(int i=zeropos;i>=0;i--)
    {
        if(tab[i]==0)
        {
            zeropos = i;
        }

        if(zeropos != -1)
        {
            if(i - zeropos < out[i])
            {
                out[i] = zeropos - i;
            }
        }
    }
    for(int i=0;i<a;i++)
    {
        cout<<out[i]<<" ";
    }
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;

int main()
{int n,a[200008],i,j,k,b[200008];
 cin>>n;
 k=-1;
 for(i=0;i<n;i++)
 {cin>>a[i];
  if(a[i]==0)
   b[++k]=i;
 }
 while(i<=b[0])
 {a[i]=b[0]-i;
  i++;
 }
 j=0;
 while(i<=b[k])
 {for(i=b[j]+1;i<=b[j+1]-1;i++)
  {a[i]=min(i-b[j],b[j+1]-i);
  }
 }
 for(i=b[k]+1;i<n;i++)
  a[i]=i-b[k];

  for(i=0;i<n;i++)
   cout<<a[i]<<" ";
  return 0;
}

/*→Judgement Protocol
Test: #1, time: 0 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: COMPILATION_ERROR
Input
9
2 1 0 3 0 0 3 2 4
Checker Log
Can't compile file:
program.cpp: In function 'int main()':
program.cpp:12:8: error: 'c' was not declared in this scope
   else c[b[k]]++;
        ^
program.cpp:28:14: error: expected ';' before string constant
    cout<<a[i]" ";
              ^~~
close*/


 #include<iostream>
using namespace std;

int main()
{int n,a[200008],i,j,k,b[200008];
 cin>>n;
 k=-1;
 for(i=0;i<n;i++)
 {cin>>a[i];
  if(a[i]==0)
   b[++k]=i;
 }
 i=0;
 while(i<=b[0])
 {a[i]=b[0]-i;
  i++;
 }
 j=0;
 while(i<=b[k])
 {for(i=b[j]+1;i<=b[j+1]-1;i++)
  {a[i]=min(i-b[j],b[j+1]-i);
  }
  j++;
 }
 for(i=b[k]+1;i<n;i++)
  a[i]=i-b[k];

  for(i=0;i<n;i++)
   cout<<a[i]<<" ";
  return 0;
}

/*Judgement Protocol
Test: #1, time: 0 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: COMPILATION_ERROR
Input
9
2 1 0 3 0 0 3 2 4
Checker Log
Can't compile file:
program.cpp: In function 'int main()':
program.cpp:12:8: error: 'c' was not declared in this scope
   else c[b[k]]++;
        ^
program.cpp:28:14: error: expected ';' before string constant
    cout<<a[i]" ";
              ^~~
close*/


#include<iostream>
#include<cmath>
using namespace std;

int main()
{int n,a[200008],i,j,k;
 cin>>n;
 for(i=0;i<n;i++)
  cin>>a[i];
 for(i=0;i<n;i++)
 {j=i;
  k=i;
  while(1)
  {if(j>=0)
   {if(a[j]==0)
    {a[i]=abs(i-j);
     break;
    }
    else j--;
   }
   if(k<n)
   {if(a[k]==0)
    {a[i]=abs(i-k);
     break;
    }
    else k++;
   }
  }
 }
 for(i=0;i<n;i++)
  cout<<a[i]<<" ";
 return 0;
}


 #include<iostream>
using namespace std;

int main()
{int n,a[200008],i,j,k,b[200008];
 cin>>n;
 k=-1;
 for(i=0;i<n;i++)
 {cin>>a[i];
  if(a[i]==0)
   b[++k]=i;
 }
 while(i<=b[0])
 {a[i]=b[0]-i;
  i++;
 }
 j=0;
 while(i<=b[k])
 {for(i=b[j]+1;i<=b[j+1]-1;i++)
  {a[i]=min(i-b[j],b[j+1]-i);
  }
 }
 for(i=b[k]+1;i<n;i++)
  a[i]=i-b[k];

  for(i=0;i<n;i++)
   cout<<a[i]<<" ";
  return 0;
}

/*→Judgement Protocol
Test: #1, time: 0 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: COMPILATION_ERROR
Input
9
2 1 0 3 0 0 3 2 4
Checker Log
Can't compile file:
program.cpp: In function 'int main()':
program.cpp:12:8: error: 'c' was not declared in this scope
   else c[b[k]]++;
        ^
program.cpp:28:14: error: expected ';' before string constant
    cout<<a[i]" ";
              ^~~
close*/


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, s;
	cin >> n;
	vector <int> a(n, 200004);
	for (int i = 0; i < n; i++)
	{
		cin >> s;
		if (s == 0)
			for (int j = 0; j < n; j++)
				if (a[j] > 1) a[j] = min(a[j], abs(j - i));
	}
	for (int i = 0; i < n; i++) cout << a[i] << ' ';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, s, l = 0, r;
    cin >> n;
    vector <int> a(n, n);
    for (int i = 0; i < n; i++)
    {
        cin >> s;
	if (s == 0)
        {
	    for (int j = l; j < n; j++)
		if (a[j]>0 && a[j]>abs(j-i)) a[j]=abs(j-i);
            l = i;
        }
    }
    for (int i = 0; i < n; i++) cout << a[i] << ' ';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, s;
	cin >> n;
	vector <int> a(n);
	vector <bool> nil(n, 0);
	for (int i = 0; i < n; i++)
	{
		cin >> s;
		if (s == 0) nil[i] = 1;
		a[i] = 200004;
	}
	int m = 200004;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
		    if (nil[j])
		    {
		    	m = min(m, abs(i - j));
			    a[i] = m;
	    	}
		}
		m = 200004;
	}
	for (int i = 0; i < n; i++) cout << a[i] << ' ';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, s;
	cin >> n;
	vector <int> a(n, n);
	for (int i = 0; i < n; i++)
	{
		cin >> s;
		if (s == 0)
			for (int j = 0; j < n; j++)
				if (a[j] > 0 && a[j] > abs(j - i)) a[j] = abs(j - i);
	}
	for (int i = 0; i < n; i++) cout << a[i] << ' ';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, s;
	cin >> n;
	vector <int> a(n);
	vector <bool> nil(n, 0);
	for (int i = 0; i < n; i++)
	{
		a[i] = 200004;
		cin >> s;
		if (s == 0) nil[i] = 1, a[i] = 0;
	}
	int m = 200004;
	for (int i = 0; i < n; i++)
	{
		if (a[i] != 0)
		{
		    for (int j = 0; j < n; j++)
		    {
		        if (nil[j])
		        {
		    	    m = min(m, abs(i - j));
			        a[i] = m;
	    	    }
		    }
		    m = 200004;
		}
	}
	for (int i = 0; i < n; i++) cout << a[i] << ' ';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, s, l = 0;
	queue <int> q;
	cin >> n;
	int qq = n;
	vector <int> a(n, n);
	for (int i = 0; i < n; i++) q.push(i);
	for (int i = 0; i < n; i++)
	{
		cin >> s;
		if (s == 0)
		{
			for (int j = 0; j < qq; j++)
			{
				int k = q.front();
				if (a[k] > abs(i - k)) a[k] = abs(k - i);
				if (a[k] != 0) q.push(k);
				else l++;
				q.pop();
	        }
	        qq -= l;
	        l = 0;
		}
	}
	for (int i = 0; i < n; i++) cout << a[i] << ' ';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, s;
	cin >> n;
	vector <int> a(n, 200004);
	for (int i = 0; i < n; i++)
	{
		cin >> s;
		if (s == 0)
			for (int j = 0; j < n; j++)
				if (a[j] > 0) a[j] = min(a[j], abs(j - i));
	}
	for (int i = 0; i < n; i++) cout << a[i] << ' ';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, s;
	cin >> n;
	vector <int> a(n, 200004);
	for (int i = 0; i < n; i++)
	{
		cin >> s;
		if (s == 0)
			for (int j = 0; j < n; j++) a[j] = min(a[j], abs(j - i));
	}
	for (int i = 0; i < n; i++) cout << a[i] << ' ';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int n, t, r;
	cin >> n;
	vector <int> a(n);
	queue <int> q;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		if (a[i] == 0) q.push(i);
	}
	t = q.front();
	q.pop();
	r = n * 2;
	if (!q.empty()){
		r = q.front();
	    q.pop();
	}
	for (int i = 0; i < n; i++){
		if (i <= t) cout << t - i;
		else if (i > t && i < r) cout << min(i - t, r - i);
		else{
			cout << i - r;
			t = r;
			r = n * 2;
			if (!q.empty()){
			    r = q.front();
			    q.pop();
			}
		}
		cout << ' ';
	}
	return 0;
}


  #include <bits/stdc++.h>
  using namespace std;

  #define vi vector<int>
  #define all(v) v.begin(),v.end()
  #define ll long long int
  #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
  #define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}

  const ll MOD=1e9+7;

  void solve(){
     int n;
     cin >> n;
     vi v(n),ans(n);
     int lst = INT_MAX;
     for(int i=0;i<n;i++){
        cin >> v[i];
        if(v[i]==0)lst=i+1;
        else ans[i]=(lst==INT_MAX?INT_MAX:i+1-lst);
     }
     lst =INT_MAX;
     for(int i=n-1;i>=0;i--){
        if(v[i]==0)lst=i+1;
        else ans[i]=min(ans[i],lst-i-1);

     }
     for(int x:ans){
       cout <<x <<' ';
    }
  }

  int main(){
    IOS
       solve();
       cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


  #include <bits/stdc++.h>
  using namespace std;

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  D(x)         cout << #x << " - " << x << endl;
  #define  D2(x)        cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]" << endl;
  #define  all(x)       (x).begin(), (x).end()
  #define  D2p(x)       cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << endl;
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;

  void solve(){
    int n;
    cin >> n;
    vll v(n);
    vll ans(n,INT_MAX);
    ll lstz = INT_MIN;
    for(int i=0;i<n;i++)
    	cin >> v[i];
    for(ll i=0;i<n;i++){
    	if(v[i]==0)lstz=i;
    	else{
    	   ans[i] = min(ans[i],i-lstz);
    	}
    }

    lstz = INT_MAX;
    for(ll i=n-1;i>=0;i--){
    	if(v[i]==0)lstz = i,ans[i]=0;
    	else{
    		ans[i] = min(ans[i],lstz-i);
    	}
    }
    for(int x:ans)cout << x << ' ';
  }

  int main(){
    IOS
    solve();
    cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


  #include <bits/stdc++.h>
  using namespace std;

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  D(x)         cout << #x << " - " << x << endl;
  #define  D2(x)        cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]" << endl;
  #define  all(x)       (x).begin(), (x).end()
  #define  D2p(x)       cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << endl;
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;

  void solve(){
    int n;
    cin >> n;
    vll v(n);
    vi ans(n,INT_MAX);
    int lstz = -n-10;
    for(int i=0;i<n;i++)
    	cin >> v[i];
    for(int i=0;i<n;i++){
    	if(v[i]==0)lstz=i;
    	else{
    	   ans[i] = min(ans[i],i-lstz);
    	}
    }

    lstz = n+10;
    for(int i=n-1;i>=0;i--){
    	if(v[i]==0)lstz = i,ans[i]=0;
    	else{
    		ans[i] = min(ans[i],lstz-i);
    	}
    }
    for(int x:ans)cout << x << ' ';
  }

  int main(){
    IOS
    solve();
    cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


  #include <bits/stdc++.h>
  using namespace std;

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  D(x)         cout << #x << " - " << x << endl;
  #define  D2(x)        cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]" << endl;
  #define  all(x)       (x).begin(), (x).end()
  #define  D2p(x)       cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << endl;
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;

  void solve(){
    int n;
    cin >> n;
    vi v(n);
    vi ans(n,n+10);
    int lstz = -10;
    for(int i=0;i<n;i++){
    	cin >> v[i];
    	if(v[i]==0)lstz=i;
    	else{
    	   ans[i] = min(ans[i],i-lstz);
    	}
    }
    lstz = n+10;
    for(int i=n-1;i>=0;i--){
    	if(v[i]==0)lstz = i,ans[i]=0;
    	else{
    		ans[i] = min(ans[i],lstz-i);
    	}
    }
    for(int x:ans)cout << x << ' ';
  }

  int main(){
    IOS
    solve();
    cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


#include <cstdio>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define INF 1000000001

int n;
vll zeros, a, b;

int main(int argc, char** argv) {
	scanf("%d", &n);
	a.clear(); a.resize(n); b.clear(); b.assign(n, INF); zeros.resize(1); zeros[0] = -1;
	for (int i = 0; i < n; i++){
		scanf("%I64d", &a[i]);
		if (!a[i]){
			zeros.push_back(i);
			for (int j = i-1; j > zeros[zeros.size()-2]; j--){
				b[j] = abs(i-j) < b[j] ? abs(i-j) : b[j];
			}
		}
	}

	if (zeros.size() < 2){
		printf("%I64d", a[0]);
		for (int i = 1; i < n; i++){
			printf(" %I64d", a[i]);
		}
		printf("\n");
		return 0
	}

	for (int i = zeros.back()+1; i < n ; i++){
		b[i] = abs(i-zeros.back()) < b[i] ? abs(i-zeros.back()) : b[i];
	}
	printf("%I64d", b[0]);
	for (int i = 1; i < b.size(); i++)printf(" %I64d", b[i]);
	printf("\n");
	return 0;
}


#include <cstdio>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define INF 1000000001

int n;
vll zeros, a, b;

int main(int argc, char** argv) {
	scanf("%d", &n);
	a.clear(); a.resize(n); b.clear(); b.assign(n, INF); zeros.resize(1); zeros[0] = -1;
	for (int i = 0; i < n; i++){
		scanf("%I64d", &a[i]);
		if (!a[i]){
			b[i] = a[i];
			zeros.push_back(i);
		}
	}

	if (zeros.size() < 2){
		printf("%I64d", a[0]);
		for (int i = 1; i < n; i++){
			printf(" %I64d", a[i]);
		}
		printf("\n");
		return 0;
	}
	zeros.push_back(n);
	for (int j = 1; j < zeros.size()-1; j++){
		for (int i = zeros[j]; i < n && i < zeros[j+1]; i++){
			b[i] = abs(i-zeros[j]) < b[i] ? abs(i-zeros[j]) : b[i];
		}
		for (int i = zeros[j]; i > -1 && i > zeros[j-1]; i--){
			b[i] = abs(i-zeros[j]) < b[i] ? abs(i-zeros[j]) : b[i];
		}
	}
	printf("%I64d", b[0]);
	for (int i = 1; i < b.size(); i++)printf(" %I64d", b[i]);
	printf("\n");
	return 0;
}


#include <cstdio>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define INF 1000000001

int n;
vll zeros, a, b;

int main(int argc, char** argv) {
	scanf("%d", &n);
	a.clear(); a.resize(n); b.clear(); b.assign(n, INF); zeros.resize(1); zeros[0] = -1;
	for (int i = 0; i < n; i++){
		scanf("%I64d", &a[i]);
		b[i] = abs(a[i]);
		if (!a[i]){
			zeros.push_back(i);
			for (int j = i-1; j > zeros[zeros.size()-2]; j--){
				b[j] = abs(i-j) < b[j] ? abs(i-j) : b[j];
			}
		}
	}

	for (int i = zeros.back()+1; i < n ; i++){
		b[i] = abs(i-zeros.back()) < b[i] ? abs(i-zeros.back()) : b[i];
	}
	printf("%I64d", b[0]);
	for (int i = 1; i < b.size(); i++)printf(" %I64d", b[i]);
	printf("\n");
	return 0;
}


#include <cstdio>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define INF 1000000001

int n;
vll zeros, a, b;

int main(int argc, char** argv) {
	scanf("%d", &n);
	a.clear(); a.resize(n); b.clear(); b.assign(n, INF); zeros.resize(1); zeros[0] = -1;
	for (int i = 0; i < n; i++){
		scanf("%I64d", &a[i]);
		if (!a[i]){
			b[i] = 0;
			zeros.push_back(i);
			for (int j = i-1; j > zeros[zeros.size()-2]; j--){
				b[j] = abs(i-j) < b[j] ? abs(i-j) : b[j];
			}
		}
	}
	for (int i = zeros.back()+1; i < n; i++){
		b[i] = abs(i-zeros.back()) < b[i] ? abs(i-zeros.back()) : b[i];
	}
	printf("%I64d", b[0]);
	for (int i = 1; i < b.size(); i++)printf(" %I64d", b[i]);
	printf("\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,co=0;
    scanf("%d",&n);
int   arr[200005],a[200005];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
        if(arr[i]==0)
        {
            a[co]=i;
            co++;
        }
    }

    for(int i=a[0];i>=1;i--)
    {
        printf("%d ",i);
    }

    for(int i=0;i<co-1;i++)
    {
        int total = a[i]+a[i+1];
        int mid = total/2;
        if(total%2==0)
        {
            int mm = 0;
            for(int j=a[i];j<=mid;j++)
            {
                printf("%d ",mm);
                mm++;
            }
            int m = mm -2;
            for(int j = mid+1;j<a[i+1];j++)
            {
                printf("%d ",m);
                m--;
            }
        }
        else
        {
            int mm = 0;
            for(int j=a[i];j<=mid;j++)
            {
                printf("%d ",mm);
                mm++;
            }
            int m = mm-1 ;
            for(int j = mid+1;j<a[i+1];j++)
            {
                printf("%d ",m);
                m--;
            }
        }
    }
    int dis = 0;
    for(int i=a[co-1];i<n;i++)
    {
        printf("%d ",dis);
        dis++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j=0,z,co=0;
    scanf("%d",&n);
int    arr[100],a[100],s1[100],minn,ans[100];
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
        if(arr[i]==0)
        {
            a[co]=i;
            co++;
        }
    }

    for(int i=a[0];i>=1;i--)
    {
        printf("%d ",i);
    }

    for(int i=0;i<co-1;i++)
    {
        int total = a[i]+a[i+1];
        int mid = total/2;
        if(total%2==0)
        {
            int mm = 0;
            for(int j=a[i];j<=mid;j++)
            {
                printf("%d ",mm);
                mm++;
            }
            int m = mid -1;
            for(int j = mid+1;j<a[i+1];j++)
            {
                printf("%d ",m);
                m--;
            }

        }
        else
        {

            int mm = 0;
            for(int j=a[i];j<=mid;j++)
            {
                printf("%d ",mm);
                mm++;
            }
            int m = mid ;
            for(int j = mid+1;j<a[i+1];j++)
            {
                printf("%d ",m);
                m--;
            }
        }
    }
    int dis = 0;
    for(int i=a[co-1];i<n;i++)
    {
        printf("%d ",dis);
        dis++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,co=0;
    scanf("%d",&n);
int   arr[200005],a[200005];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
        if(arr[i]==0)
        {
            a[co]=i;
            co++;
        }
    }
    for(int i=a[0];i>=1;i--)
    {
        printf("%d ",i);
    }
    for(int i=0;i<co-1;i++)
    {
        int dis = 0;
        int total = a[i]+a[i+1];
        int mid = total/2;
        if(total%2==0)
        {
            for(int j=a[i];j<=mid;j++)
            {
                printf("%d ",dis);
                dis++;
            }
            dis = dis -2;
            for(int j = mid+1;j<a[i+1];j++)
            {
                printf("%d ",dis);
                dis--;
            }
        }
        else
        {

            for(int j=a[i];j<=mid;j++)
            {
                printf("%d ",dis);
                dis++;
            }
            dis=  dis-1 ;
            for(int j = mid+1;j<a[i+1];j++)
            {
                printf("%d ",dis);
                dis--;
            }
        }
    }
    int dis = 0;
    for(int i=a[co-1];i<n;i++)
    {
        printf("%d ",dis);
        dis++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,co=0;
    scanf("%d",&n);
int   arr[200005],a[200005];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
        if(arr[i]==0)
        {
            a[co]=i;
            co++;
        }
    }

    for(int i=a[0];i>=1;i--)
    {
        printf("%d ",i);
    }

    for(int i=0;i<co-1;i++)
    {
        int total = a[i]+a[i+1];
        int mid = total/2;
        if(total%2==0)
        {
            int mm = 0;
            for(int j=a[i];j<=mid;j++)
            {
                printf("%d ",mm);
                mm++;
            }
            int m = mid -1;
            for(int j = mid+1;j<a[i+1];j++)
            {
                printf("%d ",m);
                m--;
            }
        }
        else
        {
            int mm = 0;
            for(int j=a[i];j<=mid;j++)
            {
                printf("%d ",mm);
                mm++;
            }
            int m = mid ;
            for(int j = mid+1;j<a[i+1];j++)
            {
                printf("%d ",m);
                m--;
            }
        }
    }
    int dis = 0;
    for(int i=a[co-1];i<n;i++)
    {
        printf("%d ",dis);
        dis++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j=0,z,co=0;
    scanf("%d",&n);
int    arr[100],a[100],s1[100],minn,ans[100];
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
        if(arr[i]==0)
        {
            a[co]=i;
     //       printf("%d ",a[co]);
            co++;
        }
    }

       for(i=0;i<n;i++)
       {
           minn = INT_MAX;
         for(z=0;z<co;z++)
         {
            int temp=abs(a[z]-i);
             if(temp<minn)
             {
                 minn=temp;
             }

         }
             cout<<minn<<" ";

       }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sil1(a) scanf("%lld",&a)
#define sil2(a,b) scanf("%lld%lld",&a,&b)
#define sil3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define pi1(a) printf("%d\n",a)
#define pi2(a,b) printf("%d%d",a,b)
#define pi3(a,b,c) printf("%d%d%d",a,b,c)
#define pil1(a) printf("%lld\n",a)
#define pil2(a,b) printf("%lld%lld",a,b)
#define pil3(a,b,c) printf("%lld%lld%lld",a,b,c)
#define dd double
using namespace std;
int main()
{
int i,j,k,n,m,pos;
vector<int>v,v1;
si1(n);
for(i=0;i<n;i++){
    si1(j);
    v.pb(j);
    if(j==0){
        v1.pb(i);
    }
}
int a[100005];
for(i=0;i<n;i++){
    if(v[i]==0){
        a[i]=0;
    }
    else {
        if(i<v1[0]){
            a[i]=v1[0]-i;
        }
        else if(i>v1[v1.size()-1]){
            a[i]=i-v1[v1.size()-1];
        }
        else {
            pos=upper_bound(v1.begin(),v1.end(),i)-v1.begin()-1;
            a[i]=min(abs(v1[pos]-i),abs(v1[pos+1]-i));
        }
    }

}
for(i=0;i<n;i++){
    printf("%d ",a[i]);
}

printf("\n");

    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sil1(a) scanf("%lld",&a)
#define sil2(a,b) scanf("%lld%lld",&a,&b)
#define sil3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define pi1(a) printf("%d\n",a)
#define pi2(a,b) printf("%d%d",a,b)
#define pi3(a,b,c) printf("%d%d%d",a,b,c)
#define pil1(a) printf("%lld ",a)
#define pil2(a,b) printf("%lld%lld",a,b)
#define pil3(a,b,c) printf("%lld%lld%lld",a,b,c)
#define dd double
using namespace std;
ll dist[200005];
int main()
{
    ll i,j,k,n,e1;
    sil1(n);
    for(i=0;i<200005;i++){
        dist[i]=1e10;
    }
    vector<ll>v;
    for(i=0;i<n;i++){
        sil1(j);
        v.pb(j);
    }
    queue<ll>q;
    for(i=0;i<n;i++){
        if(v[i]==0){
            q.push(i);
            dist[i]=0;
        }
    }
    while(!q.empty()){
        e1=q.front();
        q.pop();
        if(e1+1<n&&dist[e1+1]>dist[e1]+1){
            dist[e1+1]=dist[e1]+1;
            q.push(e1+1);
        }
        if(e1-1>=0&&dist[e1-1]>dist[e1]+1){
            dist[e1-1]=dist[e1]+1;
            q.push(e1-1);
        }
    }
    for(i=0;i<n;i++){
        pil1(dist[i]);
    }
    printf("\n");

    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sil1(a) scanf("%lld",&a)
#define sil2(a,b) scanf("%lld%lld",&a,&b)
#define sil3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define pi1(a) printf("%d\n",a)
#define pi2(a,b) printf("%d%d",a,b)
#define pi3(a,b,c) printf("%d%d%d",a,b,c)
#define pil1(a) printf("%lld\n",a)
#define pil2(a,b) printf("%lld%lld",a,b)
#define pil3(a,b,c) printf("%lld%lld%lld",a,b,c)
#define dd double
using namespace std;
int main()
{
int i,j,k,n,m,pos;
vector<int>v,v1;
si1(n);
for(i=0;i<n;i++){
    si1(j);
    v.pb(j);
    if(j==0){
        v1.pb(i);
    }
}
int a[200005];
for(i=0;i<n;i++){
  if(v[i]==0){
    a[i]=0;
    k=i;
  }
  else if(i<v1[0]){
    a[i]=v1[0]-i;
  }
  else {
    a[i]=i-k;
  }
}
for(i=n-1;i>=0;i--){
  if(v[i]==0){
    a[i]=0;
    k=i;
  }
  else if(i>v1[v1.size()-1]){
    a[i]=i-v1[v1.size()-1];
  }
  else {
    a[i]=min(a[i],k-i);
  }
}
for(i=0;i<n;i++){
    printf("%d ",a[i]);
}

printf("\n");

    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sil1(a) scanf("%lld",&a)
#define sil2(a,b) scanf("%lld%lld",&a,&b)
#define sil3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define pi1(a) printf("%d\n",a)
#define pi2(a,b) printf("%d%d",a,b)
#define pi3(a,b,c) printf("%d%d%d",a,b,c)
#define pil1(a) printf("%lld\n",a)
#define pil2(a,b) printf("%lld%lld",a,b)
#define pil3(a,b,c) printf("%lld%lld%lld",a,b,c)
#define dd double
using namespace std;
int main()
{
int i,j,k,n,m,pos;
vector<int>v,v1;
si1(n);
for(i=0;i<n;i++){
    si1(j);
    v.pb(j);
    if(j==0){
        v1.pb(i);
    }
}
int a[100005];
for(i=0;i<n;i++){
  if(v[i]==0){
    a[i]=0;
    k=i;
  }
  else if(i<v1[0]){
    a[i]=v1[0]-i;
  }
  else {
    a[i]=i-k;
  }
}
for(i=n-1;i>=0;i--){
  if(v[i]==0){
    a[i]=0;
    k=i;
  }
  else if(i>v1[v1.size()-1]){
    a[i]=i-v1[v1.size()-1];
  }
  else {
    a[i]=min(a[i],k-i);
  }
}
for(i=0;i<n;i++){
    printf("%d ",a[i]);
}

printf("\n");

    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sil1(a) scanf("%lld",&a)
#define sil2(a,b) scanf("%lld%lld",&a,&b)
#define sil3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define pi1(a) printf("%d\n",a)
#define pi2(a,b) printf("%d%d",a,b)
#define pi3(a,b,c) printf("%d%d%d",a,b,c)
#define pil1(a) printf("%lld\n",a)
#define pil2(a,b) printf("%lld%lld",a,b)
#define pil3(a,b,c) printf("%lld%lld%lld",a,b,c)
#define dd double
using namespace std;
int main()
{
int i,j,k,n,m,pos;
vector<int>v,v1;
si1(n);
for(i=0;i<n;i++){
    si1(j);
    v.pb(j);
    if(j==0){
        v1.pb(i);
    }
}
int a[200005];
for(i=0;i<n;i++){
    if(v[i]==0){
        a[i]=0;
    }
    else {
        if(i<v1[0]){
            a[i]=v1[0]-i;
        }
        else if(i>v1[v1.size()-1]){
            a[i]=i-v1[v1.size()-1];
        }
        else {
            pos=upper_bound(v1.begin(),v1.end(),i)-v1.begin()-1;
            a[i]=min(abs(v1[pos]-i),abs(v1[pos+1]-i));
        }
    }

}
for(i=0;i<n;i++){
    printf("%d ",a[i]);
}

printf("\n");

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>

using namespace std;

int getClose(vector<int> zeros, int idx) {
	int minElem = 1e9;
	for (int i = 0; i < zeros.size(); i++) {
		minElem = min(minElem, abs(zeros[i] - idx));
		if (idx <= zeros[i]) {
			break;
		}
	}

	return minElem;
}

int main() {

	int n;

	cin >> n;

	vector<int> arr(n);
	vector<int> dist(n);
	vector<int> zeros;

	for (int i = 0; i < n; i++) {
		cin >> arr[i];

		if (arr[i] == 0)
			zeros.push_back(i);
	}

	for (int i = 0; i < n; i++) {
		dist[i] = getClose(zeros, i);
	}

	for (int i = 0; i < n; i++) {
		cout << dist[i] << " ";
	}

	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>

using namespace std;

int main() {

	int n;

	cin >> n;

	vector<int> arr(n);
	vector<int> dist(n, 1e9);

	int lastZero = -1;
	int idxBefore = -1;
	int firstZero = -1;

	bool firstTime = true;

	for (int i = 0; i < n; i++) {
		cin >> arr[i];

		if (arr[i] == 0) {
			lastZero = i;

			if (firstTime) {
				idxBefore = i;
				firstZero = i;
				firstTime = false;
			}
		}

		if (lastZero != -1) {
			dist[i] = min(dist[i], abs(i - lastZero));
		}
	}

	for (int i = 0; i < idxBefore; i++) {
		dist[i] = abs(i - firstZero);
	}

	for (int i = 0; i < n; i++) {
		cout << dist[i] << " ";
	}

	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>

using namespace std;

int main() {

	int n;

	cin >> n;

	vector<int> arr(n);
	vector<int> dist(n, 1e9);

	int zeroIdx = -1;

	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	for (int i = 0; i < n; i++) {
		if (arr[i] == 0)
			zeroIdx = i;

		if (zeroIdx != -1) {
			dist[i] = min(abs(i - zeroIdx), dist[i]);
		}
	}

	for (int i = n - 1; i >= 0; i--) {
		if (arr[i] == 0)
			zeroIdx = i;

		if (zeroIdx != -1) {
			dist[i] = min(abs(i - zeroIdx), dist[i]);
		}
	}

	for (int i = 0; i < n; i++) {
		cout << dist[i] << " ";
	}

	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>

using namespace std;

int main() {

	int n;

	cin >> n;

	vector<int> arr(n);
	vector<int> dist(n, 1e9);

	int lastZero = -1;
	int idxBefore = -1;
	int firstZero = -1;

	bool firstTime = true;

	for (int i = 0; i < n; i++) {
		cin >> arr[i];

		if (arr[i] == 0) {
			lastZero = i;

			if (firstTime) {
				idxBefore = i;
				firstZero = i;
				firstTime = false;
			}
		}

		if (lastZero != -1) {
			dist[i] = min(dist[i], abs(i - lastZero));
		}
	}

	for (int i = 0; i < idxBefore; i++) {
		dist[i] = abs(i - firstZero);
	}

	for (int i = lastZero; i >= 0; i--) {
		dist[i] = min(dist[i], abs(i - lastZero));
		if (arr[i] == 0)
			lastZero = i;
	}

	for (int i = 0; i < n; i++) {
		cout << dist[i] << " ";
	}

	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>

using namespace std;

int main() {

	int n;

	cin >> n;

	vector<int> arr(n);
	vector<int> dist(n);

	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	for (int i = 0; i < n; i++) {
		int min = 1e9;

		for (int j = i; j < n; j++) {
			if (arr[j] == 0) {
				min = j - i;
				break;
			}
		}

		for (int j = i; j >= 0; j--) {
			if (arr[j] == 0) {
				min = std::min(i - j, min);
				break;
			}
		}

		dist[i] = min;
	}

	for (int i = 0; i < n; i++) {
		cout << dist[i] << " ";
	}

	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>

using namespace std;

int main() {

	int n;

	cin >> n;

	vector<int> arr(n);
	vector<int> dist(n);
	vector<int> zeros;

	for (int i = 0; i < n; i++) {
		cin >> arr[i];

		if (arr[i] == 0)
			zeros.push_back(i);
	}

	for (int i = 0; i < n; i++) {
		int min = 1e9;
		int j = 0;
		bool found = false;

		for (; j < zeros.size(); j++) {
			if (zeros[j] >= i) {
				found = true;
				break;
			}
		}

		if (!found) {
			dist[i] = abs(i - zeros[j - 1]);
		}
		else {
			dist[i] = abs(i - zeros[j]);

			if (j - 1 != 0)
				dist[i] = std::min(abs(i - zeros[j - 1]), dist[i]);
		}
	}

	for (int i = 0; i < n; i++) {
		cout << dist[i] << " ";
	}

	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>

using namespace std;

int main() {

	int n;

	cin >> n;

	vector<int> arr(n);
	vector<int> dist(n, 1e9);

	int lastZero = -1;
	int idxBefore = -1;
	int firstZero = -1;

	bool firstTime = true;
	bool stop = false;

	for (int i = 0; i < n; i++) {
		cin >> arr[i];

		if (arr[i] == 0) {
			lastZero = i;

			if (firstTime) {
				idxBefore = i;
				firstZero = i;
				firstTime = false;
			}
		}

		if (lastZero != -1) {
			dist[i] = min(dist[i], abs(i - lastZero));
		}
	}

	for (int i = 0; i < idxBefore; i++) {
		dist[i] = abs(i - firstZero);
	}

	for (int i = lastZero; i >= 0; i--) {
		dist[i] = min(dist[i], abs(i - lastZero));
		if (arr[i] == 0 && stop)
			break;
		stop = true;
	}

	for (int i = 0; i < n; i++) {
		cout << dist[i] << " ";
	}

	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>

int main()
{
	int n;
	std::cin >> n;
	int* mass = new int[n];
	std::vector<int> zero;
	for(int i = 0; i < n; i++)
	{
		std::cin >> mass[i];
		if(mass[i] == 0)
		{
			zero.push_back(i);
		}
	}

	int j = 0;
	for(int i = 0; i < zero[0]; i++)
		mass[i] = zero[j] - i;
	for(int i = zero[0]; i < zero[zero.size()-1]; i++)
	{
		if(mass[i] == 0)
		{
			j++;
		}
		else
		{
			if(zero[j] - i < i - zero[j-1])
				mass[i] = zero[j] - i;
			else
				mass[i] = i - zero[j-1];
		}
	}
	for(int i = zero[zero.size()-1]; i < n; i++)
		mass[i] = i - zero[zero.size() - 1];
	for(int i = 0; i < n; i++)
	std::cout << mass[i] << ' ';

	return 0;
}


#include <iostream>
#include <vector>

int main()
{
	int n;
	std::cin >> n;
	int* mass = new int[n];
	std::vector<int> zero;
	for(int i = 0; i < n; i++)
	{
		std::cin >> mass[i];
		if(mass[i] == 0)
		{
			zero.push_back(i);
		}
	}

	int j = 0;
	for(int i = 0; i < zero[0]; i++)
		mass[i] = zero[j] - i;
	for(int i = zero[0]; i < zero.size() - 1; i++)
	{
		if(mass[i] == 0)
		{
			j++;
		}
		else
		{
			if(zero[j] - i < i - zero[j-1])
				mass[i] = zero[j] - i;
			else
				mass[i] = i - zero[j-1];
		}
	}
	for(int i = zero[zero.size()-1]; i < n; i++)
		mass[i] = i - zero[zero.size() - 1];
	for(int i = 0; i < n; i++)
	std::cout << mass[i];

	return 0;
}


#include <iostream>
#include <vector>

int main()
{
	int n;
	std::cin >> n;
	int* mass = new int[n];
	std::vector<int> zero;
	for(int i = 0; i < n; i++)
	{
		std::cin >> mass[i];
		if(mass[i] == 0)
		{
			zero.push_back(i);
		}
	}

	int j = 0;
	for(int i = 0; i < zero[0]; i++)
		mass[i] = zero[j] - i;
	for(int i = zero[0]; i < zero[zero.size()-1]; i++)
	{
		if(mass[i] == 0)
		{
			j++;
		}
		else
		{
			if(zero[j] - i < i - zero[j-1])
				mass[i] = zero[j] - i;
			else
				mass[i] = i - zero[j-1];
		}
	}
	for(int i = zero[zero.size()-1] - 2; i < n; i++)
		mass[i] = i - zero[zero.size() - 1];
	for(int i = 0; i < n; i++)
	std::cout << mass[i];

	return 0;
}


#include <iostream>

void counter(int *arr, int l, int r, int n)
{
    int a, b;
    if ((l > 1) && (r < n-2))
    {
        a = l-1;
        b = r+1;

        for (int i = l; i <= r; i++)
        {
            arr[i] = std::min(i - a, b - i);
        }
    }
    else if ((l == 0) && (r < n-2))
    {
        b = r+1;
        for (int i = 0; i <= r; i++)
        {
            arr[i] = b - i;
        }
    }
    else if ((l > 0) && (r == n - 1))
    {
        for (int i = 1; i < n; i++)
        {
            arr[i] = i;
        }
    }
    else if ((l > 1) && (r > n-2))
    {
        a = l-1;
        for (int i = l; i < n; i++)
        {
            arr[i] = i - a;
        }
        std::cout << '!' << '\n';
    }
}

void print(int* arr, int n)
{
    for (int i = 0; i < n; i++)
    {
        std::cout << arr[i] << " ";
    }

    std::cout << '\n';
}

int main() {
    int n;
    std::cin >> n;
    int *arr = new int[n];

    for (int i = 0; i < n; i++)
    {
        std::cin >> arr[i];
    }

    bool left_0 = false, right_0 = false;
    int l = 0;
    if (arr[0] == 0)
    {
        left_0 = true;
    }

    for (int i = 1; i < n; i++)
    {
        if (arr[i] == 0)
        {
            if (left_0 == false)
            {
                counter(arr, 0, i-1, n);
                left_0 = true;
                l = i;
            }
            else if(i - l == 1)
            {
                l = i;
                continue;
            }
            else
            {
                counter(arr, l+1, i-1, n);
                l = i;
            }
        }
        else if ((left_0 == true) && (i == n-1))
        {
            counter(arr, l+1, i, n);
        }
    }

    print(arr, n);
    return 0;
}


#include <iostream>
#include <vector>

int main()
{
	int n;
	std::cin >> n;
	int* mass = new int[n];
	std::vector<int> zero;
	for(int i = 0; i < n; i++)
	{
		std::cin >> mass[i];
		if(mass[i] == 0)
		{
			zero.push_back(i);
		}
	}

	int j = 0;
	for(int i = 0; i < zero[0]; i++)
		mass[i] = zero[j] - i;
	for(int i = zero[0]; i < zero.size() - 1; i++)
	{
		if(mass[i] == 0)
		{
			j++;
		}
		else
		{
			if(zero[j] - i < i - zero[j-1])
				mass[i] = zero[j] - i;
			else
				mass[i] = i - zero[j-1];
		}
	}
	for(int i = zero.size() - 2; i < n; i++)
		mass[i] = i - zero[zero.size() - 1];
	for(int i = 0; i < n; i++)
	std::cout << mass[i]  << ' ';

	return 0;
}


#include <iostream>

void counter(int *arr, int l, int r, int n)
{
    int a, b;
    if ((l > 1) && (r < n-2))
    {
        a = l-1;
        b = r+1;

        for (int i = l; i <= r; i++)
        {
            arr[i] = std::min(i - a, b - i);
        }
    }
    else if ((l == 0) && (r < n-2))
    {
        b = r+1;
        for (int i = 0; i <= r; i++)
        {
            arr[i] = b - i;
        }
    }
    else if ((l > 1) && (r > n-2))
    {
        a = l-1;
        for (int i = l; i < n; i++)
        {
            arr[i] = i - a;
        }
    }
}

void print(int* arr, int n)
{
    for (int i = 0; i < n; i++)
    {
        std::cout << arr[i] << " ";
    }

    std::cout << '\n';
}

int main() {
    int n;
    std::cin >> n;
    int *arr = new int[n];

    for (int i = 0; i < n; i++)
    {
        std::cin >> arr[i];
    }

    bool left_0 = false, right_0 = false;
    int l = 0;
    if (arr[0] == 0)
    {
        left_0 = true;
    }

    for (int i = 0; i < n; i++)
    {
        if (arr[i] == 0)
        {
            if (left_0 == false)
            {
                counter(arr, 0, i-1, n);
                left_0 = true;
                l = i;
            }
            else if(i - l == 1)
            {
                l = i;
                continue;
            }
            else
            {
                counter(arr, l+1, i-1, n);
                l = i;
            }
        }
        else if ((left_0 == true) && (i == n-1))
        {
            counter(arr, l+1, i, n);
        }
    }

    print(arr, n);
    return 0;
}


#include <iostream>
#include <vector>

int main()
{
	int n;
	std::cin >> n;
	int* mass = new int[n];
	std::vector<int> zero;
	for(int i = 0; i < n; i++)
	{
		std::cin >> mass[i];
		if(mass[i] == 0)
		{
			zero.push_back(i);
		}
	}

	int j = 0;
	for(int i = 0; i < zero[0]; i++)
		mass[i] = zero[j] - i;
	for(int i = zero[0]; i < zero[zero.size() - 1]; i++)
	{
		if(mass[i] == 0)
		{
			j++;
		}
		else
		{
			if(zero[j] - i < i - zero[j-1])
				mass[i] = zero[j] - i;
			else
				mass[i] = i - zero[j-1];
		}
	}
	for(int i = zero.size() - 2; i < n; i++)
		mass[i] = i - zero[zero.size() - 1];
	for(int i = 0; i < n; i++)
	std::cout << mass[i];

	return 0;
}


#include <iostream>
#include <vector>

int main()
{
    int n;
    std::cin >> n;
    int *arr = new int[n];
    std::vector<int> myV;

    for (int i = 0; i < n; i++)
    {
        int buf;
        std::cin >> buf;
        arr[i] = buf;
        if (buf == 0)
        {
            myV.push_back(i);
        }
    }

    int dist = 0;
    int l_i = 0, r_i = 0;

    for (int i = 0; i < n; i++)
    {
        if (arr[i] != 0)//нули пропускаем
        {
          if ((i < myV[l_i]) && (r_i <= l_i)) //мы левее левой границы, а правая еще не определена
          {
              arr[i] = myV[l_i] - i;
          }

          if (i > myV[l_i]) //пересекли левую границу
          {
              if (r_i <= l_i) //правая еще не определена
              {
                  if (l_i == myV.size() - 1) //чтобы не выйти за вектор
                  {
                    arr[i] = i - myV[l_i];
                  }
                  else
                  {
                    r_i = l_i + 1;
                    arr[i] = std::min(i - myV[l_i], myV[r_i] - i);
                  }
              }
              else //правая граница уже есть
              {
                if (i > myV[r_i]) //пересекли правую границу
                {
                    if (r_i == myV.size() - 1) //чтобы не выйти за вектор
                    {
                        arr[i] = i - myV[r_i];
                    }
                    else
                    {
                        while((myV[r_i] < i) && (r_i != myV.size() - 1)) //чтобы не взять повторяющиеся 0
                        {
                            r_i ++;
                        }
                        l_i = r_i - 1;
                        if (myV[r_i] < i)
                        {
                            arr[i] = i - myV[r_i];
                        }
                        else
                        {
                            arr[i] = std::min(i - myV[l_i], myV[r_i] - i);
                        }
                    }
                }
              }
          }
        }
    }

    for (int i = 0; i < n; i++)//вывод на экран
    {
        std::cout << arr[i] << ' ';
    }

    return 0;
}


#include <iostream>
#include <vector>

int main()
{
	int n;
	std::cin >> n;
	int* mass = new int[n];
	std::vector<int> zero;
	for(int i = 0; i < n; i++)
	{
		std::cin >> mass[i];
		if(mass[i] == 0)
		{
			zero.push_back(i);
		}
	}

	int j = 0;
	for(int i = 0; i < zero[0]; i++)
		mass[i] = zero[j] - i;
	for(int i = zero[0]; i < zero.size() - 1; i++)
	{
		if(mass[i] == 0)
		{
			j++;
		}
		else
		{
			if(zero[j] - i < i - zero[j-1])
				mass[i] = zero[j] - i;
			else
				mass[i] = i - zero[j-1];
		}
	}
	for(int i = zero.size() - 2; i < n; i++)
		mass[i] = i - zero[zero.size() - 1];
	for(int i = 0; i < n; i++)
	std::cout << mass[i];

	return 0;
}


#include <iostream>

void counter(int *arr, int l, int r, int n)
{
    int a, b;
    if ((l > 1) && (r < n-2))
    {
        a = l-1;
        b = r+1;

        for (int i = l; i <= r; i++)
        {
            arr[i] = std::min(i - a, b - i);
        }
    }
    else if ((l == 0) && (r < n-2))
    {
        b = r+1;
        for (int i = 0; i <= r; i++)
        {
            arr[i] = b - i;
        }
    }
    else if ((l == 1) && (r == n - 1))
    {
        for (int i = 1; i < n; i++)
        {
            arr[i] = i;
        }
    }
    else if ((l > 1) && (r > n-2))
    {
        a = l-1;
        for (int i = l; i < n; i++)
        {
            arr[i] = i - a;
        }
    }
}

void print(int* arr, int n)
{
    for (int i = 0; i < n; i++)
    {
        std::cout << arr[i] << " ";
    }

    std::cout << '\n';
}

int main() {
    int n;
    std::cin >> n;
    int *arr = new int[n];

    for (int i = 0; i < n; i++)
    {
        std::cin >> arr[i];
    }

    bool left_0 = false, right_0 = false;
    int l = 0;
    if (arr[0] == 0)
    {
        left_0 = true;
    }

    for (int i = 1; i < n; i++)
    {
        if (arr[i] == 0)
        {
            if (left_0 == false)
            {
                counter(arr, 0, i-1, n);
                left_0 = true;
                l = i;
            }
            else if(i - l == 1)
            {
                l = i;
                continue;
            }
            else
            {
                counter(arr, l+1, i-1, n);
                l = i;
            }
        }
        else if ((left_0 == true) && (i == n-1))
        {
            counter(arr, l+1, i, n);
        }
    }

    print(arr, n);
    return 0;
}


#include <iostream>

void counter(int *arr, int l, int r, int n)
{
    int a, b;
    if ((l > 1) && (r < n-2))
    {
        a = l-1;
        b = r+1;

        for (int i = l; i <= r; i++)
        {
            arr[i] = std::min(i - a, b - i);
        }
    }
    else if ((l == 0) && (r < n-2))
    {
        b = r+1;
        for (int i = 0; i <= r; i++)
        {
            arr[i] = b - i;
        }
    }
    else if ((l == 0) && (r == n - 2))
    {
        for (int i = 0; i <= r; i++)
        {
            arr[i] = r+1 - i;
        }
    }
    else if ((l == 1) && (r == n - 1))
    {
        for (int i = 1; i < n; i++)
        {
            arr[i] = i;
        }
    }
    else if ((l > 1) && (r > n-2))
    {
        a = l-1;
        for (int i = l; i < n; i++)
        {
            arr[i] = i - a;
        }
    }
}

void print(int* arr, int n)
{
    for (int i = 0; i < n; i++)
    {
        std::cout << arr[i] << " ";
    }

    std::cout << '\n';
}

int main() {
    int n;
    std::cin >> n;
    int *arr = new int[n];

    for (int i = 0; i < n; i++)
    {
        std::cin >> arr[i];
    }

    bool left_0 = false, right_0 = false;
    int l = 0;
    if (arr[0] == 0)
    {
        left_0 = true;
    }

    for (int i = 1; i < n; i++)
    {
        if (arr[i] == 0)
        {
            if (left_0 == false)
            {
                counter(arr, 0, i-1, n);
                left_0 = true;
                l = i;
            }
            else if(i - l == 1)
            {
                l = i;
                continue;
            }
            else
            {
                counter(arr, l+1, i-1, n);
                l = i;
            }
        }
        else if ((left_0 == true) && (i == n-1))
        {
            counter(arr, l+1, i, n);
        }
    }

    print(arr, n);
    return 0;
}


#include <iostream>
#include <vector>

int main()
{
	int n;
	std::cin >> n;
	int* mass = new int[n];
	std::vector<int> zero;
	for(int i = 0; i < n; i++)
	{
		std::cin >> mass[i];
		if(mass[i] == 0)
		{
			zero.push_back(i);
		}
	}

	int j = 0;
	for(int i = 0; i < zero[0]; i++)
		mass[i] = zero[j] - i;
	for(int i = zero[0]; i < zero.size() - 1; i++)
	{
		if(mass[i] == 0)
		{
			j++;
		}
		else
		{
			if(zero[j] - i < i - zero[j-1])
				mass[i] = zero[j] - i;
			else
				mass[i] = i - zero[j-1];
		}
	}
	for(int i = zero[zero.size()-1]; i < n; i++)
		mass[i] = i - zero[zero.size() - 1];
	for(int i = 0; i < n; i++)
	std::cout << mass[i] << ' ';

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) rbegin(v),rend(v)
#define see(x) cout<<(#x)<<" -> "<<(x)<<"\n"
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define fr(a,b) for(int i=a;i<b;i++)
#define frv(v) for(int i=0;i<_sz(v);i++)
#define fr1(b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
    nimble;
    int tt=1;cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        vector<ll> a(n);
        ll s=0;
        ll x=0;
        frv(a){cin>>a[i];s+=a[i];x=x^a[i];}
        if(x==0){
            cout<<1<<nl;
            cout<<s<<nl;
            continue;
        }
        if(s==2*x){
            cout<<0<<nl;
            cout<<nl;
            continue;
        }
        ll tmp=1000000000*100000000;
        if(s>2*x){
            if(s&1){
                cout<<3<<nl;
                ll xxxx=(tmp+1ll);
                cout<<xxxx<<" ";
                s+=(tmp+1ll);
                x^=(tmp+1ll);
                cout<<abs(2*x-s)/2<<" "<<abs(2*x-s)/2<<nl;
                continue;
            }
            cout<<3<<nl;
            ll xxxx=(tmp);
            cout<<xxxx<<" ";
            s+=(tmp);
            x^=(tmp);
            cout<<abs(2*x-s)/2<<" "<<abs(2*x-s)/2<<nl;
            continue;
        }
        if(s&1){
            s+=1;
            x=x^1;
            if(x==0){
                cout<<2<<nl;
                cout<<1<<" "<<s<<nl;
                continue;
            }
            if(s==2*x){
                cout<<1<<nl;
                cout<<1<<nl;
                continue;
            }
            if(s<2*x){
                cout<<3<<nl;
                cout<<1<<" "<<(2*x-s)/2<<" "<<(2*x-s)/2<<nl;
                continue;
            }
        }
        if(s<2*x){
            cout<<2<<nl;
            cout<<(2*x-s)/2<<" "<<(2*x-s)/2<<nl;
            continue;
        }
        cout<<"PLS HACK MY CODE XD..."<<nl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) rbegin(v),rend(v)
#define see(x) cout<<(#x)<<" -> "<<(x)<<"\n"
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define fr(a,b) for(int i=a;i<b;i++)
#define frv(v) for(int i=0;i<_sz(v);i++)
#define fr1(b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
    nimble;
    int tt=1;cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        vector<ll> a(n);
        ll s=0;
        ll x=0;
        frv(a){cin>>a[i];s+=a[i];x=x^a[i];}
        if(x==0){
            cout<<1<<nl;
            cout<<s<<nl;
            continue;
        }
        if(s==2*x){
            cout<<0<<nl;
            cout<<nl;
            continue;
        }
        if(s>2*x){
            cout<<3<<nl;
            cout<<100000000*x<<" ";
            s+=100000000*x;
            x^=(100000000*x);
            cout<<(2*x-s)/2<<" "<<(2*x-s)/2<<nl;
            continue;
        }
        if(s&1){
            s+=1;
            x=x^1;
            if(s<2*x){
                cout<<3<<nl;
                cout<<1<<" "<<(2*x-s)/2<<" "<<(2*x-s)/2<<nl;
                continue;
            }
        }
        if(s<2*x){
            cout<<2<<nl;
            cout<<(2*x-s)/2<<" "<<(2*x-s)/2<<nl;
            continue;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) rbegin(v),rend(v)
#define see(x) cout<<(#x)<<" -> "<<(x)<<"\n"
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define fr(a,b) for(int i=a;i<b;i++)
#define frv(v) for(int i=0;i<_sz(v);i++)
#define fr1(b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
    nimble;
    int tt=1;cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        vector<ll> a(n);
        ll s=0;
        ll x=0;
        frv(a){cin>>a[i];s+=a[i];x=x^a[i];}
        while(s>2*x){
            s+=x<<1;
            x^=(2*(x<<1));
            if(x==0){
                break;
            }
        }
        if(x==0){
            cout<<1<<nl;
            cout<<s<<nl;
            continue;
        }
        if(s==2*x){
            cout<<0<<nl;
            continue;
        }
        if(s&1){
            s+=1;
            x=x^1;
        }
        if(s<2*x){
            cout<<3<<nl;
            cout<<1<<" "<<(2*x-s)/2<<" "<<(2*x-s)/2<<nl;
            continue;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) rbegin(v),rend(v)
#define see(x) cout<<(#x)<<" -> "<<(x)<<"\n"
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define fr(a,b) for(int i=a;i<b;i++)
#define frv(v) for(int i=0;i<_sz(v);i++)
#define fr1(b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
    nimble;
    int tt=1;cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        vector<ll> a(n);
        ll s=0;
        ll x=0;
        frv(a){cin>>a[i];s+=a[i];x=x^a[i];}
        if(x==0){
            cout<<1<<nl;
            cout<<s<<nl;
            continue;
        }
        if(s==2*x){
            cout<<0<<nl;
            cout<<nl;
            continue;
        }
        ll tmp=1000000000*100000000;
        if(s>2*x){
            if(s&1){
                cout<<3<<nl;
                cout<<(tmp+1ll)^x<<" ";
                s+=(tmp+1ll)^x;
                x^=((tmp+1ll)^x);
                cout<<(2*x-s)/2<<" "<<(2*x-s)/2<<nl;
                continue;
            }
            cout<<3<<nl;
            cout<<(tmp)^x<<" ";
            s+=(tmp)^x;
            x^=((tmp)^x);
            cout<<(2*x-s)/2<<" "<<(2*x-s)/2<<nl;
            continue;
        }
        if(s&1){
            s+=1;
            x=x^1;
            if(x==0){
                cout<<2<<nl;
                cout<<1<<" "<<s<<nl;
                continue;
            }
            if(s==2*x){
                cout<<1<<nl;
                cout<<1<<nl;
                continue;
            }
            if(s<2*x){
                cout<<3<<nl;
                cout<<1<<" "<<(2*x-s)/2<<" "<<(2*x-s)/2<<nl;
                continue;
            }
        }
        if(s<2*x){
            cout<<2<<nl;
            cout<<(2*x-s)/2<<" "<<(2*x-s)/2<<nl;
            continue;
        }
        cout<<"PLS HACK MY CODE XD..."<<nl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) rbegin(v),rend(v)
#define see(x) cout<<(#x)<<" -> "<<(x)<<"\n"
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define fr(a,b) for(int i=a;i<b;i++)
#define frv(v) for(int i=0;i<_sz(v);i++)
#define fr1(b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
    nimble;
    int tt=1;cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        vector<ll> a(n);
        ll s=0;
        ll x=0;
        frv(a){cin>>a[i];s+=a[i];x=x^a[i];}
        if(x==0){
            cout<<1<<nl;
            cout<<s<<nl;
            continue;
        }
        if(s==2*x){
            cout<<0<<nl;
            cout<<nl;
            continue;
        }
        ll tmp=1000000000*1000000;
        tmp/=x;
        if(s>2*x){
            if(s&1){
                cout<<3<<nl;
                cout<<1ll*(tmp*x+1ll)<<" ";
                s+=1ll*(tmp*x+1ll);
                x^=(1ll*tmp*x+1ll);
                cout<<(2*x-s)/2<<" "<<(2*x-s)/2<<nl;
                continue;
            }
            cout<<3<<nl;
            cout<<1ll*tmp*x<<" ";
            s+=1ll*tmp*x;
            x^=(1ll*tmp*x);
            cout<<(2*x-s)/2<<" "<<(2*x-s)/2<<nl;
            continue;
        }
        if(s&1){
            s+=1;
            x=x^1;
            if(x==0){
                cout<<2<<nl;
                cout<<1<<" "<<s<<nl;
                continue;
            }
            if(s==2*x){
                cout<<1<<nl;
                cout<<1<<nl;
                continue;
            }
            if(s<2*x){
                cout<<3<<nl;
                cout<<1<<" "<<(2*x-s)/2<<" "<<(2*x-s)/2<<nl;
                continue;
            }
        }
        if(s<2*x){
            cout<<2<<nl;
            cout<<(2*x-s)/2<<" "<<(2*x-s)/2<<nl;
            continue;
        }
        cout<<"PLS HACK MY CODE XD..."<<nl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) rbegin(v),rend(v)
#define see(x) cout<<(#x)<<" -> "<<(x)<<"\n"
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define fr(a,b) for(int i=a;i<b;i++)
#define frv(v) for(int i=0;i<_sz(v);i++)
#define fr1(b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
    nimble;
    int tt=1;cin>>tt;
    while(tt--){
        int n;
        cin>>n;
        vector<ll> a(n);
        ll s=0;
        ll x=0;
        frv(a){cin>>a[i];s+=a[i];x=x^a[i];}
        if(x==0){
            cout<<1<<nl;
            cout<<s<<nl;
            continue;
        }
        if(s==2*x){
            cout<<0<<nl;
            cout<<nl;
            continue;
        }
        ll tmp=1ll*1000000000*1000000000;
        ll gg=tmp+s%2;
        s+=gg;
        x^=gg;
        cout<<3<<nl;
        cout<<gg<<" "<<(2*x-s)/2<<" "<<(2*x-s)/2<<nl;
    }
    return 0;
}