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

n = int(input())
X = list(input())

popcount = [0]*(2*10**5)

num = int("".join(X), 2)
cnt = X.count("1")

for i in range(1,2*10**5):
    tmp_cnt = bin(i).count("1")
    popcount[i] = i%tmp_cnt

for i,x in enumerate(X):
    tmp = copy.deepcopy(X)
    ans = 1
    if x == "0":
        tmp[i] = "1"
        now = int("".join(tmp), 2)
        now = now%(cnt+1)
    else:
        tmp[i] = "0"
        now = int("".join(tmp), 2)
        now = now%(cnt-1)
    while now:
        now = popcount[now]
        ans += 1
    print(ans)

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

cnt = [0]*(200001)
for i in range(1,200001):
    pc = bin(i).count('1')
    cnt[i] = cnt[i%pc] + 1
    
plus = X.count("1")+1
minus = X.count("1")-1

defp = int(X, 2)%plus
if minus:
    defm = int(X, 2)%minus
else:
    defm = None

pl = 1
mi = 1
ans = []
for i, x in enumerate(X[::-1]):
    if x == "0":
        ans.append(cnt[(defp+pl)%plus]+1)
    else:
        if minus:
            ans.append(cnt[(defm-mi)%minus]+1)
        else:
            ans.append(0)
    pl = 2*pl%plus
    if minus:
        mi = 2*mi%minus

print(*ans[::-1], sep="\n")

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

cnt = [0]*(200001)
for i in range(1,200001):
    pc = bin(i).count('1')
    cnt[i] = cnt[i%pc] + 1
    
plus = X.count("1")+1
minus = X.count("1")-1

defp = int(X, 2)%plus
defm = int(X, 2)%minus

pl = 1
mi = 1
ans = []
for i, x in enumerate(X[::-1]):
    if x == "0":
        ans.append(cnt[(defp+pl)%plus]+1)
    else:
        if minus:
            ans.append(cnt[(defm-mi)%minus]+1)
        else:
            ans.append(0)
    pl = 2*pl%plus
    if minus:
        mi = 2*mi%minus

print(*ans[::-1], sep="\n")

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

cnt = [0]*(200001)
for i in range(1,200001):
    pc = bin(i).count('1')
    cnt[i] = cnt[i%pc] + 1
    
plus = X.count("1")+1
minus = X.count("1")-1

defp = int(X, 2)%plus
if minus:
    defm = int(X, 2)%minus
else:
    defm = None

pl = 1
mi = 1
ans = []
for i, x in enumerate(X[::-1]):
    if x == "0":
        ans.append(cnt[(defp+pl)%plus]+1)
    else:
        if minus:
            ans.append(cnt[(defm-mi)%minus]+1)
        else:
            ans.append(0)
    pl = 2*pl%plus
    if minus:
        mi = 2*mi%minus

print(*ans[::-1], sep="\n")

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

cnt_1 = 0
for x in X:
    if x == "1":
        cnt_1 += 1

plus = [0]*n
minus = [0]*n
plus[0] = 1%(cnt_1+1)
minus[0] = 1%(cnt_1-1)
for i in range(1,n):
    plus[i] = (plus[i-1]*2)%(cnt_1+1)
    minus[i] = (minus[i]*2)%(cnt_1-1)

cnt = [0]*(200001)

for i in range(1,200001):
    pc = bin(i).count('1')
    cnt[i] = cnt[i%pc] + 1

ans = []
for i,x in enumerate(X[::-1]):
    if x == "0":
        res = plus[n-1] + plus[i]
        ans.append(cnt[res]+1)
    else:
        res = minus[n-1] + minus[i]
        ans.append(cnt[res]+1)

print(*ans[::-1],sep="\n")

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

cnt = [0]*(200001)
for i in range(1,200001):
    pc = bin(i).count('1')
    cnt[i] = cnt[i%pc] + 1
    
plus = X.count("1")+1
minus = X.count("1")-1

defp = int(X, 2)%plus
if minus:
    defm = int(X, 2)%minus
else:
    defm = None

pl = 1
mi = 1
ans = []
for i, x in enumerate(X[::-1]):
    if x == "0":
        ans.append(cnt[(defp+pl)%plus]+1)
    else:
        if minus:
            ans.append(cnt[(defm-mi)%minus]+1)
        else:
            ans.append(0)
    pl = 2*pl%plus
    if minus:
        mi = 2*mi%minus

print(*ans[::-1], sep="\n")

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

def popcount(num):
    return num.count('1')

popc = [-1]*(n+1)
dp = [-1]*(n+1)#index=わったあまり

for i in range(1,n+1):
    now = list(x)
    if now[i-1] == '0':
        now[i-1] = "1"
    else:
        now[i-1] = "0"
    now = "".join(now)
    
    ans = 0
    hozon = int(now,2)%popcount(now)
    while True:
        """
        if popc[int(now,2)] == -1:
            popc[int(now,2)] = popcount(now)
        """
        
        amari = int(now,2)%popcount(now) 
        if dp[amari] != -1:
            ans += dp[amari]
            dp[hozon] = ans
            break
        now = amari
        ans += 1
        if now == 0:
            break
        now = bin(now)[2:]
    
    print(ans) 

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

cnt = [0]*(200001)
for i in range(1,200001):
    pc = bin(i).count('1')
    cnt[i] = cnt[i%pc] + 1
    
plus = X.count("1")+1
minus = X.count("1")-1

defp = int(X, 2)%plus
if minus:
    defm = int(X, 2)%minus
else:
    defm = None

pl = 1
mi = 1
ans = []
for i, x in enumerate(X[::-1]):
    if x == "0":
        ans.append(cnt[(defp+pl)%plus]+1)
    else:
        if minus:
            ans.append(cnt[(defm-mi)%minus]+1)
        else:
            ans.append(0)
    pl = 2*pl%plus
    if minus:
        mi = 2*mi%minus

print(*ans[::-1], sep="\n")