Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 9)

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

lst = [-1] * (2 * N + 10)
lst[0] = 0
lst[1] = 1

def calc(x):
    if lst[x] != -1:
        return lst[x]
    count = 0
    y = x
    while y:
        if y % 2 == 1:
            count += 1
        y //= 2
    lst[x] = calc(x % count) + 1
    return lst[x]



count = X.count('1') #1の数

count1 = count - 1
count2 = count + 1

# print (count)
total1 = 0
total2 = 0

for i in range(N):
    if X[N - 1 - i] == '1':
        total1 += pow(2, i, count1)
        total1 %= (count1)

        total2 += pow(2, i, count2)
        total2 %= (count2)
# print ('total', total)

for i in range(N):
    if X[i] == '1':
        tmp_total = (total1 - pow(2, N - 1 - i, count1)) % count1
        amari = tmp_total % count1
        ans = calc(amari) + 1
        print (ans)
    else: # 0の時
        tmp_total = (total2 + pow(2, N - 1 - i, count2)) % count2
        amari = tmp_total % (count2)
        ans = calc(amari) + 1
        print (ans)






Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

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

lst = [-1] * (4 * N + 10)
lst[0] = 0
lst[1] = 1

def calc(x):
    if lst[x] != -1:
        return lst[x]
    count = 0
    y = x
    while y:
        if y % 2 == 1:
            count += 1
        y //= 2
    lst[x] = calc(x % count) + 1
    return lst[x]



count = X.count('1') #1の数

count1 = count - 1
count2 = count + 1

# print (count)
total1 = 0
total2 = 0

for i in range(N):
    if X[N - 1 - i] == '1':
        if count1 >= 1:
            total1 += pow(2, i, count1)
            total1 %= (count1)

        total2 += pow(2, i, count2)
        total2 %= (count2)
# print ('total', total)

for i in range(N):
    if X[i] == '1':
        if count1 == 0:
            print (0)
            continue
        tmp_total = (total1 - pow(2, N - 1 - i, count1)) % count1
        amari = tmp_total % count1
        ans = calc(amari) + 1
        print (ans)
    else: # 0の時
        tmp_total = (total2 + pow(2, N - 1 - i, count2)) % count2
        amari = tmp_total % (count2)
        ans = calc(amari) + 1
        print (ans)

Buggy python submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7

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

lst = [-1] * (N + 10)
lst[0] = 0
lst[1] = 1

def calc(x):
    if lst[x] != -1:
        return lst[x]
    count = 0
    y = x
    while y:
        if y % 2 == 1:
            count += 1
        y //= 2
    lst[x] = calc(x % count) + 1
    return lst[x]



count = X.count('1') #1の数
# print (count)
total = 0
for i in range(N):
    if X[N - 1 - i] == '1':
        total += pow(2, i, MOD)
        total %= MOD
# print ('total', total)

for i in range(N):
    if X[i] == '1':
        tmp_total = (total - pow(2, N - 1 - i, MOD)) % MOD
        amari = tmp_total % (count - 1)
        ans = calc(amari) + 1
        print (ans)
    else: # 0の時
        tmp_total = (total + pow(2, N - 1 - i, MOD)) % MOD
        amari = tmp_total % (count + 1)
        ans = calc(amari) + 1
        print (ans)






Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

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

lst = [-1] * (4 * N + 10)
lst[0] = 0
lst[1] = 1

def calc(x):
    if lst[x] != -1:
        return lst[x]
    count = 0
    y = x
    while y:
        if y % 2 == 1:
            count += 1
        y //= 2
    lst[x] = calc(x % count) + 1
    return lst[x]



count = X.count('1') #1の数

count1 = count - 1
count2 = count + 1

# print (count)
total1 = 0
total2 = 0

for i in range(N):
    if X[N - 1 - i] == '1':
        if count1 >= 1:
            total1 += pow(2, i, count1)
            total1 %= (count1)

        total2 += pow(2, i, count2)
        total2 %= (count2)
# print ('total', total)

for i in range(N):
    if X[i] == '1':
        if count1 == 0:
            print (0)
            continue
        tmp_total = (total1 - pow(2, N - 1 - i, count1)) % count1
        amari = tmp_total % count1
        ans = calc(amari) + 1
        print (ans)
    else: # 0の時
        tmp_total = (total2 + pow(2, N - 1 - i, count2)) % count2
        amari = tmp_total % (count2)
        ans = calc(amari) + 1
        print (ans)