Buggy python submission (verdict: Runtime Error):
N = int(input())
bin_X = input()
int_X = int(bin_X, 2)

pop_cnt_1 = 0
for i in bin_X:
    if i == '1':
        pop_cnt_1 += 1
pop_cnt_0 = pop_cnt_1 + 1
pop_cnt_1 = pop_cnt_1 - 1

int_X_0 = int_X % pop_cnt_0
int_X_1 = int_X % pop_cnt_1

def pop_cnt(n):
    c = 0
    for i in bin(n):
        if i == '1':
            c += 1
    return c

for i in range(N):
    if bin_X == '0':
        print(0)
        continue
    
    z = 2 ** (N-i-1)
    if bin_X[i] == '1':
        n = (int_X-z)%pop_cnt_1
    else:
        n = (int_X+z)%pop_cnt_0
   
    cnt = 1
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    print(cnt)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def pop_cnt(n):
    return bin(n).count('1')


def f(n):
    cnt = 0
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    return cnt
 
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c-1 != 0 else 0

for i in range(n):
    ans = 0
    if x2[i] == '0':
        t = (mod1 + pow(2, n-i-1, c+1)) % (c+1)
    else:
        if c-1 != 0:
            t = (mod2 - pow(2, n-i-1, c-1)) % (c-1)
        else:
            print(0)
            continue
    
    ans = f(t) + 1
    print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
bin_X = input()
int_X = int(bin_X, 2)

pop_cnt_1 = 0
for i in bin_X:
    if i == '1':
        pop_cnt_1 += 1
pop_cnt_0 = pop_cnt_1 + 1
pop_cnt_1 = pop_cnt_1 - 1

int_X_0 = int_X % pop_cnt_0
int_X_1 = int_X % pop_cnt_1

def pop_cnt(n):
    c = 0
    for i in bin(n):
        if i == '1':
            c += 1
    return c

for i in range(N):
    if bin_X == '0':
        print(0)
        continue
    
    z = 2 ** (N-i-1)
    if bin_X[i] == '1':
        n = (int_X-z)%pop_cnt_1
    else:
        n = (int_X+z)%pop_cnt_0
   
    cnt = 1
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    print(cnt)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def pop_cnt(n):
    return bin(n).count('1')


def f(n):
    cnt = 0
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    return cnt
 
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c-1 != 0 else 0

for i in range(n):
    ans = 0
    if x2[i] == '0':
        t = (mod1 + pow(2, n-i-1, c+1)) % (c+1)
    else:
        if c-1 != 0:
            t = (mod2 - pow(2, n-i-1, c-1)) % (c-1)
        else:
            print(0)
            continue
    
    ans = f(t) + 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = input()
    
cnt_1 = 0
for i in X:
    if i == '1':
        cnt_1 += 1

for i in range(N):
    if X[i] == '1':
        n = int(X, 2) - (1 << (N-i-1))
        tmp_cnt_1 = cnt_1 - 1
    else:
        n = int(X, 2) + (1 << (N-i-1))
        tmp_cnt_1 = cnt_1 + 1
        
    if n == 0:
        print(0)
        continue

    n = n % tmp_cnt_1
    cnt = 1

    while n != 0:
        c = 0
        for j in bin(n):
            c += j=='1'
        n = n % c
        cnt += 1
    print(cnt)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def pop_cnt(n):
    return bin(n).count('1')


def f(n):
    cnt = 0
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    return cnt
 
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c-1 != 0 else 0

for i in range(n):
    ans = 0
    if x2[i] == '0':
        t = (mod1 + pow(2, n-i-1, c+1)) % (c+1)
    else:
        if c-1 != 0:
            t = (mod2 - pow(2, n-i-1, c-1)) % (c-1)
        else:
            print(0)
            continue
    
    ans = f(t) + 1
    print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
X = input()

if X == '1':
    print(1)
    exit()
elif X == '0':
    print(0)
    exit()
    
x1 = 0
for i in X:
    if i == '1':
        x1 += 1

for i in range(N):
    if X[i] == '1':
        tmp = - (1<<(N-i-1))
        tmp2 = -1
    else:
        tmp = (1<<(N-i-1))
        tmp2 = 1
    
    n = int(X, 2) + tmp
    n %= x1 + tmp2
    cnt = 1
    while n != 0:
        c = 0
        for j in bin(n):
            c += j=='1'
        n %= c
        cnt += 1
    print(cnt)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def pop_cnt(n):
    return bin(n).count('1')


def f(n):
    cnt = 0
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    return cnt
 
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c-1 != 0 else 0

for i in range(n):
    ans = 0
    if x2[i] == '0':
        t = (mod1 + pow(2, n-i-1, c+1)) % (c+1)
    else:
        if c-1 != 0:
            t = (mod2 - pow(2, n-i-1, c-1)) % (c-1)
        else:
            print(0)
            continue
    
    ans = f(t) + 1
    print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
X = input()

x1 = 0
for i in X:
    if i == '1':
        x1 += 1

for i in range(N):
    if X[i] == '1':
        tmp = - (1<<(N-i-1))
        tmp2 = -1
    else:
        tmp = (1<<(N-i-1))
        tmp2 = 1
    
    n = int(X, 2) + tmp
    n %= x1 + tmp2
    cnt = 1
    while n != 0:
        c = 0
        for j in bin(n):
            c += j=='1'
        n %= c
        cnt += 1
    print(cnt)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def pop_cnt(n):
    return bin(n).count('1')


def f(n):
    cnt = 0
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    return cnt
 
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c-1 != 0 else 0

for i in range(n):
    ans = 0
    if x2[i] == '0':
        t = (mod1 + pow(2, n-i-1, c+1)) % (c+1)
    else:
        if c-1 != 0:
            t = (mod2 - pow(2, n-i-1, c-1)) % (c-1)
        else:
            print(0)
            continue
    
    ans = f(t) + 1
    print(ans)

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

for i in range(N):
    if X[i] == '1':
        tmp = - (1<<(N-i-1))
    else:
        tmp = (1<<(N-i-1))
    
    n = int(X, 2) + tmp    
    cnt = 0
    while n != 0:
        c = 0
        for j in bin(n):
            c += j=='1'
        n %= c
        cnt += 1
    print(cnt)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def pop_cnt(n):
    return bin(n).count('1')


def f(n):
    cnt = 0
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    return cnt
 
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c-1 != 0 else 0

for i in range(n):
    ans = 0
    if x2[i] == '0':
        t = (mod1 + pow(2, n-i-1, c+1)) % (c+1)
    else:
        if c-1 != 0:
            t = (mod2 - pow(2, n-i-1, c-1)) % (c-1)
        else:
            print(0)
            continue
    
    ans = f(t) + 1
    print(ans)

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

for i in range(N):
    if X[i] == '1':
        tmp = - (1<<(N-i-1))
    else:
        tmp = (1<<(N-i-1))
    
    n = int(X, 2) + tmp    
    cnt = 0
    while n != 0:
        c = 0
        for j in bin(n):
            c += j=='1'
        n %= c
        cnt += 1
    print(cnt)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def pop_cnt(n):
    return bin(n).count('1')


def f(n):
    cnt = 0
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    return cnt
 
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c-1 != 0 else 0

for i in range(n):
    ans = 0
    if x2[i] == '0':
        t = (mod1 + pow(2, n-i-1, c+1)) % (c+1)
    else:
        if c-1 != 0:
            t = (mod2 - pow(2, n-i-1, c-1)) % (c-1)
        else:
            print(0)
            continue
    
    ans = f(t) + 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
X = input()

for i in range(N):
    if X[i] == '1':
        tmp = - (1<<(N-i-1))
        n = int(X, 2) + tmp
    else:
        tmp = (1<<(N-i-1))
        n = int(X, 2) + tmp
        
    cnt = 0
    while n != 0:
        n %= Counter(bin(n))['1']
        cnt += 1
    print(cnt)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def pop_cnt(n):
    return bin(n).count('1')


def f(n):
    cnt = 0
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    return cnt
 
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c-1 != 0 else 0

for i in range(n):
    ans = 0
    if x2[i] == '0':
        t = (mod1 + pow(2, n-i-1, c+1)) % (c+1)
    else:
        if c-1 != 0:
            t = (mod2 - pow(2, n-i-1, c-1)) % (c-1)
        else:
            print(0)
            continue
    
    ans = f(t) + 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter, defaultdict

N = int(input())
X = input()

def f(n):
    init = n
    cnt = 0
    while n != 0:
        n %= Counter(bin(n))['1']
        cnt += 1
    return cnt

for i in range(N):
    if X[i] == '1':
        tmp = - (1<<(N-i-1))
        n = int(X, 2) + tmp
    else:
        tmp = (1<<(N-i-1))
        n = int(X, 2) + tmp
    print(f(n))

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def pop_cnt(n):
    return bin(n).count('1')


def f(n):
    cnt = 0
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    return cnt
 
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c-1 != 0 else 0

for i in range(n):
    ans = 0
    if x2[i] == '0':
        t = (mod1 + pow(2, n-i-1, c+1)) % (c+1)
    else:
        if c-1 != 0:
            t = (mod2 - pow(2, n-i-1, c-1)) % (c-1)
        else:
            print(0)
            continue
    
    ans = f(t) + 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter, defaultdict

N = int(input())
X = input()

def f(n):
    init = n
    cnt = 0
    while n != 0:
        n %= Counter(bin(n))['1']
        cnt += 1
    return cnt

for i in range(N):
    if X[i] == '1':
        tmp = - (1<<(N-i-1))
        n = int(X, 2) + tmp
    else:
        tmp = (1<<(N-i-1))
        n = int(X, 2) + tmp
    print(f(n))

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def pop_cnt(n):
    return bin(n).count('1')


def f(n):
    cnt = 0
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    return cnt
 
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c-1 != 0 else 0

for i in range(n):
    ans = 0
    if x2[i] == '0':
        t = (mod1 + pow(2, n-i-1, c+1)) % (c+1)
    else:
        if c-1 != 0:
            t = (mod2 - pow(2, n-i-1, c-1)) % (c-1)
        else:
            print(0)
            continue
    
    ans = f(t) + 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter, defaultdict

N = int(input())
X = input()
x = []
for i in range(N):
    x.append(X[i])

fn = defaultdict(int)
def f(n):
    init = n
    cnt = 0
    while n != 0:
        if fn[n]:
            fn[init] = cnt + fn[n]
            return fn[init]
        n %= Counter(bin(n))['1']
        cnt += 1
    fn[init] = cnt
    return cnt

for i in range(N):
    if x[i] == '1':
        tmp = '1'
        x[i] = '0'
    else:
        tmp = '0'
        x[i] = '1'
    print(f(int(''.join(x), 2)))
    x[i] = tmp



Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def pop_cnt(n):
    return bin(n).count('1')


def f(n):
    cnt = 0
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    return cnt
 
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c-1 != 0 else 0

for i in range(n):
    ans = 0
    if x2[i] == '0':
        t = (mod1 + pow(2, n-i-1, c+1)) % (c+1)
    else:
        if c-1 != 0:
            t = (mod2 - pow(2, n-i-1, c-1)) % (c-1)
        else:
            print(0)
            continue
    
    ans = f(t) + 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
X = input()
x = []
for i in range(N):
    x.append(X[i])

def f(n):
    cnt = 0
    while n != 0:
        n %= Counter(bin(n))['1']
        cnt += 1
    return cnt

for i in range(N):
    if x[i] == '1':
        tmp = '1'
        x[i] = '0'
    else:
        tmp = '0'
        x[i] = '1'
    n = ''.join(x)
    x[i] = tmp
    print(f(int(n, 2)))

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def pop_cnt(n):
    return bin(n).count('1')


def f(n):
    cnt = 0
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    return cnt
 
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c-1 != 0 else 0

for i in range(n):
    ans = 0
    if x2[i] == '0':
        t = (mod1 + pow(2, n-i-1, c+1)) % (c+1)
    else:
        if c-1 != 0:
            t = (mod2 - pow(2, n-i-1, c-1)) % (c-1)
        else:
            print(0)
            continue
    
    ans = f(t) + 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
X = input()
x = []
for i in range(N):
    x.append(X[i])
    
def popcount(n):
    return Counter(bin(n))['1']

def f(n):
    cnt = 0
    while n != 0:
        n %= popcount(n)
        cnt += 1
    return cnt

for i in range(N):
    n = x.copy()
    if x[i] == '1':
        n[i] = '0'
    else:
        n[i] = '1'
    n = ''.join(n)
    print(f(int(n, 2)))

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def pop_cnt(n):
    return bin(n).count('1')


def f(n):
    cnt = 0
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    return cnt
 
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c-1 != 0 else 0

for i in range(n):
    ans = 0
    if x2[i] == '0':
        t = (mod1 + pow(2, n-i-1, c+1)) % (c+1)
    else:
        if c-1 != 0:
            t = (mod2 - pow(2, n-i-1, c-1)) % (c-1)
        else:
            print(0)
            continue
    
    ans = f(t) + 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
X = input()
x = []
for i in range(N):
    x.append(X[i])
    
def popcount(n):
    return Counter(bin(n))['1']

def f(n):
    cnt = 0
    while n != 0:
        n %= popcount(n)
        cnt += 1
    return cnt

for i in range(N):
    n = x.copy()
    if x[i] == '1':
        n[i] = '0'
    else:
        n[i] = '1'
    n = ''.join(n)
    print(f(int(n, 2)))

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def pop_cnt(n):
    return bin(n).count('1')


def f(n):
    cnt = 0
    while n != 0:
        n = n % pop_cnt(n)
        cnt += 1
    return cnt
 
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c-1 != 0 else 0

for i in range(n):
    ans = 0
    if x2[i] == '0':
        t = (mod1 + pow(2, n-i-1, c+1)) % (c+1)
    else:
        if c-1 != 0:
            t = (mod2 - pow(2, n-i-1, c-1)) % (c-1)
        else:
            print(0)
            continue
    
    ans = f(t) + 1
    print(ans)