### BUGGY CODE ###


n = int(input())
x = input()

# def main():
n_ansl = [0]*(n)
for i in range(1,n):
# for i in range(1,20):
    cnt = 0
    one = bin(i).count("1")
    rem = i
    while rem != 0:
        one = bin(rem).count("1")
        rem = rem%one   
        cnt += 1
    n_ansl[i] = cnt


one_cnt = x.count('1')
# if one_cnt == 0:
#     for _ in range(n):
#         print(1)
#     exit()

c2bl = [1]*n
c2blp = [1]*n
c2blm = [1]*n

curr_2b = 1
curr_2b_p = 1
curr_2b_m = 1
curr_sum = 0
curr_sum_p1 = 0
curr_sum_m1 = 0

x = x[::-1]
# for i in range(n-1, -1, -1):
for i, curr_x in enumerate(x):
    c2bl[i] = curr_2b
    c2blp[i] = curr_2b_p
    c2blm[i] = curr_2b_m
    if x[i] == '1':
        curr_sum += curr_2b
        curr_sum_p1 += curr_2b_p
        curr_sum_m1 += curr_2b_m
        if one_cnt >0:
            curr_sum%=one_cnt
        curr_sum_p1%=(one_cnt+1)
        if one_cnt > 1:
            curr_sum_m1%=(one_cnt-1)
    curr_2b*=2
    curr_2b_p*=2
    curr_2b_m*=2
    if one_cnt > 0:
        curr_2b%=one_cnt
    curr_2b_p%=(one_cnt+1)
    if one_cnt > 1:
        curr_2b_m%=(one_cnt-1)



    
curr_2b = 1
curr_2b_p = 1
curr_2b_m = 1
ansl = [0]*(n)
# for i in range(n-1, -1, -1):
for i, curr_x in enumerate(x):
    if x[i] == '1':
        # diff = (-1)*curr_2b_m
        diff = (-1)*c2blm[i]
        if one_cnt > 1:
            ans = (curr_sum_m1 + diff)%(one_cnt-1)
            ansl[n-i-1] = n_ansl[ans]+1
        else:
            ansl[n-i-1] = 0
    else:
        # diff = curr_2b_p
        diff = c2blp[i]
        ans = (curr_sum_p1 + diff)%(one_cnt+1)
        ansl[n-i-1] = (n_ansl[ans]+1)
    # curr_2b *= 2
    # curr_2b*=2
    # curr_2b_p*=2
    # curr_2b_m*=2
    # curr_2b%=one_cnt
    # curr_2b_p%=(one_cnt+1)
    # if one_cnt > 1:
    #     curr_2b_m%=(one_cnt-1)


# print(ansl)
for a in ansl:
    print(a)

# if __name__ == "__main__":
#     main()

### FIXED CODE ###

def main():
    n_ansl = [0]*(2*(10**5))
    for i in range(1,2*(10**5)):
    # for i in range(1,20):
        cnt = 0
        one_cnt = bin(i).count("1")
        rem = i
        while rem != 0:
            one_cnt = bin(rem).count("1")
            rem = rem%one_cnt   
            cnt += 1
        n_ansl[i] = cnt
 
    n = int(input())
    x = input()
    one_cnt = x.count('1')

    if one_cnt == 0:
        for i in range(n):
            print(1)
        exit()
    
    curr_2b = 1
    curr_2b_p = 1
    curr_2b_m = 1
    curr_sum = 0
    curr_sum_p1 = 0
    curr_sum_m1 = 0
    for i in range(n-1, -1, -1):
        if x[i] == '1':
            curr_sum += curr_2b
            curr_sum_p1 += curr_2b_p
            curr_sum_m1 += curr_2b_m
            curr_sum%=one_cnt
            curr_sum_p1%=(one_cnt+1)
            if one_cnt > 1:
                curr_sum_m1%=(one_cnt-1)
        curr_2b*=2
        curr_2b_p*=2
        curr_2b_m*=2
        curr_2b%=one_cnt
        curr_2b_p%=(one_cnt+1)
        if one_cnt > 1:
            curr_2b_m%=(one_cnt-1)
 
        
 
    curr_2b = 1
    curr_2b_p = 1
    curr_2b_m = 1
    ansl = [0]*(n)
    for i in range(n-1, -1, -1):
        if x[i] == '1':
            diff = (-1)*curr_2b_m
            if one_cnt > 1:
                ans = (curr_sum_m1 + diff)%(one_cnt-1)
                ansl[i] = n_ansl[ans]+1
            else:
                ansl[i] = 0
        else:
            diff = curr_2b_p
            ans = (curr_sum_p1 + diff)%(one_cnt+1)
            ansl[i] = (n_ansl[ans]+1)
        # curr_2b *= 2
        curr_2b*=2
        curr_2b_p*=2
        curr_2b_m*=2
        curr_2b%=one_cnt
        curr_2b_p%=(one_cnt+1)
        if one_cnt > 1:
            curr_2b_m%=(one_cnt-1)
 
 
    # print(ansl)
    for a in ansl:
        print(a)
 
if __name__ == "__main__":
    main()