Buggy python submission (verdict: Time Limit Exceeded):
# # by Quarz
# # generator
#
# import random
#
# ri = random.randint
#
#
# def randomArray(x, y, n):
#     ret = []
#     for i in range(n):
#         ret.append(ri(x, y))
#     return ret
#
#
# def pr(a):
#     file.write(str(a).replace(" ", "").replace("\'", "\"") + '\n')
#
#
# def randomDag(n, m):
#     permutation = [i for i in range(n)]
#     random.shuffle(permutation)
#
#     added_edges = set()
#     # indeg = [0 for _ in range(n)]
#     for i in range(n-1):
#         # print(m // (n-1))
#         rem = ri(1, max(1, min(n-i-1, m // (n-1))))
#         while rem != 0:
#             j = ri(i+1, n-1)
#             u = permutation[i]
#             v = permutation[j]
#             if (u, v) in added_edges: continue
#             # indeg[v] += 1
#             added_edges.add((u, v))
#             rem -= 1
#
#
#     # print(indeg)
#     # print([min(1, indeg[i]) ^ 1 for i in range(n)])
#     # cnt = sum([min(1, indeg[i]) ^ 1 for i in range(n)])
#     # print(cnt)
#
#     # add remaining edges
#     loop = 0
#     while len(added_edges) < m and loop < 10**3:
#         loop += 1
#         u = ri(0, n-2)
#         v = ri(u+1, n-1)
#         u = permutation[u]
#         v = permutation[v]
#         # if indeg[v] == 0: continue
#         if (u, v) in added_edges: continue
#         added_edges.add((u, v))
#         loop = 0
#
#     return [[x[0], x[1]] for x in added_edges]
#
#     #
#     # indeg = random.sample(permutation[1:n-1], ri(0, n-2))
#     # indeg.append(permutation[0])
#     #
#     #
#     # # make it connected
#     # for i in range(1, n):
#     #     u = permutation[ri(0, i-1)]
#     #     v = permutation[i]
#     #     # edges.append((u, v))
#     #     added_edges.add((u, v))
#     #
#     #
#
#
#
# with open('test2.txt', 'w') as file:
#     for i in range(20):
#         n = ri(2, 10)
#         m = ri(n-1, (n * (n-1)) // 2)
#         pr(n)
#         pr(str(randomDag(n, m)).replace(' ', ''))
#
#     for i in range(20):
#         n = ri(11, 50)
#         m = min(500, ri(n-1, (n * (n-1)) // 2))
#         pr(n)
#         pr(str(randomDag(n, m)).replace(' ', ''))
#
#     for i in range(10):
#         n = ri(50, 500)
#         m = min(1000, ri(n-1, (n * (n-1)) // 2))
#         pr(n)
#         pr(str(randomDag(n, m)).replace(' ', ''))
#     for i in range(10):
#         n = ri(500, 5000)
#         m = min(10**4, ri(n-1, (n * (n-1)) // 2))
#         pr(n)
#         pr(str(randomDag(n, m)).replace(' ', ''))
#     for i in range(2):
#         n = ri(5000, 10**4)
#         m = min(ri(2, 3) * n, ri(n-1, (n * (n-1)) // 2))
#         pr(n)
#         pr(str(randomDag(n, m)).replace(' ', ''))
#     for i in range(2):
#         n = ri(10**4, 10**4)
#         m = min(min(10**5, 2 * n), ri(n-1, (n * (n-1)) // 2))
#         pr(n)
#         pr(str(randomDag(n, m)).replace(' ', ''))
#     for i in range(1):
#         n = ri(10**5, 10**5)
#         m = min(10**5, ri(n-1, (n * (n-1)) // 2))
#         pr(n)
#         pr(str(randomDag(n, m)).replace(' ', ''))


import sys

input = sys.stdin.readline

n = int(input())
y = str(input())
ones = 0
for i in y:
    if i == '1': ones += 1
x = int(y, 2)

def get(z):
    ret = 0
    while z > 0:
        if z % 2 == 1:
            ret += 1
        z //= 2
    return ret

out = []
rem1 = -1
rem2 = -1
if ones > 1:
    rem1 = x % (ones - 1)
if ones < n:
    rem2 = x % (ones + 1)

for i in range(n):
    tmp = (1 << i) * -1
    o = ones - 1
    if y[n - i - 1] == '0':
        tmp = 1 << i
        o = ones + 1

    # tmp = tmp + x
    if o == 0:
        out.append(0)
        continue
    if o == 1:
        out.append(1)
        continue

    if o > ones:
        tmp = (rem2 % o + tmp % o) % o
    else:
        tmp = (rem1 % o + tmp % o) % o

    cnt = 1
    while tmp > 0:
        tmp %= get(tmp)
        cnt += 1

    out.append(cnt)

for i in range(n):
    print(out[n-i-1])


Fixed submission:
import sys

input = sys.stdin.readline

n = int(input())
y = str(input())
# n = 10**5
# y  = '1' * n
ones = 0
for i in y:
    if i == '1': ones += 1
x = int(y, 2)

def get(z):
    ret = 0
    while z > 0:
        if z % 2 == 1:
            ret += 1
        z //= 2
    return ret

out = []
rem1 = -1
rem2 = -1
if ones > 1:
    rem1 = x % (ones - 1)
if ones < n:
    rem2 = x % (ones + 1)

def calc(p, m):
    if p <= 2:
        return (1 << p) % m
    a = p // 2
    ret = calc(a, m)
    ret = (ret * ret) % m
    if p % 2 == 1:
        ret = (ret * 2) % m
    return ret



for i in range(n):
    # tmp = (1 << i) * -1
    o = ones - 1
    if y[n - i - 1] == '0':
        # tmp = 1 << i
        o = ones + 1

    # tmp = tmp + x
    if o == 0:
        out.append(0)
        continue
    if o == 1:
        out.append(1)
        continue


    if o > ones:
        tmp = (rem2 % o + calc(i, o)) % o
    else:
        tmp = (rem1 % o - calc(i, o) + o) % o


    cnt = 1
    while tmp > 0:
        tmp %= get(tmp)
        cnt += 1

    out.append(cnt)

for i in range(n):
    print(out[n-i-1])

Buggy python submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

n = int(input())
y = str(input())
ones = 0
for i in y:
    if i == '1': ones += 1
x = int(y, 2)

def get(z):
    ret = 0
    while z > 0:
        if z % 2 == 1:
            ret += 1
        z //= 2
    return ret

out = []
for i in range(n):
    tmp = (1 << i) * -1
    o = ones - 1
    if y[n - i - 1] == '0':
        tmp = 1 << i
        o = ones + 1

    tmp = tmp + x
    if tmp == 0:
        out.append(0)
    cnt = 1
    tmp %= o
    while tmp > 0:
        tmp %= get(tmp)
        cnt += 1

    out.append(cnt)

for i in range(n):
    print(out[n-i-1])


Fixed submission:
import sys

input = sys.stdin.readline

n = int(input())
y = str(input())
# n = 10**5
# y  = '1' * n
ones = 0
for i in y:
    if i == '1': ones += 1
x = int(y, 2)

def get(z):
    ret = 0
    while z > 0:
        if z % 2 == 1:
            ret += 1
        z //= 2
    return ret

out = []
rem1 = -1
rem2 = -1
if ones > 1:
    rem1 = x % (ones - 1)
if ones < n:
    rem2 = x % (ones + 1)

def calc(p, m):
    if p <= 2:
        return (1 << p) % m
    a = p // 2
    ret = calc(a, m)
    ret = (ret * ret) % m
    if p % 2 == 1:
        ret = (ret * 2) % m
    return ret



for i in range(n):
    # tmp = (1 << i) * -1
    o = ones - 1
    if y[n - i - 1] == '0':
        # tmp = 1 << i
        o = ones + 1

    # tmp = tmp + x
    if o == 0:
        out.append(0)
        continue
    if o == 1:
        out.append(1)
        continue


    if o > ones:
        tmp = (rem2 % o + calc(i, o)) % o
    else:
        tmp = (rem1 % o - calc(i, o) + o) % o


    cnt = 1
    while tmp > 0:
        tmp %= get(tmp)
        cnt += 1

    out.append(cnt)

for i in range(n):
    print(out[n-i-1])