n = int(eval(input()))

s = eval(input())

x = [int(i) for i in s]

pc = s.count('1')



def popcnt(x):

    x = x - ((x >> 1) & 0x5555555555555555)

    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f

    x = x + (x >> 8)

    x = x + (x >> 16)

    x = x + (x >> 32)

    return x & 0x0000007f



def f(x):

    if x == 0:

        return 0

    return f(x % popcnt(x)) + 1



ans = [0]*n

for a in range(2):

    npc = pc

    if a == 0:

        npc += 1

    else:

        npc -= 1

    

    if npc <= 0:

        continue

    

    r0 = 0

    for i in range(n):

        r0 = (r0*2) % npc

        r0 += x[i]



    k = 1

    for i in range(n-1, -1, -1):

        if x[i] == a:

            r = r0

            if a == 0:

                r = (r+k) % npc

            else:

                r = (r-k+npc) % npc

            ans[i] = f(r) + 1

        k = (k*2) % npc



for i in ans:

    print(i)
n = int(input())

s = input()

int_s = [int(i) for i in s]

pc = s.count('1')



def f(x):

    bi = bin(x)

    pc = bi.count('1')

    cnt = 1

    while True:

        if x == 0:

            break

        x = x % pc

        bi = bin(x)

        pc = bi.count('1')

        cnt += 1

    return cnt



num_pl = 0

for i in range(n):

    num_pl = (num_pl*2) % (pc+1)

    num_pl += int_s[i]



num_mi = 0

for i in range(n):

    if pc-1 <= 0:

        continue

    num_mi = (num_mi*2) % (pc-1)

    num_mi += int_s[i]



ans = [0]*n

pc_pl, pc_mi = pc+1, pc-1

r_pl, r_mi = 1, 1

for i in range(n-1, -1, -1):

    if int_s[i] == 0:

        num = num_pl

        num = (num+r_pl) % pc_pl

    else:

        num = num_mi

        if pc_mi <= 0:

            continue

        num = (num-r_mi+pc_mi) % pc_mi



    ans[i] = f(num)

    r_pl = (r_pl*2) % pc_pl

    if pc_mi <= 0:

        continue

    r_mi = (r_mi*2) % pc_mi

     

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

n = int(eval(input()))
s = eval(input())
x = [int(i) for i in s]
pc = s.count("1")


def popcnt(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007F


def f(x):
    if x == 0:
        return 0
    return f(x % popcnt(x)) + 1


ans = [0] * n
for a in range(2):
    npc = pc
    if a == 0:
        npc += 1
    else:
        npc -= 1
    if npc <= 0:
        continue
    r0 = 0
    for i in range(n):
        r0 = (r0 * 2) % npc
        r0 += x[i]
    k = 1
    for i in range(n - 1, -1, -1):
        if x[i] == a:
            r = r0
            if a == 0:
                r = (r + k) % npc
            else:
                r = (r - k + npc) % npc
            ans[i] = f(r) + 1
        k = (k * 2) % npc
for i in ans:
    print(i)

n = int(input())
s = input()
int_s = [int(i) for i in s]
pc = s.count("1")


def f(x):
    bi = bin(x)
    pc = bi.count("1")
    cnt = 1
    while True:
        if x == 0:
            break
        x = x % pc
        bi = bin(x)
        pc = bi.count("1")
        cnt += 1
    return cnt


num_pl = 0
for i in range(n):
    num_pl = (num_pl * 2) % (pc + 1)
    num_pl += int_s[i]
num_mi = 0
for i in range(n):
    if pc - 1 <= 0:
        continue
    num_mi = (num_mi * 2) % (pc - 1)
    num_mi += int_s[i]
ans = [0] * n
pc_pl, pc_mi = pc + 1, pc - 1
r_pl, r_mi = 1, 1
for i in range(n - 1, -1, -1):
    if int_s[i] == 0:
        num = num_pl
        num = (num + r_pl) % pc_pl
    else:
        num = num_mi
        if pc_mi <= 0:
            continue
        num = (num - r_mi + pc_mi) % pc_mi
    ans[i] = f(num)
    r_pl = (r_pl * 2) % pc_pl
    if pc_mi <= 0:
        continue
    r_mi = (r_mi * 2) % pc_mi
print(*ans, sep="\n")

-n = int(eval(input())) -s = eval(input()) -x = [int(i) for i in s] +n = int(input()) +s = input() +int_s = [int(i) for i in s] -def popcnt(x): -    x = x - ((x >> 1) & 0x5555555555555555) -    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) -    x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F -    x = x + (x >> 8) -    x = x + (x >> 16) -    x = x + (x >> 32) -    return x & 0x0000007F +def f(x): +    bi = bin(x) +    pc = bi.count("1") +    cnt = 1 +    while True: +        if x == 0: +            break +        x = x % pc +        bi = bin(x) +        pc = bi.count("1") +        cnt += 1 +    return cnt -def f(x): -    if x == 0: -        return 0 -    return f(x % popcnt(x)) + 1 - - +num_pl = 0 +for i in range(n): +    num_pl = (num_pl * 2) % (pc + 1) +    num_pl += int_s[i] +num_mi = 0 +for i in range(n): +    if pc - 1 <= 0: +        continue +    num_mi = (num_mi * 2) % (pc - 1) +    num_mi += int_s[i] -for a in range(2): -    npc = pc -    if a == 0: -        npc += 1 +pc_pl, pc_mi = pc + 1, pc - 1 +r_pl, r_mi = 1, 1 +for i in range(n - 1, -1, -1): +    if int_s[i] == 0: +        num = num_pl +        num = (num + r_pl) % pc_pl -        npc -= 1 -    if npc <= 0: +        num = num_mi +        if pc_mi <= 0: +            continue +        num = (num - r_mi + pc_mi) % pc_mi +    ans[i] = f(num) +    r_pl = (r_pl * 2) % pc_pl +    if pc_mi <= 0: -    r0 = 0 -    for i in range(n): -        r0 = (r0 * 2) % npc -        r0 += x[i] -    k = 1 -    for i in range(n - 1, -1, -1): -        if x[i] == a: -            r = r0 -            if a == 0: -                r = (r + k) % npc -            else: -                r = (r - k + npc) % npc -            ans[i] = f(r) + 1 -        k = (k * 2) % npc -for i in ans: -    print(i) +    r_mi = (r_mi * 2) % pc_mi +print(*ans, sep="\n")