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

cnt = X.count('1')
if cnt == 1:
    print(*([1] + N), sep='\n')
    exit()

M = 0
for x in X:
    M <<= 1
    if x == '1':
        M += 1

def solve(n):
    ret = 1
    while n > 0:
        ret += 1
        n %= bin(n).count('1')
    return ret

ans = []
p = M % (cnt + 1)
m = M % (cnt - 1)

for i in range(N):
    if X[i] == '0':
        ans.append(solve((p + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)))
    else:
        ans.append(solve((m - pow(2, N - i - 1, cnt - 1)) % (cnt - 1)))
print(*ans, sep='\n')


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

cnt = X.count('1')
if cnt == 1:
    for x in X[:-1]:
        if x == '0':
            print(1)
        else:
            print(0)
    if X[-1] == '1':
        print(0)
    else:
        print(2)
    exit()

M = 0
for x in X:
    M <<= 1
    if x == '1':
        M += 1

def solve(n):
    ret = 1
    while n > 0:
        ret += 1
        n %= bin(n).count('1')
    return ret

ans = []
p = M % (cnt + 1)
m = M % (cnt - 1)

for i in range(N):
    if X[i] == '0':
        ans.append(solve((p + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)))
    else:
        ans.append(solve((m - pow(2, N - i - 1, cnt - 1)) % (cnt - 1)))
print(*ans, sep='\n')

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

cnt = X.count('1')
M = 0
for x in X:
    M <<= 1
    if x == '1':
        M += 1

def solve(n):
    ret = 1
    while n > 0:
        ret += 1
        n %= bin(n).count('1')
    return ret

ans = []
p = M % (cnt + 1)
m = M % (cnt - 1)

for i in range(N):
    if X[i] == '0':
        ans.append(solve((p + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)))
    else:
        ans.append(solve((m - pow(2, N - i - 1, cnt - 1)) % (cnt - 1)))
print(*ans, sep='\n')


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

cnt = X.count('1')
if cnt == 1:
    for x in X[:-1]:
        if x == '0':
            print(1)
        else:
            print(0)
    if X[-1] == '1':
        print(0)
    else:
        print(2)
    exit()

M = 0
for x in X:
    M <<= 1
    if x == '1':
        M += 1

def solve(n):
    ret = 1
    while n > 0:
        ret += 1
        n %= bin(n).count('1')
    return ret

ans = []
p = M % (cnt + 1)
m = M % (cnt - 1)

for i in range(N):
    if X[i] == '0':
        ans.append(solve((p + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)))
    else:
        ans.append(solve((m - pow(2, N - i - 1, cnt - 1)) % (cnt - 1)))
print(*ans, sep='\n')

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

for s in input():
    X <<= 1
    if s == '1':
        X += 1
        C += 1

def f(n, c):
    if n == 0:
        return 0
    n %= c

    ret = 1
    while n > 0:
        n %= bin(n).count('1')
        ret += 1
    return ret

ans = [f(X ^ (1 << i), C + (1 if (X & (1 << i) == 0) else -1)) for i in range(N)]
print(*ans[::-1], sep='\n')


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

cnt = X.count('1')
if cnt == 1:
    for x in X[:-1]:
        if x == '0':
            print(1)
        else:
            print(0)
    if X[-1] == '1':
        print(0)
    else:
        print(2)
    exit()

M = 0
for x in X:
    M <<= 1
    if x == '1':
        M += 1

def solve(n):
    ret = 1
    while n > 0:
        ret += 1
        n %= bin(n).count('1')
    return ret

ans = []
p = M % (cnt + 1)
m = M % (cnt - 1)

for i in range(N):
    if X[i] == '0':
        ans.append(solve((p + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)))
    else:
        ans.append(solve((m - pow(2, N - i - 1, cnt - 1)) % (cnt - 1)))
print(*ans, sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
M = 1

while M < N:
    M <<= 1

mask = []
K = M
while K // 2 > 0:
    s = (1 << (K // 2)) - 1
    m = 0
    for _ in range(M // K):
        m <<= K
        m += s
    mask.append(m)
    K >>= 1
mask = mask[::-1]

def popcnt(n):
    for i, m in enumerate(mask):
        n = (n & m) + ((n >> (1 << i)) & m)
    return n

def f(n):
    ret = 0
    while n > 0:
        ret += 1
        n %= popcnt(n)
    return ret

X = 0
for s in input():
    X <<= 1
    if s == '1':
        X += 1

ans = [f(X ^ (1 << i)) for i in range(N)]
print(*ans[::-1], sep='\n')


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

cnt = X.count('1')
if cnt == 1:
    for x in X[:-1]:
        if x == '0':
            print(1)
        else:
            print(0)
    if X[-1] == '1':
        print(0)
    else:
        print(2)
    exit()

M = 0
for x in X:
    M <<= 1
    if x == '1':
        M += 1

def solve(n):
    ret = 1
    while n > 0:
        ret += 1
        n %= bin(n).count('1')
    return ret

ans = []
p = M % (cnt + 1)
m = M % (cnt - 1)

for i in range(N):
    if X[i] == '0':
        ans.append(solve((p + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)))
    else:
        ans.append(solve((m - pow(2, N - i - 1, cnt - 1)) % (cnt - 1)))
print(*ans, sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
M = 1

while M < N:
    M <<= 1

mask = []
K = M
while K // 2 > 0:
    s = (1 << (K // 2)) - 1
    m = 0
    for _ in range(M // K):
        m <<= K
        m += s
    mask.append(m)
    K >>= 1
mask = mask[::-1]

def popcnt(n):
    for i, m in enumerate(mask):
        n = (n & m) + ((n >> (1 << i)) & m)
    return n

def f(n):
    ret = 0
    while n > 0:
        ret += 1
        n %= popcnt(n)
    return ret

X = 0
for s in input():
    X <<= 1
    if s == '1':
        X += 1

ans = [f(X ^ (1 << i)) for i in range(N)]
print(*ans[::-1], sep='\n')


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

cnt = X.count('1')
if cnt == 1:
    for x in X[:-1]:
        if x == '0':
            print(1)
        else:
            print(0)
    if X[-1] == '1':
        print(0)
    else:
        print(2)
    exit()

M = 0
for x in X:
    M <<= 1
    if x == '1':
        M += 1

def solve(n):
    ret = 1
    while n > 0:
        ret += 1
        n %= bin(n).count('1')
    return ret

ans = []
p = M % (cnt + 1)
m = M % (cnt - 1)

for i in range(N):
    if X[i] == '0':
        ans.append(solve((p + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)))
    else:
        ans.append(solve((m - pow(2, N - i - 1, cnt - 1)) % (cnt - 1)))
print(*ans, sep='\n')

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

def binToInt(X):
    ret = 0
    for s in X:
        ret <<= 1
        if s == '1':
            ret += 1
    return ret

def cnt(n):
    ret = 0
    while n > 0:
        n, r = divmod(n, 2)
        ret += r
    return ret

def f(n):
    ret = 0
    while n > 0:
        ret += 1
        n %= cnt(n)
    return ret

N = int(input())
X = binToInt(input().rstrip())

for i in range(N)[::-1]:
    print(f(X ^ (1 << i)))


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

cnt = X.count('1')
if cnt == 1:
    for x in X[:-1]:
        if x == '0':
            print(1)
        else:
            print(0)
    if X[-1] == '1':
        print(0)
    else:
        print(2)
    exit()

M = 0
for x in X:
    M <<= 1
    if x == '1':
        M += 1

def solve(n):
    ret = 1
    while n > 0:
        ret += 1
        n %= bin(n).count('1')
    return ret

ans = []
p = M % (cnt + 1)
m = M % (cnt - 1)

for i in range(N):
    if X[i] == '0':
        ans.append(solve((p + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)))
    else:
        ans.append(solve((m - pow(2, N - i - 1, cnt - 1)) % (cnt - 1)))
print(*ans, sep='\n')