Buggy python submission (verdict: Time Limit Exceeded):
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = readline().decode().rstrip()
one_cnt = S.count('1')
cnt = [0]*(one_cnt+1)
pop_cnt = [0]* (N+1)
for i in range(1,one_cnt+1):
    pop_cnt[i] = pop_cnt[i//2] + i%2
    j = i % pop_cnt[i]
    cnt[i] = 1 + cnt[j] 
    
n = int(S, 2)
for i in range(N):
    if S[i] == '1':
        tmp = n - 2**(N-i-1)
        if tmp == 0:
            print(0)
        else:
            tmp %= (one_cnt-1)
            print(1+cnt[tmp])
    else:
        tmp = n + 2**(N-i-1) 
        tmp %= (one_cnt+1)
        print(1+cnt[tmp])

Fixed submission:
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = readline().decode().rstrip()
one_cnt = S.count('1')
S_rev = S[::-1]
#one_modは元のビットが立ってるとき zero_modは逆
one_mod = 0
zero_mod = 0
#Nが大きすぎるため下の桁から順に計算
for i in range(N):
    if S_rev[i] == '1' and one_cnt - 1 != 0:
        one_mod += pow(2,i,one_cnt - 1)
        one_mod %= (one_cnt - 1)
        zero_mod += pow(2,i,one_cnt + 1)
        zero_mod %= (one_cnt + 1)

cnt = [0]*(one_cnt+1)
pop_cnt = [0]* (one_cnt+1)
for i in range(1,one_cnt+1):
    pop_cnt[i] = pop_cnt[i//2] + i%2
    j = i % pop_cnt[i]
    cnt[i] = 1 + cnt[j] 

one_pow2 = [1]*(N+1)
zero_pow2 = [1]*(N+1)
for i in range(1,N):
    if one_cnt-1 != 0:
        one_pow2[i+1] = one_pow2[i]*2 % (one_cnt - 1)
    zero_pow2[i+1] = zero_pow2[i]*2 % (one_cnt + 1)

for i in range(N):
    if S[i] == '1':
        if one_cnt-1 == 0:
            print(0)
        else:
            nxt = one_mod
            nxt -= one_pow2[N-i]
            nxt %= (one_cnt - 1)
            print(1+cnt[nxt])
    else:
        nxt = zero_mod
        nxt += zero_pow2[N-i]
        nxt %= (one_cnt + 1)
        print(1+cnt[nxt])

Buggy python submission (verdict: Runtime Error):
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c
N = int(readline())
S = readline().decode().rstrip()
one_cnt = S.count('1')
cnt = [0]*(one_cnt+1)
for i in range(1,one_cnt+1):
    j = i % popcnt(i)
    cnt[i] = 1 + cnt[j] 
    
n = int(S, 2)
for i in range(N):
    if S[i] == '1':
        tmp = n - 2**(N-i-1)
        tmp %= (one_cnt-1)
        print(1+cnt[tmp])
    else:
        tmp = n + 2**(N-i-1) 
        tmp %= (one_cnt+1)
        print(1+cnt[tmp])

Fixed submission:
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = readline().decode().rstrip()
one_cnt = S.count('1')
S_rev = S[::-1]
#one_modは元のビットが立ってるとき zero_modは逆
one_mod = 0
zero_mod = 0
#Nが大きすぎるため下の桁から順に計算
for i in range(N):
    if S_rev[i] == '1' and one_cnt - 1 != 0:
        one_mod += pow(2,i,one_cnt - 1)
        one_mod %= (one_cnt - 1)
        zero_mod += pow(2,i,one_cnt + 1)
        zero_mod %= (one_cnt + 1)

cnt = [0]*(one_cnt+1)
pop_cnt = [0]* (one_cnt+1)
for i in range(1,one_cnt+1):
    pop_cnt[i] = pop_cnt[i//2] + i%2
    j = i % pop_cnt[i]
    cnt[i] = 1 + cnt[j] 

one_pow2 = [1]*(N+1)
zero_pow2 = [1]*(N+1)
for i in range(1,N):
    if one_cnt-1 != 0:
        one_pow2[i+1] = one_pow2[i]*2 % (one_cnt - 1)
    zero_pow2[i+1] = zero_pow2[i]*2 % (one_cnt + 1)

for i in range(N):
    if S[i] == '1':
        if one_cnt-1 == 0:
            print(0)
        else:
            nxt = one_mod
            nxt -= one_pow2[N-i]
            nxt %= (one_cnt - 1)
            print(1+cnt[nxt])
    else:
        nxt = zero_mod
        nxt += zero_pow2[N-i]
        nxt %= (one_cnt + 1)
        print(1+cnt[nxt])