"""
n is divisible by 2 ** i <=> the i suffix bits are 0
to meet the condition, we move 0s to the right
"""
for _ in range(int(input())):
n: int = int(input())
s: list[str] = list(input())
num0: int = len([x for x in s if x == "0"])
# it's impossible to make 0s suffix
if num0 == 0:
print(" ".join([str(-1) for i in range(n)]))
continue
# distance from the right
# we will move the 0s to the right
pos0: list[int] = []
for i in range(n):
if s[i] == "0":
pos0.append(n - i - 1)
# to make it easier to perform following operations
# pos0 = pos0[::-1] also works
pos0.sort()
# the first zero needs to go to the right most position to fill suffix with 0
# the second zero needs to go to the n - 1 position to fill the right corner with 0s
# the first zero already fills the rightmost cell, so the second moves to n - 1
# ...
for i in range(num0):
pos0[i] -= i
# sum array to not repeat the same calculation
sumarr: list[int] = [pos0[0]]
for i in range(1, num0):
sumarr.append(sumarr[-1] + pos0[i])
# padding. if the number of 0s needed exceeds 0s we have, it's impossible to meet the condition
for i in range(n - num0):
sumarr.append(-1)
print(" ".join([str(x) for x in sumarr]))
Kombucha 200 Protein shake 200 Salad 400 Rice 400 Mexican rice 500 Yogurt 200
Total 1900 kcal
pull-ups, 30 minutes walking, push-ups
MUST:
TODO: