Buggy python submission (verdict: Runtime Error):
# %%
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f((first_zero + pow(2, n-i-1, num_of_1 + 1)) % num_of_1 + 1))
    else:
        print(1 + f((first_one - pow(2, n-i-1, num_of_1 - 1)) % num_of_1 - 1))


Fixed submission:
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f((first_zero + pow(2, n-i-1, num_of_1 + 1)) % (num_of_1 + 1)))
    else:
        print(1 + f((first_one - pow(2, n-i-1, num_of_1 - 1)) % (num_of_1 - 1)))

Buggy python submission (verdict: Runtime Error):
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f(first_zero + pow(2, n-i-1, num_of_1 + 1)))
    else:
        print(1 + f(first_one - pow(2, n-i-1, num_of_1 - 1))

Fixed submission:
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f((first_zero + pow(2, n-i-1, num_of_1 + 1)) % (num_of_1 + 1)))
    else:
        print(1 + f((first_one - pow(2, n-i-1, num_of_1 - 1)) % (num_of_1 - 1)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

for i in range(n):
    ans = 0

    if x[i] == "0":
        temp_num_of_1 = num_of_1 + 1
        a = first + pow(2, n-i-1)
    else:
        temp_num_of_1 = num_of_1 - 1
        a = first - pow(2, n-i-1)

    a = a % temp_num_of_1

    ans += 1 + f(a)

    print(ans)

Fixed submission:
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f((first_zero + pow(2, n-i-1, num_of_1 + 1)) % (num_of_1 + 1)))
    else:
        print(1 + f((first_one - pow(2, n-i-1, num_of_1 - 1)) % (num_of_1 - 1)))

Buggy python submission (verdict: Time Limit Exceeded):
# %%
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

for i in range(n):
    ans = 0

    if x[i] == "0":
        temp_num_of_1 = num_of_1 + 1
        a = first + 2 ** (n - i - 1)
    else:
        temp_num_of_1 = num_of_1 - 1
        a = first - 2 ** (n - i - 1)

    a = a % temp_num_of_1

    ans += 1 + f(a)

    print(ans)

Fixed submission:
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f((first_zero + pow(2, n-i-1, num_of_1 + 1)) % (num_of_1 + 1)))
    else:
        print(1 + f((first_one - pow(2, n-i-1, num_of_1 - 1)) % (num_of_1 - 1)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

for i in range(n):
    temp_num_of_1 = num_of_1 + 1 if x[i] == "0" else num_of_1 - 1

    ans = 0

    a = first + 2 ** (n - i - 1) if x[i] == "0" else first - 2 ** (n - i - 1)

    a = a % temp_num_of_1

    ans += 1 + f(a)

    print(ans)

Fixed submission:
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f((first_zero + pow(2, n-i-1, num_of_1 + 1)) % (num_of_1 + 1)))
    else:
        print(1 + f((first_one - pow(2, n-i-1, num_of_1 - 1)) % (num_of_1 - 1)))

Buggy python submission (verdict: Runtime Error):
# %%
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(N):
        if X[i]=='1':
            print(0)
        elif i==N-1:
            print(2)
        else:
            print(1)
    exit()

for i in range(n):
    temp_num_of_1 = num_of_1 + 1 if x[i] == "0" else num_of_1 - 1

    ans = 0

    a = first + 2 ** (n - i - 1) if x[i] == "0" else first - 2 ** (n - i - 1)

    a = a % temp_num_of_1

    temp = bin(a)[2:]

    ans += 1 + f(a)

    print(ans)

Fixed submission:
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f((first_zero + pow(2, n-i-1, num_of_1 + 1)) % (num_of_1 + 1)))
    else:
        print(1 + f((first_one - pow(2, n-i-1, num_of_1 - 1)) % (num_of_1 - 1)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x==0:
        return 0
    return 1+f(x%bin(x).count('1'))

for i in range(n):
    temp_num_of_1 = num_of_1 + 1 if x[i] == "0" else num_of_1 - 1

    ans = 0

    if temp_num_of_1 > 0:
        a = first + 2 ** (n - i - 1) if x[i] == "0" else first - 2 ** (n - i - 1)

        a = a % temp_num_of_1

        temp = bin(a)[2:]

        ans += 1 + f(a)

    print(ans)

Fixed submission:
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f((first_zero + pow(2, n-i-1, num_of_1 + 1)) % (num_of_1 + 1)))
    else:
        print(1 + f((first_one - pow(2, n-i-1, num_of_1 - 1)) % (num_of_1 - 1)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

for i in range(n):
    temp_num_of_1 = num_of_1 + 1 if x[i] == "0" else num_of_1 - 1

    ans = 0

    if temp_num_of_1 > 0:
        a = first + 2 ** (n - i - 1) if x[i] == "0" else first - 2 ** (n - i - 1)

        a = a % temp_num_of_1

        temp = bin(a)[2:]

        ans += 1
    
        while temp.count("1") != 0:
            a = int(temp, 2)

            a = a % temp.count("1")

            temp = bin(a)[2:]

            ans += 1

    print(ans)

Fixed submission:
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f((first_zero + pow(2, n-i-1, num_of_1 + 1)) % (num_of_1 + 1)))
    else:
        print(1 + f((first_one - pow(2, n-i-1, num_of_1 - 1)) % (num_of_1 - 1)))

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

n = int(input())
x = input()

x_list = list(x)

num_dict = dict(collections.Counter(x_list))

num_of_1 = num_dict["1"]

first_temp = int(x, 2)

for i in range(n):
    temp_num_of_1 = num_of_1 + 1 if x_list[i] == "0" else num_of_1 - 1

    ans = 0

    if temp_num_of_1 > 0:
        a = first_temp + 2 ** (n - i - 1) if x_list[i] == "0" else first_temp - 2 ** (n - i - 1)

        a = a % temp_num_of_1

        temp = list(bin(a)[2:])

        ans += 1
    
        while temp.count("1") != 0:
            a = int("".join(temp), 2)

            a = a % temp.count("1")

            temp = list(bin(a)[2:])

            ans += 1

    print(ans)

Fixed submission:
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f((first_zero + pow(2, n-i-1, num_of_1 + 1)) % (num_of_1 + 1)))
    else:
        print(1 + f((first_one - pow(2, n-i-1, num_of_1 - 1)) % (num_of_1 - 1)))

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

n = int(input())
x = input()

x_list = list(x)

num_dict = dict(collections.Counter(x_list))

num_of_1 = num_dict["1"]

first_temp = int("".join(x_list), 2)

for i in range(n):
    temp_num_of_1 = num_of_1 + 1 if x_list[i] == "0" else num_of_1 - 1

    ans = 0

    if temp_num_of_1 > 0:
        a = first_temp + 2 ** (n - i - 1) if x_list[i] == "0" else first_temp - 2 ** (n - i - 1)

        a = a % temp_num_of_1

        temp = list(bin(a)[2:])

        ans += 1
    
        while temp.count("1") != 0:
            a = int("".join(temp), 2)

            a = a % temp.count("1")

            temp = list(bin(a)[2:])

            ans += 1

    print(ans)

Fixed submission:
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f((first_zero + pow(2, n-i-1, num_of_1 + 1)) % (num_of_1 + 1)))
    else:
        print(1 + f((first_one - pow(2, n-i-1, num_of_1 - 1)) % (num_of_1 - 1)))

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

n = int(input())
x = input()

x_list = list(x)

num_dict = dict(collections.Counter(x_list))

num_of_1 = num_dict["1"]

for i in range(n):
    temp = x_list.copy()
    temp_num_of_1 = num_of_1 + 1 if temp[i] == "0" else num_of_1 - 1

    temp[i] = "1" if temp[i] == "0" else "0"

    ans = 0

    if temp_num_of_1 != 0:
        a = int("".join(temp), 2)

        a = a % temp_num_of_1

        temp = list(bin(a)[2:])

        ans += 1
    
        while temp.count("1") != 0:
            a = int("".join(temp), 2)

            a = a % temp.count("1")

            temp = list(bin(a)[2:])

            ans += 1

    print(ans)

Fixed submission:
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f((first_zero + pow(2, n-i-1, num_of_1 + 1)) % (num_of_1 + 1)))
    else:
        print(1 + f((first_one - pow(2, n-i-1, num_of_1 - 1)) % (num_of_1 - 1)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = input()

x_list = list(x)

for i in range(n):
    temp = x_list.copy()
    temp[i] = "1" if temp[i] == "0" else "0"

    ans = 0
    
    while temp.count("1") != 0:
        a = int("".join(temp), 2)

        a = a % temp.count("1")

        temp = list(bin(a)[2:])

        ans += 1

    print(ans)

Fixed submission:
n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f((first_zero + pow(2, n-i-1, num_of_1 + 1)) % (num_of_1 + 1)))
    else:
        print(1 + f((first_one - pow(2, n-i-1, num_of_1 - 1)) % (num_of_1 - 1)))