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

pop_X = sum(map(int,list(X)))
X_10 = int('0b'+X,2)
r_0 = X_10%(pop_X+1)
zero_flag = False
if pop_X == 1:
    zero_flag = True
else:
    r_1 = X_10%(pop_X-1)

diff = 2 ** (N-1)
for i in range(N):
    if X[i]=='0':
        r = (r_0+diff%(pop_X+1))%(pop_X+1)
    else:
        if zero_flag:
            print(0)
            break
        else:
            r = (r_1-diff%(pop_X-1))%(pop_X-1)
    count = 1
    while True:
        if r == 0:
            break
        pop = sum(map(int,list(bin(r)[2:])))
        r = r % pop
        count += 1
        
    print(count)
    diff = int(diff/2)

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

pop_X = sum(map(int,list(X)))
X_10 = int('0b'+X,2)

r_0 = X_10%(pop_X+1)
diff_0 = 1%(pop_X+1)

zero_flag = False
if pop_X == 1:
    zero_flag = True
else:
    r_1 = X_10%(pop_X-1)
    diff_1 = 1%(pop_X-1)

answer = []


for i in range(N)[::-1]:
    if X[i]=='0':
        r = (r_0+diff_0)%(pop_X+1)
    else:
        if zero_flag:
            answer.append(0)
            diff_0 = (diff_0*2)%(pop_X+1)
            continue
        else:
            r = (r_1-diff_1)%(pop_X-1)
    count = 1
    while True:
        if r == 0:
            break
        pop = sum(map(int,list(bin(r)[2:])))
        r = r % pop
        count += 1
        
    answer.append(count)
    diff_0 = (diff_0*2)%(pop_X+1)
    if zero_flag:
        continue
    diff_1 = (diff_1*2)%(pop_X-1)

for i in answer[::-1]:
    print(i)

Buggy python submission (verdict: Runtime Error):
N = int(input())
X = input()
​
pop_X = sum(map(int,list(X)))
X_10 = int('0b'+X,2)
r_0 = X_10%(pop_X+1)
zero_flag = False
if pop_X == 1:
    zero_flag = True
else:
    r_1 = X_10%(pop_X-1)
​
diff = 2 ** (N-1)
for i in range(N):
    if X[i]=='0':
        r = (r_0+diff%(pop_X+1))%(pop_X+1)
    else:
        if zero_flag:
            print(0)
            break
        else:
            r = (r_1-diff%(pop_X-1))%(pop_X-1)
    count = 1
    while True:
        if r == 0:
            break
        pop = sum(map(int,list(bin(r)[2:])))
        r = r % pop
        count += 1
        
    print(count)
    diff /= 2


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

pop_X = sum(map(int,list(X)))
X_10 = int('0b'+X,2)

r_0 = X_10%(pop_X+1)
diff_0 = 1%(pop_X+1)

zero_flag = False
if pop_X == 1:
    zero_flag = True
else:
    r_1 = X_10%(pop_X-1)
    diff_1 = 1%(pop_X-1)

answer = []


for i in range(N)[::-1]:
    if X[i]=='0':
        r = (r_0+diff_0)%(pop_X+1)
    else:
        if zero_flag:
            answer.append(0)
            diff_0 = (diff_0*2)%(pop_X+1)
            continue
        else:
            r = (r_1-diff_1)%(pop_X-1)
    count = 1
    while True:
        if r == 0:
            break
        pop = sum(map(int,list(bin(r)[2:])))
        r = r % pop
        count += 1
        
    answer.append(count)
    diff_0 = (diff_0*2)%(pop_X+1)
    if zero_flag:
        continue
    diff_1 = (diff_1*2)%(pop_X-1)

for i in answer[::-1]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
def pop(x):
    binary = []
    while True:
        if x == 1:
            binary.append(x)
            break
        q,mod = divmod(x,2)
        binary.append(mod)
        x = q
    return sum(binary)

N = int(input())
X = list(map(int,list(input())))

pop_X = sum(X)
X_10 = sum([X[i]*2**(N-i-1) for i in range(N)])


for i in range(N):
    count = 0
    Xi_10 = X_10 + 2**(N-i-1) if X[i]==0 else X_10 - 2**(N-i-1)
    pop_Xi = pop_X + 1 if X[i]==0 else pop_X -1
    if pop_Xi == 0:
        print(count)
        continue
    while True:
        r = Xi_10 % pop_Xi
        count+= 1
        if r == 0:
            break
        Xi_10 = r
        pop_Xi = pop(r)
    print(count)


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

pop_X = sum(map(int,list(X)))
X_10 = int('0b'+X,2)

r_0 = X_10%(pop_X+1)
diff_0 = 1%(pop_X+1)

zero_flag = False
if pop_X == 1:
    zero_flag = True
else:
    r_1 = X_10%(pop_X-1)
    diff_1 = 1%(pop_X-1)

answer = []


for i in range(N)[::-1]:
    if X[i]=='0':
        r = (r_0+diff_0)%(pop_X+1)
    else:
        if zero_flag:
            answer.append(0)
            diff_0 = (diff_0*2)%(pop_X+1)
            continue
        else:
            r = (r_1-diff_1)%(pop_X-1)
    count = 1
    while True:
        if r == 0:
            break
        pop = sum(map(int,list(bin(r)[2:])))
        r = r % pop
        count += 1
        
    answer.append(count)
    diff_0 = (diff_0*2)%(pop_X+1)
    if zero_flag:
        continue
    diff_1 = (diff_1*2)%(pop_X-1)

for i in answer[::-1]:
    print(i)

Buggy python submission (verdict: Runtime Error):
def pop(x):
    binary = []
    while True:
        if x == 1:
            binary.append(x)
            break
        q,mod = divmod(x,2)
        binary.append(mod)
        x = q
    return sum(binary)

N = int(input())
X = list(map(int,list(input())))

pop_X = sum(X)
X_10 = sum([X[i]*2**(N-i-1) for i in range(N)])

answer = []
for i in range(N):
    count = 0
    Xi_10 = X_10 + 2**(N-i-1) if X[i]==0 else X_10 - 2**(N-i-1)
    pop_Xi = pop_X + 1 if X[i]==0 else pop_X -1
    while True:
        r = Xi_10 % pop_Xi
        count+= 1
        if r == 0:
            break
        Xi_10 = r
        pop_Xi = pop(r)
    answer.append(count)

for i in range(N):
    print(answer[i])
    

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

pop_X = sum(map(int,list(X)))
X_10 = int('0b'+X,2)

r_0 = X_10%(pop_X+1)
diff_0 = 1%(pop_X+1)

zero_flag = False
if pop_X == 1:
    zero_flag = True
else:
    r_1 = X_10%(pop_X-1)
    diff_1 = 1%(pop_X-1)

answer = []


for i in range(N)[::-1]:
    if X[i]=='0':
        r = (r_0+diff_0)%(pop_X+1)
    else:
        if zero_flag:
            answer.append(0)
            diff_0 = (diff_0*2)%(pop_X+1)
            continue
        else:
            r = (r_1-diff_1)%(pop_X-1)
    count = 1
    while True:
        if r == 0:
            break
        pop = sum(map(int,list(bin(r)[2:])))
        r = r % pop
        count += 1
        
    answer.append(count)
    diff_0 = (diff_0*2)%(pop_X+1)
    if zero_flag:
        continue
    diff_1 = (diff_1*2)%(pop_X-1)

for i in answer[::-1]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
import numpy as np

def f(X):
    count = 0
    while np.sum(X)>0:
        X = popcount(X)
        count += 1
    return count

def popcount(X):
    a = np.sum(X)
    x_10 = 0
    for i in range(len(X)):
        x_10 += X[-(i+1)]*2**i
    n = x_10 % a
    k=2
    bi=''
    while n!=0:
        bi+=str(n%abs(k))
        if k<0:n=-(-n//k)
        else:n=n//k
    bi[::-1]
    return list(map(int,list(bi[::-1])))


N = int(input())
X = list(map(int,list(input())))

for i in range(N):
    X_i = copy.copy(X)
    if X_i[i] == 0:
        X_i[i] =1
    else:
        X_i[i] = 0
    print(f(X_i))

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

pop_X = sum(map(int,list(X)))
X_10 = int('0b'+X,2)

r_0 = X_10%(pop_X+1)
diff_0 = 1%(pop_X+1)

zero_flag = False
if pop_X == 1:
    zero_flag = True
else:
    r_1 = X_10%(pop_X-1)
    diff_1 = 1%(pop_X-1)

answer = []


for i in range(N)[::-1]:
    if X[i]=='0':
        r = (r_0+diff_0)%(pop_X+1)
    else:
        if zero_flag:
            answer.append(0)
            diff_0 = (diff_0*2)%(pop_X+1)
            continue
        else:
            r = (r_1-diff_1)%(pop_X-1)
    count = 1
    while True:
        if r == 0:
            break
        pop = sum(map(int,list(bin(r)[2:])))
        r = r % pop
        count += 1
        
    answer.append(count)
    diff_0 = (diff_0*2)%(pop_X+1)
    if zero_flag:
        continue
    diff_1 = (diff_1*2)%(pop_X-1)

for i in answer[::-1]:
    print(i)