Buggy python submission (verdict: Time Limit Exceeded):
def solve(x):
    cnt = 1
    while x > 0:
        x %= bin(x).count('1')
        cnt += 1
    return cnt

n = int(input())
x = input()
one = sum(map(int, list(x)))
num = int(x, 2)

up = num%(one+1)
if one == 1:
    down = 0
else:
    down = num%(one-1)
z = pow(2, n-1)
for i in range(n):
    if x[i] == '1':
        if one == 1:
            print(0)
            z //= 2
            continue
        s = down - z%(one-1)
        if s < 0:
            s += one-1
    else:
        s = (up + z%(one+1))%(one+1)
    print(solve(s))
    z //= 2

Fixed submission:
def solve(x):
    cnt = 1
    while x > 0:
        x %= bin(x).count('1')
        cnt += 1
    return cnt

n = int(input())
x = input()
one = sum(map(int, list(x)))
num = int(x, 2)

up = num%(one+1)
if one == 1:
    down = 0
else:
    down = num%(one-1)

for i in range(n):
    if x[i] == '1':
        if one == 1:
            print(0)
            continue
        s = (down - pow(2, n-i-1, one-1))%(one-1)
    else:
        s = (up + pow(2, n-i-1, one+1))%(one+1)
    print(solve(s))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(x):
    cnt = 1
    while x > 0:
        count = 0
        y = x
        while y > 0:
            count += (y%2==1)
            y >>= 1
        x %= count
        cnt += 1
    return cnt

n = int(input())
x = input()
one = x.count('1')
num = int(x, 2)

up = num%(one+1)
if one == 1:
    down = 0
else:
    down = num%(one-1)
z = 2**(n-1)
for i in range(n):
    if x[i] == '1':
        if one == 1:
            print(0)
            z //= 2
            continue
        s = down - z%(one-1)
        if s < 0:
            s += one-1
    else:
        s = (up + z%(one+1))%(one+1)
    print(solve(s))
    z //= 2

Fixed submission:
def solve(x):
    cnt = 1
    while x > 0:
        x %= bin(x).count('1')
        cnt += 1
    return cnt

n = int(input())
x = input()
one = sum(map(int, list(x)))
num = int(x, 2)

up = num%(one+1)
if one == 1:
    down = 0
else:
    down = num%(one-1)

for i in range(n):
    if x[i] == '1':
        if one == 1:
            print(0)
            continue
        s = (down - pow(2, n-i-1, one-1))%(one-1)
    else:
        s = (up + pow(2, n-i-1, one+1))%(one+1)
    print(solve(s))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(x):
    cnt = 1
    while x > 0:
        count = 0
        y = x
        while y > 0:
            count += (y%2==1)
            y >>= 1
        x %= count
        cnt += 1
    return cnt

n = int(input())
x = input()
one = x.count('1')
num = int(x, 2)

up = num%(one+1)
if one == 1:
    down = 0
else:
    down = num%(one-1)
z = 2**(n-1)
for i in range(n):
    if x[i] == '1':
        if one == 1:
            print(0)
            z //= 2
            continue
        s = down - z%(one-1)
        if s < 0:
            s += one-1
    else:
        s = (up + z%(one+1))%(one+1)
    print(solve(s))
    z //= 2

Fixed submission:
def solve(x):
    cnt = 1
    while x > 0:
        x %= bin(x).count('1')
        cnt += 1
    return cnt

n = int(input())
x = input()
one = sum(map(int, list(x)))
num = int(x, 2)

up = num%(one+1)
if one == 1:
    down = 0
else:
    down = num%(one-1)

for i in range(n):
    if x[i] == '1':
        if one == 1:
            print(0)
            continue
        s = (down - pow(2, n-i-1, one-1))%(one-1)
    else:
        s = (up + pow(2, n-i-1, one+1))%(one+1)
    print(solve(s))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(x):
    cnt = 1
    while x > 0:
        count = 0
        y = x
        while y > 0:
            count += (y%2==1)
            y >>= 1
        x %= count
        cnt += 1
    return cnt

n = int(input())
x = input()
one = x.count('1')
num = int(x, 2)

up = num%(one+1)
if one == 1:
    down = 0
else:
    down = num%(one-1)

for i in range(n):
    if x[i] == '1':
        if one == 1:
            print(0)
            continue
        s = down - (2**(n-i-1))%(one-1)
        if s < 0:
            s += one-1
    else:
        s = (up + (2**(n-i-1))%(one+1))%(one+1)
    print(solve(s))

Fixed submission:
def solve(x):
    cnt = 1
    while x > 0:
        x %= bin(x).count('1')
        cnt += 1
    return cnt

n = int(input())
x = input()
one = sum(map(int, list(x)))
num = int(x, 2)

up = num%(one+1)
if one == 1:
    down = 0
else:
    down = num%(one-1)

for i in range(n):
    if x[i] == '1':
        if one == 1:
            print(0)
            continue
        s = (down - pow(2, n-i-1, one-1))%(one-1)
    else:
        s = (up + pow(2, n-i-1, one+1))%(one+1)
    print(solve(s))

Buggy python submission (verdict: Runtime Error):
def solve(x):
    cnt = 1
    while x > 0:
        count = 0
        y = x
        while y > 0:
            count += (y%2==1)
            y >>= 1
        x %= count
        cnt += 1
    return cnt

n = int(input())
x = input()
one = x.count('1')
num = int(x, 2)

up = num%(one+1)
down = num%(one-1)

for i in range(n):
    if x[i] == '1':
        if one == 1:
            print(0)
            continue
        s = down - (2**(n-i-1))%(one-1)
        if s < 0:
            s += one-1
    else:
        s = (up + (2**(n-i-1))%(one+1))%(one+1)
    print(solve(s))

Fixed submission:
def solve(x):
    cnt = 1
    while x > 0:
        x %= bin(x).count('1')
        cnt += 1
    return cnt

n = int(input())
x = input()
one = sum(map(int, list(x)))
num = int(x, 2)

up = num%(one+1)
if one == 1:
    down = 0
else:
    down = num%(one-1)

for i in range(n):
    if x[i] == '1':
        if one == 1:
            print(0)
            continue
        s = (down - pow(2, n-i-1, one-1))%(one-1)
    else:
        s = (up + pow(2, n-i-1, one+1))%(one+1)
    print(solve(s))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(st):
    num = int(st, 2)
    count = 0
    while num > 0:
        x = bin(num).count('1')
        num %= x
        count += 1
    return count

n = int(input())
x = list(input())
for i in range(n):
    y = x.copy()
    if y[i] == '1':
        y[i] = '0'
    else:
        y[i] = '1'
    print(solve(''.join(y)))

Fixed submission:
def solve(x):
    cnt = 1
    while x > 0:
        x %= bin(x).count('1')
        cnt += 1
    return cnt

n = int(input())
x = input()
one = sum(map(int, list(x)))
num = int(x, 2)

up = num%(one+1)
if one == 1:
    down = 0
else:
    down = num%(one-1)

for i in range(n):
    if x[i] == '1':
        if one == 1:
            print(0)
            continue
        s = (down - pow(2, n-i-1, one-1))%(one-1)
    else:
        s = (up + pow(2, n-i-1, one+1))%(one+1)
    print(solve(s))