Buggy python submission (verdict: Runtime Error):
N = int(input())
X = input()

cnt = 0
for i in range(N):
    if X[i] == "1":
        cnt += 1
    
down = [0] * N
up = [0] * N
ald = 0
alu = 0
for i in range(N):
    down[i] = pow(2, N-1-i, cnt-1)
    up[i] = pow(2, N-1-i, cnt+1)
    if X[i] == "1":
        ald += down[i]
        ald %= cnt-1
        alu += up[i]
        alu %= cnt+1

for i in range(N):
    if X[i] == "1":
        n = (ald - down[i]) % (cnt-1)
    else:
        n = (alu + up[i]) % (cnt+1)
    ans = 1
    while n != 0:
        c = 0
        for j in range(20):
            if (n >> j) % 2 == 1:
                c += 1
        n %= c
        ans += 1
    print(ans)
        
    
    

Fixed submission:
N = int(input())
X = input()

cnt = 0
for i in range(N):
    if X[i] == "1":
        cnt += 1
    
down = [0] * N
up = [0] * N
ald = 0
alu = 0
for i in range(N):
    up[i] = pow(2, N-1-i, cnt+1)
    if X[i] == "1":
        alu += up[i]
        alu %= cnt+1
    if cnt <= 1:
        continue
    down[i] = pow(2, N-1-i, cnt-1)
    if X[i] == "1":
        ald += down[i]
        ald %= cnt-1

for i in range(N):    
    if X[i] == "1":
        if cnt == 1:
            print(0)
            continue
        n = (ald - down[i]) % (cnt-1)
    else:
        n = (alu + up[i]) % (cnt+1)
    ans = 1
    while n != 0:
        c = 0
        for j in range(20):
            if (n >> j) % 2 == 1:
                c += 1
        n %= c
        ans += 1
    print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
X = input()

cnt = 0
for i in range(N):
    if X[i] == "1":
        cnt += 1
    
down = [0] * N
up = [0] * N
ald = 0
alu = 0
for i in range(N):
    down[i] = pow(2, N-1-i, cnt-1)
    up[i] = pow(2, N-1-i, cnt+1)
    if X[i] == "1":
        ald += down[i]
        ald %= cnt-1
        alu += up[i]
        alu %= cnt+1

for i in range(N):
    if X[i] == "1":
        n = (ald - down[i]) % (cnt-1)
    else:
        n = (alu + up[i]) % (cnt+1)
    ans = 1
    while n != 0:
        c = 0
        for j in range(18):
            if (n >> j) % 2 == 1:
                c += 1
        n %= c
        ans += 1
    print(ans)
        
    
    

Fixed submission:
N = int(input())
X = input()

cnt = 0
for i in range(N):
    if X[i] == "1":
        cnt += 1
    
down = [0] * N
up = [0] * N
ald = 0
alu = 0
for i in range(N):
    up[i] = pow(2, N-1-i, cnt+1)
    if X[i] == "1":
        alu += up[i]
        alu %= cnt+1
    if cnt <= 1:
        continue
    down[i] = pow(2, N-1-i, cnt-1)
    if X[i] == "1":
        ald += down[i]
        ald %= cnt-1

for i in range(N):    
    if X[i] == "1":
        if cnt == 1:
            print(0)
            continue
        n = (ald - down[i]) % (cnt-1)
    else:
        n = (alu + up[i]) % (cnt+1)
    ans = 1
    while n != 0:
        c = 0
        for j in range(20):
            if (n >> j) % 2 == 1:
                c += 1
        n %= c
        ans += 1
    print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
X = input()

x = Counter(X)
cnt = x["1"]

down = [0] * N
up = [0] * N
ald = 0
alu = 0
for i in range(N):
    down[i] = pow(2, N-1-i, cnt-1)
    up[i] = pow(2, N-1-i, cnt+1)
    if X[i] == "1":
        ald += down[i]
        ald %= cnt-1
        alu += up[i]
        alu %= cnt+1

for i in range(N):
    if X[i] == "1":
        n = (ald - down[i]) % (cnt-1)
    else:
        n = (alu + up[i]) % (cnt+1)
    ans = 1
    while n != 0:
        c = 0
        for j in range(18):
            if (n >> j) % 2 == 1:
                c += 1
        n %= c
        ans += 1
    print(ans)
        
    
    

Fixed submission:
N = int(input())
X = input()

cnt = 0
for i in range(N):
    if X[i] == "1":
        cnt += 1
    
down = [0] * N
up = [0] * N
ald = 0
alu = 0
for i in range(N):
    up[i] = pow(2, N-1-i, cnt+1)
    if X[i] == "1":
        alu += up[i]
        alu %= cnt+1
    if cnt <= 1:
        continue
    down[i] = pow(2, N-1-i, cnt-1)
    if X[i] == "1":
        ald += down[i]
        ald %= cnt-1

for i in range(N):    
    if X[i] == "1":
        if cnt == 1:
            print(0)
            continue
        n = (ald - down[i]) % (cnt-1)
    else:
        n = (alu + up[i]) % (cnt+1)
    ans = 1
    while n != 0:
        c = 0
        for j in range(20):
            if (n >> j) % 2 == 1:
                c += 1
        n %= c
        ans += 1
    print(ans)