Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X_2 = input()
X_10 = int(X_2, 2)

y = X_2.count('1')

a = X_10%(y+1)
if y==1:
    b = 0
else:
    b = X_10%(y-1)

for i in range(N):
    if X_2[i] == '1' and y == 1:
        print(0)
        continue
    elif X_2[i] == '1':
        c = (2**(N-1-i))%(y-1)
        x = (b-c)%(y-1)
    else:
        c = (2**(N-1-i))%(y+1)
        x = (a+c)%(y+1)
    count = 1
    while x!=0:
        x %= bin(x)[2:].count('1')
        count += 1
    print(count)

Fixed submission:
N = int(input())
X_2 = input()
X_10 = int(X_2, 2)

y = X_2.count('1')

a = X_10%(y+1)
if y==1:
    b = 0
else:
    b = X_10%(y-1)

for i in range(N):
    if X_2[i] == '1' and y == 1:
        print(0)
        continue
    elif X_2[i] == '1':
        x = (b-pow(2, N-1-i, y-1))%(y-1)
    else:
        x = (a+pow(2, N-1-i, y+1))%(y+1)
    count = 1
    while x!=0:
        x %= bin(x)[2:].count('1')
        count += 1
    print(count)

Buggy python submission (verdict: Runtime Error):
N = int(input())
X_2 = input()
X_10 = int(X_2, 2)

y=sum(map(int, X_2))+1
z=y-2

a = X_10%y
b = X_10%z

for i in range(N):
    if X_2[i]=='0':
        c = (2**(N-1-i))%y
        x = (a+c)%y
    elif sum(map(int, X_2[0:i]+X_2[i+1:]))==0:
        print(0)
        continue
    else:
        c = (2**(N-1-i))%z
        x = (b-c)%z
    
    count = 1
    while x != 0:
        x = x%sum(map(int, bin(x)[2:]))
        count+=1
    print(count)

Fixed submission:
N = int(input())
X_2 = input()
X_10 = int(X_2, 2)

y = X_2.count('1')

a = X_10%(y+1)
if y==1:
    b = 0
else:
    b = X_10%(y-1)

for i in range(N):
    if X_2[i] == '1' and y == 1:
        print(0)
        continue
    elif X_2[i] == '1':
        x = (b-pow(2, N-1-i, y-1))%(y-1)
    else:
        x = (a+pow(2, N-1-i, y+1))%(y+1)
    count = 1
    while x!=0:
        x %= bin(x)[2:].count('1')
        count += 1
    print(count)

Buggy python submission (verdict: Runtime Error):
from itertools import product
from math import log2

N = int(input())
X = input()
m = sum(list(map(int, X)))+1
n = int(log2(m)+1)
f = [0]

i = 0
for p in product([0,1], repeat=n):
    if i>0:
        a = sum(p)
        f.append(f[i%a]+1)
    i += 1

for i in range(N):
    if X[i] == '1':
        x = int(X[0:i]+'0'+X[i+1:], 2)
        a = m-2
    else:
        x = int(X[0:i]+'1'+X[i+1:], 2)
        a = m
    print(f[x%a]+1)

Fixed submission:
N = int(input())
X_2 = input()
X_10 = int(X_2, 2)

y = X_2.count('1')

a = X_10%(y+1)
if y==1:
    b = 0
else:
    b = X_10%(y-1)

for i in range(N):
    if X_2[i] == '1' and y == 1:
        print(0)
        continue
    elif X_2[i] == '1':
        x = (b-pow(2, N-1-i, y-1))%(y-1)
    else:
        x = (a+pow(2, N-1-i, y+1))%(y+1)
    count = 1
    while x!=0:
        x %= bin(x)[2:].count('1')
        count += 1
    print(count)

Buggy python submission (verdict: Runtime Error):
from itertools import product
from math import log2

N = int(input())
X = input()
f = [0]*(N+1)
m = sum(list(map(int, X)))+1
n = int(log2(m)+1)

i = 0
for p in product([0,1], repeat=n):
    if i>0:
        a = sum(p)
        f[i] = f[i%a]+1
    i += 1

for i in range(N):
    if X[i] == '1':
        x = int(X[0:i]+'0'+X[i+1:], 2)
        a = m-2
    else:
        x = int(X[0:i]+'1'+X[i+1:], 2)
        a = m
    print(f[x%a]+1)

Fixed submission:
N = int(input())
X_2 = input()
X_10 = int(X_2, 2)

y = X_2.count('1')

a = X_10%(y+1)
if y==1:
    b = 0
else:
    b = X_10%(y-1)

for i in range(N):
    if X_2[i] == '1' and y == 1:
        print(0)
        continue
    elif X_2[i] == '1':
        x = (b-pow(2, N-1-i, y-1))%(y-1)
    else:
        x = (a+pow(2, N-1-i, y+1))%(y+1)
    count = 1
    while x!=0:
        x %= bin(x)[2:].count('1')
        count += 1
    print(count)

Buggy python submission (verdict: Runtime Error):
N = int(input())
X = input()
f = [0]*(N+1)
for i in range(1, N):
    a = sum(list(map(int, bin(i)[2:])))
    f[i] = f[i%a]+1

for i in range(N):
    if X[i] == '1':
        x = int(X[0:i]+'0'+X[i+1:], 2)
    else:
        x = int(X[0:i]+'1'+X[i+1:], 2)
    a = sum(list(map(int, bin(x)[2:])))
    print(f[x%a]+1)

Fixed submission:
N = int(input())
X_2 = input()
X_10 = int(X_2, 2)

y = X_2.count('1')

a = X_10%(y+1)
if y==1:
    b = 0
else:
    b = X_10%(y-1)

for i in range(N):
    if X_2[i] == '1' and y == 1:
        print(0)
        continue
    elif X_2[i] == '1':
        x = (b-pow(2, N-1-i, y-1))%(y-1)
    else:
        x = (a+pow(2, N-1-i, y+1))%(y+1)
    count = 1
    while x!=0:
        x %= bin(x)[2:].count('1')
        count += 1
    print(count)