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

def popcount(x):
    tmp = x
    count = 0
    while tmp > 0:
        if tmp & 1 == 1:
            count += 1
        tmp >>= 1
    
    return count

x = int(X, 2)
pcx = X.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)


for i in range(N):
    if X[i] == '0':
        X_next = pc2 + pow(2,N-1-i,pcx+1)
        X_pop_next = pcx + 1
    else:
        X_next = pc1 - pow(2,N-1-i,pcx-1)
        X_pop_next = pcx - 1
        
    if X_pop_next == 0:
        print(0)
        continue
        
    X_next = X_next % X_pop_next
    ans = 1
    
    while X_next != 0:
        X_next = X_next % popcount(X_next)
        ans += 1
    
    print(ans)

Fixed submission:
n = int(input())
s = input()
x = int(s, 2)
pcx = s.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

for i, y in enumerate(s):
    k = n - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)

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

def popcount(x):
    tmp = x
    count = 0
    while tmp > 0:
        if tmp & 1 == 1:
            count += 1
        tmp >>= 1
    
    return count

tmp_pop_X = X.count('1')
X_tmp = int(X,2)
pc1 = X_tmp % (tmp_pop_X - 1) if tmp_pop_X > 1 else 0
pc2 = X_tmp % (tmp_pop_X + 1)

for i in range(N):
    if X[i] == '0':
        X_next = pc2 + pow(2,N-1-i,tmp_pop_X + 1)
        X_pop_next = tmp_pop_X + 1
    else:
        X_next = pc1 - pow(2,N-1-i,tmp_pop_X - 1)
        X_pop_next = tmp_pop_X - 1
        
    if X_pop_next == 0:
        print(0)
        continue
        
    X_next = X_next % X_pop_next
    ans = 1
    
    while X_next != 0:
        X_next = X_next % popcount(X_next)
        ans += 1
    
    print(ans)

Fixed submission:
n = int(input())
s = input()
x = int(s, 2)
pcx = s.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

for i, y in enumerate(s):
    k = n - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)

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

def popcount(x):
    tmp = x
    count = 0
    while tmp > 0:
        if tmp & 1 == 1:
            count += 1
        tmp >>= 1
    
    return count

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

def pow_k(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

tmp_pop_X = X.count('1')
X_tmp = int(X,2)

for i in range(N):
    if X[i] == '0':
        X_next = X_tmp + pow_k(2,N-1-i)
        X_pop_next = tmp_pop_X + 1
    else:
        X_next = X_tmp - pow_k(2,N-1-i)
        X_pop_next = tmp_pop_X - 1
        
    if X_pop_next == 0:
        print(0)
        continue
        
    X_next = X_next % X_pop_next
    ans = 1
    
    #while X_next != 0:
    #    X_next = X_next % popcount(X_next)
    #    ans += 1
    print(ans + f(X_next))

Fixed submission:
n = int(input())
s = input()
x = int(s, 2)
pcx = s.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

for i, y in enumerate(s):
    k = n - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)

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

def popcount(x):
    tmp = x
    count = 0
    while tmp > 0:
        if tmp & 1 == 1:
            count += 1
        tmp >>= 1
    
    return count

def pow_k(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

tmp_pop_X = X.count('1')
X_tmp = int(X,2)

for i in range(N):
    if X[i] == '0':
        X_next = X_tmp + pow_k(2,N-1-i)
        X_pop_next = tmp_pop_X + 1
    else:
        X_next = X_tmp - pow_k(2,N-1-i)
        X_pop_next = tmp_pop_X - 1
        
    if X_pop_next == 0:
        print(0)
        continue
        
    X_next = X_next % X_pop_next
    ans = 1
    
    while X_next != 0:
        X_next = X_next % popcount(X_next)
        ans += 1
        
    print(ans)

Fixed submission:
n = int(input())
s = input()
x = int(s, 2)
pcx = s.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

for i, y in enumerate(s):
    k = n - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)

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

def popcount(x):
    tmp = x
    count = 0
    while tmp > 0:
        if tmp & 1 == 1:
            count += 1
        tmp >>= 1
    
    return count

def pow_k(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

tmp_pop_X = X.count('1')

for i in range(N):
    if X[i] == '0':
        X_next = int(X,2) + pow_k(2,N-1-i)
        X_pop_next = tmp_pop_X + 1
    else:
        X_next = int(X,2) - pow_k(2,N-1-i)
        X_pop_next = tmp_pop_X - 1
        
    if X_pop_next == 0:
        print(0)
        continue
        
    X_next = X_next % X_pop_next
    ans = 1
    
    while X_next != 0:
        X_next = X_next % popcount(X_next)
        ans += 1
        
    print(ans)

Fixed submission:
n = int(input())
s = input()
x = int(s, 2)
pcx = s.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

for i, y in enumerate(s):
    k = n - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)

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

def popcount(x):
    tmp = x
    count = 0
    while tmp > 0:
        if tmp & 1 == 1:
            count += 1
        tmp >>= 1
    
    return count

tmp_pop_X = X.count('1')

for i in range(N):
    if X[i] == '0':
        X_next = int(X,2) + 2**(N-1-i)
        X_pop_next = tmp_pop_X + 1
    else:
        X_next = int(X,2) - 2**(N-1-i)
        X_pop_next = tmp_pop_X - 1
        
    X_next = X_next % X_pop_next
    ans = 1
    
    while X_next != 0:
        X_next = X_next % popcount(X_next)
        ans += 1
        
    print(ans)

Fixed submission:
n = int(input())
s = input()
x = int(s, 2)
pcx = s.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

for i, y in enumerate(s):
    k = n - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = input()
X_list = []
for i in range(N):
    X_list.append(int(X[i]))

import math
def solve(x):
    ans = 0
    while x != 0:
        tmp = x
        count = 0
        while x > 0:
            if x & 1 == 1:
                count += 1
            x >>= 1
        x = tmp%count
        ans += 1
    return ans

def solve2(x):
    tmp = X_list.copy()
    if tmp[x] == 1:
        tmp[x] = 0
    else:
        tmp[x] = 1
    num = 1
    ans = 0
    for i in range(N-1,-1,-1):
        ans += tmp[i]*num
        num = num*2
        
    return ans   

for i in range(N):
    tmp = solve2(i)
    ans = solve(tmp)
    print(ans)

Fixed submission:
n = int(input())
s = input()
x = int(s, 2)
pcx = s.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

for i, y in enumerate(s):
    k = n - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)

Buggy python submission (verdict: Runtime Error):
N = int(input())
X = input()
X_list = []
for i in range(N):
    X_list.append(int(X[i]))


import math
def solve(x):
    count = 0
    while x != 1:
        tmp = int(math.log2(x))
        tmp += 1
        for i in range(tmp):
            if (x >> i) & 1 == 1:
                count += 1
        x = x%count
    return x

def solve2(x):
    tmp = X_list.copy()
    if tmp[x] == 1:
        tmp[x] = 0
    else:
        tmp[x] = 1
    num = 1
    ans = 0
    for i in range(N-1,-1,-1):
        ans += tmp[i]*num
        num = num*2
        
    return ans   

for i in range(N):
    tmp = solve2(i)
    ans = solve(tmp)
    print(ans)

Fixed submission:
n = int(input())
s = input()
x = int(s, 2)
pcx = s.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

for i, y in enumerate(s):
    k = n - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)

Buggy python submission (verdict: Runtime Error):
N = int(input())
X = input()
X_list = []
for i in range(N):
    X_list.append(int(X[i]))


import math
def solve(x):
    count = 0
    while x != 1 or :
        tmp = int(math.log2(x))
        tmp += 1
        for i in range(tmp):
            if (x >> i) & 1 == 1:
                count += 1
        x = x%count
    return x

def solve2(x):
    tmp = X_list.copy()
    if tmp[x] == 1:
        tmp[x] = 0
    else:
        tmp[x] = 1
    num = 1
    ans = 0
    for i in range(N-1,-1,-1):
        ans += tmp[i]*num
        num = num*2
        
    return ans   

for i in range(N):
    tmp = solve2(i)
    ans = solve(tmp)
    print(ans)

Fixed submission:
n = int(input())
s = input()
x = int(s, 2)
pcx = s.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

for i, y in enumerate(s):
    k = n - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)