Buggy python submission (verdict: Runtime Error):
N = int(input())
X = input()   
              
memo = {}     
x_val = int(X, 2)
pc_x = X.count('1')
              
x_mod_pc_x_plus_1 = x_val % (pc_x + 1)
x_mod_pc_x_minus_1 = x_val % (pc_x - 1)
              
for i in range(N):
    if X[i] == '1':
        pc = pc_x - 1
        if pc == 0:
            print(0)
            continue
        val = (x_mod_pc_x_minus_1 - pow(2, N-i-1, pc)) % pc
    else:     
        pc = pc_x + 1
        val = (x_mod_pc_x_plus_1 + pow(2, N-i-1, pc)) % pc
    ans = 1   
    while val > 0:
        val %= bin(val).count('1')
        ans += 1
    print(ans)
              
              


Fixed submission:
N = int(input())
X = input()   
              
x_val = int(X, 2)
pc_x = X.count('1')
              
x_mod_pc_x_plus_1 = x_val % (pc_x + 1)
x_mod_pc_x_minus_1 = x_val % max(pc_x - 1, 1)
              
for i in range(N):
    if X[i] == '1':
        pc = pc_x - 1
        if pc == 0:
            print(0)
            continue
        val = (x_mod_pc_x_minus_1 - pow(2, N-i-1, pc)) % pc
    else:     
        pc = pc_x + 1
        val = (x_mod_pc_x_plus_1 + pow(2, N-i-1, pc)) % pc
    ans = 1   
    while val > 0:
        val %= bin(val).count('1')
        ans += 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def popcount(x):
    ans = 0   
    while x > 0:
        if x & 1:
            ans += 1
        x >>= 1
    return ans
              
def f(x, pc, memo=None):
    if memo and (x, pc) in memo:
        return memo[(x, pc)]
    r = x % pc
    if memo:  
        memo[(x, pc)] = r
    return r  
              
N = int(input())
X = input()   
              
x = int(X, 2) 
              
memo = {}     
pc_x = X.count('1')
              
for i in range(N):
    if X[i] == '1':
        pc = pc_x - 1
    else:     
        pc = pc_x + 1
    if pc == 0:
        print('0')
        continue
    f_x = f(x, pc, memo)
    f_res = f(pow(2, (N-i-1), pc), pc, memo)
    if X[i] == '1':
        f_i = f_x - f_res
    else:     
        f_i = f_x + f_res
    f_i = (f_i + 2 * pc) % pc
    ans = 1   
    while f_i > 0:
        ans += 1
        pc = popcount(f_i)
        f_i = f(f_i, pc)
    print(ans)


Fixed submission:
N = int(input())
X = input()   
              
x_val = int(X, 2)
pc_x = X.count('1')
              
x_mod_pc_x_plus_1 = x_val % (pc_x + 1)
x_mod_pc_x_minus_1 = x_val % max(pc_x - 1, 1)
              
for i in range(N):
    if X[i] == '1':
        pc = pc_x - 1
        if pc == 0:
            print(0)
            continue
        val = (x_mod_pc_x_minus_1 - pow(2, N-i-1, pc)) % pc
    else:     
        pc = pc_x + 1
        val = (x_mod_pc_x_plus_1 + pow(2, N-i-1, pc)) % pc
    ans = 1   
    while val > 0:
        val %= bin(val).count('1')
        ans += 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def popcount(x):
    ans = 0   
    while x > 0:
        if x & 1:
            ans += 1
        x >>= 1
    return ans
              
def f(x, pc, memo=None):
    if memo and (x, pc) in memo:
        return memo[(x, pc)]
    r = x % pc
    if memo:  
        memo[(x, pc)] = r
    return r  
              
N = int(input())
X = input()   
              
x = int(X, 2) 
              
memo = {}     
pc_x = X.count('1')
              
for i in range(N):
    if X[i] == '1':
        pc = pc_x - 1
    else:     
        pc = pc_x + 1
    if pc == 0:
        print('0')
        continue
    f_x = f(x, pc, memo)
    f_res = f(1<<(N-i-1), pc, memo)
    if X[i] == '1':
        f_i = f_x - f_res
    else:     
        f_i = f_x + f_res
    f_i = (f_i + 2 * pc) % pc
    ans = 1   
    while f_i > 0:
        ans += 1
        pc = popcount(f_i)
        f_i = f(f_i, pc)
    print(ans)
              

Fixed submission:
N = int(input())
X = input()   
              
x_val = int(X, 2)
pc_x = X.count('1')
              
x_mod_pc_x_plus_1 = x_val % (pc_x + 1)
x_mod_pc_x_minus_1 = x_val % max(pc_x - 1, 1)
              
for i in range(N):
    if X[i] == '1':
        pc = pc_x - 1
        if pc == 0:
            print(0)
            continue
        val = (x_mod_pc_x_minus_1 - pow(2, N-i-1, pc)) % pc
    else:     
        pc = pc_x + 1
        val = (x_mod_pc_x_plus_1 + pow(2, N-i-1, pc)) % pc
    ans = 1   
    while val > 0:
        val %= bin(val).count('1')
        ans += 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def popcount(x):
    ans = 0   
    while x > 0:
        if x & 1:
            ans += 1
        x >>= 1
    return ans
              
def f(x, pc, memo=None):
    if memo and (x, pc) in memo:
        return memo[(x, pc)]
    r = x % pc
    if memo:  
        memo[(x, pc)] = r
    return r  
              
N = int(input())
X = input()   
              
x = int(X, 2) 
              
memo = {}     
pc_x = popcount(x)
              
for i in range(N):
    if X[i] == '1':
        pc = pc_x - 1
    else:     
        pc = pc_x + 1
    if pc == 0:
        print('0')
        continue
    f_x = f(x, pc, memo)
    f_res = f(1<<(N-i-1), pc, memo)
    if X[i] == '1':
        f_i = f_x - f_res
    else:     
        f_i = f_x + f_res
    f_i = (f_i + 2 * pc) % pc
    ans = 1   
    while f_i > 0:
        ans += 1
        pc = popcount(f_i)
        f_i = f(f_i, pc)
    print(ans)
              

Fixed submission:
N = int(input())
X = input()   
              
x_val = int(X, 2)
pc_x = X.count('1')
              
x_mod_pc_x_plus_1 = x_val % (pc_x + 1)
x_mod_pc_x_minus_1 = x_val % max(pc_x - 1, 1)
              
for i in range(N):
    if X[i] == '1':
        pc = pc_x - 1
        if pc == 0:
            print(0)
            continue
        val = (x_mod_pc_x_minus_1 - pow(2, N-i-1, pc)) % pc
    else:     
        pc = pc_x + 1
        val = (x_mod_pc_x_plus_1 + pow(2, N-i-1, pc)) % pc
    ans = 1   
    while val > 0:
        val %= bin(val).count('1')
        ans += 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def popcount(x):
    ans = 0   
    while x > 0:
        if x & 1:
            ans += 1
        x >>= 1
    return ans
              
def f(x, pc, memo=None):
    if memo and (x, pc) in memo:
        return memo[(x, pc)]
    r = x % pc
    if memo:  
        memo[(x, pc)] = r
    return r  
              
N = int(input())
X = input()   
              
x = int(X, 2) 
              
memo = {}     
pc_x = popcount(x)
              
for i in range(N):
    if X[i] == '1':
        pc = pc_x - 1
    else:     
        pc = pc_x + 1
    if pc == 0:
        print('0')
        continue
    f_x = f(x, pc, memo)
    f_res = f(1<<(N-i-1), pc, memo)
    if X[i] == '1':
        f_i = f_x - f_res
    else:     
        f_i = f_x + f_res
    f_i = (f_i + 2 * pc) % pc
    ans = 1   
    while f_i > 0:
        ans += 1
        pc = popcount(f_i)
        f_i = f(f_i, pc)
    print(ans)
              

Fixed submission:
N = int(input())
X = input()   
              
x_val = int(X, 2)
pc_x = X.count('1')
              
x_mod_pc_x_plus_1 = x_val % (pc_x + 1)
x_mod_pc_x_minus_1 = x_val % max(pc_x - 1, 1)
              
for i in range(N):
    if X[i] == '1':
        pc = pc_x - 1
        if pc == 0:
            print(0)
            continue
        val = (x_mod_pc_x_minus_1 - pow(2, N-i-1, pc)) % pc
    else:     
        pc = pc_x + 1
        val = (x_mod_pc_x_plus_1 + pow(2, N-i-1, pc)) % pc
    ans = 1   
    while val > 0:
        val %= bin(val).count('1')
        ans += 1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def popcount(x):
    ans = 0   
    while x > 0:
        if x & 1:
            ans += 1
        x >>= 1
    return ans
              
def f(x, pc, memo):
    if (x, pc) in memo:
        return memo[(x, pc)]
    r = x % pc
    memo[(x, pc)] = r
    return r  
              
N = int(input())
X = input()   
              
x = int(X, 2) 
              
memo = {}     
pc_x = popcount(x)
              
for i in range(N):
    if X[i] == '1':
        pc = pc_x - 1
    else:     
        pc = pc_x + 1
    if pc == 0:
        print('0')
        continue
    f_x = f(x, pc, memo)
    f_res = f(1<<(N-i-1), pc, memo)
    if X[i] == '1':
        f_i = f_x - f_res
    else:     
        f_i = f_x + f_res
    f_i = (f_i + 2 * pc) % pc
    ans = 1   
    while f_i > 0:
        ans += 1
        pc = popcount(f_i)
        f_i = f(f_i, pc, memo)
    print(ans)

Fixed submission:
N = int(input())
X = input()   
              
x_val = int(X, 2)
pc_x = X.count('1')
              
x_mod_pc_x_plus_1 = x_val % (pc_x + 1)
x_mod_pc_x_minus_1 = x_val % max(pc_x - 1, 1)
              
for i in range(N):
    if X[i] == '1':
        pc = pc_x - 1
        if pc == 0:
            print(0)
            continue
        val = (x_mod_pc_x_minus_1 - pow(2, N-i-1, pc)) % pc
    else:     
        pc = pc_x + 1
        val = (x_mod_pc_x_plus_1 + pow(2, N-i-1, pc)) % pc
    ans = 1   
    while val > 0:
        val %= bin(val).count('1')
        ans += 1
    print(ans)