Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = input()
fn = {0: 0}
fn_keys = {0}

def culc_fn(n, fn, fn_keys):
    if not n in fn_keys:
        popcount = bin(n).count('1')
        tmp = n%popcount
        fn[n] = culc_fn(tmp, fn, fn_keys) + 1
        fn_keys.add(n)
    return fn[n]

culc_fn(int('1'*N), fn, fn_keys)

for i in range(N):
    tmp = int(X[:i] + ('0' if X[i] == '1' else '1') + X[i+1:], 2)
    popcount = bin(tmp).count('1')
    if popcount > 0:
        print(culc_fn(tmp%popcount, fn, fn_keys)+1)
    else:
        print(0)

Fixed submission:
# N = 10
# X = '1'*N
N = int(input())
X = input()
popcount_X = X.count('1')
X_ = int(X, 2)

X_mod_minus = X_%(popcount_X-1) if popcount_X > 1 else -1
X_mod_plus = X_%(popcount_X+1)
for i in range(N):
    if X[i] == '0':
        popcount = popcount_X+1
        X_i = (X_mod_plus + pow(2, N-i-1, popcount))%(popcount)
    else:
        if X_mod_minus == -1:
            print(0)
            continue
        popcount = popcount_X-1
        X_i = (X_mod_minus - pow(2, N-i-1, popcount))%(popcount)
    ans = 1
    while X_i > 0:
        X_i %= bin(X_i).count('1')
        ans += 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = input()
fn = {0: 0}
fn_keys = {0}

def culc_fn(n, fn, fn_keys):
    if not n in fn_keys:
        popcount = bin(n).count('1')
        tmp = n%popcount
        fn[n] = culc_fn(tmp, fn, fn_keys) + 1
        fn_keys.add(n)
    return fn[n]

culc_fn(int('1'*N), fn, fn_keys)

for i in range(N):
    tmp = int(X[:i] + ('0' if X[i] == '1' else '1') + X[i+1:], 2)
    popcount = bin(tmp).count('1')
    if popcount > 0:
        print(culc_fn(tmp%popcount, fn, fn_keys)+1)
    else:
        print(0)

Fixed submission:
# N = 10
# X = '1'*N
N = int(input())
X = input()
popcount_X = X.count('1')
X_ = int(X, 2)

X_mod_minus = X_%(popcount_X-1) if popcount_X > 1 else -1
X_mod_plus = X_%(popcount_X+1)
for i in range(N):
    if X[i] == '0':
        popcount = popcount_X+1
        X_i = (X_mod_plus + pow(2, N-i-1, popcount))%(popcount)
    else:
        if X_mod_minus == -1:
            print(0)
            continue
        popcount = popcount_X-1
        X_i = (X_mod_minus - pow(2, N-i-1, popcount))%(popcount)
    ans = 1
    while X_i > 0:
        X_i %= bin(X_i).count('1')
        ans += 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = input()
fn = {0: 0}

def culc_fn(n, fn):
    if not n in fn.keys():
        popcount = bin(n).count('1')
        tmp = n%popcount
        fn[n] = culc_fn(tmp, fn) + 1
    return fn[n]

for i in range(N):
    tmp = int(X[:i] + ('0' if X[i] == '1' else '1') + X[i+1:], 2)
    print(culc_fn(tmp, fn))

Fixed submission:
# N = 10
# X = '1'*N
N = int(input())
X = input()
popcount_X = X.count('1')
X_ = int(X, 2)

X_mod_minus = X_%(popcount_X-1) if popcount_X > 1 else -1
X_mod_plus = X_%(popcount_X+1)
for i in range(N):
    if X[i] == '0':
        popcount = popcount_X+1
        X_i = (X_mod_plus + pow(2, N-i-1, popcount))%(popcount)
    else:
        if X_mod_minus == -1:
            print(0)
            continue
        popcount = popcount_X-1
        X_i = (X_mod_minus - pow(2, N-i-1, popcount))%(popcount)
    ans = 1
    while X_i > 0:
        X_i %= bin(X_i).count('1')
        ans += 1
    print(ans)