import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

X = list(map(int, list(input())))
bit_num = sum(x==1 for x in X)
bp = [0]*N
bm = [0]*N
for i in range(N):
    if X[i]:
        bp[i] = pow(2, N-1-i, bit_num+1)
        bm[i] = pow(2, N-1-i, bit_num-1)
flag = sum(X) == 1
ans = [0]*N
for i in range(N):
    if X[i]:
        if flag:
            ans[i] = 0
            continue
        s = sum(bm)
        s -= bm[i]
        b = bit_num-1
        s %= b
        cnt = 1
        tmp = s
        nex = list(map(int, "{:b}".format(s)))
        b = sum(x==1 for x in nex)
        while tmp:
            for j in range(len(nex)):
                if nex[-(j+1)]:
                    tmp += pow(2, j, b)
                    tmp %= b
            nex = list(map(int, "{:b}".format(tmp)))
            b = sum(x==1 for x in nex)
            cnt += 1
    else:
        s = sum(bp)
        b = bit_num+1
        s += pow(2, N-i-1, bit_num+1)
        s %= b
        cnt = 1
        tmp = s
        nex = list(map(int, "{:b}".format(s)))
        b = sum(x==1 for x in nex)
        while tmp:
            for j in range(len(nex)):
                if nex[-(j+1)]:
                    tmp += pow(2, j, b)
                    tmp %= b
            nex = list(map(int, "{:b}".format(tmp)))
            b = sum(x==1 for x in nex)
            cnt += 1
    ans[i] = cnt

print(*ans, sep="\n")


### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# import random
# N = random.randint(0, 2*100000)
# X = ""
# for i in range(N):
#     if random.random() < 0.5:
#         X += "0"
#     else:
#         X += "1"
# print(N, X)


N = INT()
X = input()

def popcount(n):
    cnt = 0
    while n:
        n %= "{:b}".format(n).count("1")
        cnt += 1
    return cnt

pl = [0]*(N+1)
for i in range(N+1):
    pl[i] = popcount(i)
bn = X.count("1")

modp = [0]*N
modm = [0]*N

for i in range(N):
    if X[i] == "1":
        modp[i] = pow(2, N-1-i, bn+1)
        if not bn == 1:
            modm[i] = pow(2, N-1-i, bn-1)

sp = sum(modp)
sm = sum(modm)
ans = [0]*N
for i in range(N):
    if X[i] == "1":
        if bn == 1:
            ans[i] = 0
            continue
        s = sm
        s -= modm[i]
        s %= bn-1
        ans[i] = pl[s]+1
    else:
        s = sp
        s += pow(2, N-1-i, bn+1)
        s %= bn+1
        ans[i] = pl[s]+1

print(*ans, sep="\n")