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

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

if n==1:
    if x=="0":
        print(1)
    else:
        print(0)
    sys.exit()


lis=[0,1]

for i in range(2,n+1):
    ni=i
    cnti=0
    while ni!=0:
        if ni%2==1:
            cnti+=1
        ni=ni//2
    lis.append(lis[i%cnti]+1)

cnt=0
for i in range(len(x)):
    if x[i]=="1":
        cnt+=1

cpls=cnt+1
cmns=cnt-1

cplis=[1]
if cpls!=0:
    for i in range(n):
        cplis.append((cplis[i]*2)%cpls)
cmlis=[1]
if cmns!=0:
    for i in range(n):
        cmlis.append((cmlis[i]*2)%cmns)

cpsum=0
cmsum=0
for i in range(n):
    if x[i]=="1":
        cpsum=(cpsum+cplis[n-1-i])%cpls
        cmsum=(cmsum+cmlis[n-1-i])%cmns

for i in range(n):
    if x[i]=="0":
        Xi=(cpsum+cplis[n-1-i])%cpls
        print(lis[Xi]+1)
    else:
        if cmns==0:
            print(0)
        else:
            Xi=(cmsum-cmlis[n-1-i])%cmns
            print(lis[Xi]+1)

Fixed submission:
import sys

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

if n==1:
    if x=="0":
        print(1)
    else:
        print(0)
    sys.exit()


lis=[0,1]

for i in range(2,n+1):
    ni=i
    cnti=0
    while ni!=0:
        if ni%2==1:
            cnti+=1
        ni=ni//2
    lis.append(lis[i%cnti]+1)

cnt=0
for i in range(len(x)):
    if x[i]=="1":
        cnt+=1

cpls=cnt+1
cmns=cnt-1

cplis=[1]
if cpls!=0:
    for i in range(n):
        cplis.append((cplis[i]*2)%cpls)
cmlis=[1]
if cmns!=0:
    for i in range(n):
        cmlis.append((cmlis[i]*2)%cmns)

cpsum=0
cmsum=0
for i in range(n):
    if x[i]=="1":
        cpsum=(cpsum+cplis[n-1-i])%cpls
        if cmns!=0:
            cmsum=(cmsum+cmlis[n-1-i])%cmns

for i in range(n):
    if x[i]=="0":
        Xi=(cpsum+cplis[n-1-i])%cpls
        print(lis[Xi]+1)
    else:
        if cmns==0:
            print(0)
        else:
            Xi=(cmsum-cmlis[n-1-i])%cmns
            print(lis[Xi]+1)

Buggy python submission (verdict: Runtime Error):
n=int(input())
x=input()
X=0
for i in range(n):
    X+=int(x[n-1-i])*(2**i)

lis=[0,1]

for i in range(2,n+1):
    ni=i
    cnti=0
    while ni!=0:
        if ni%2==1:
            cnti+=1
        ni=ni//2
    lis.append(lis[i%cnti]+1)

cnt=0
for i in range(len(x)):
    if x[i]=="1":
        cnt+=1

for i in range(n):
    Xi=X
    ci=cnt
    if x[i]=="0":
        Xi+=2**(n-1-i)
        ci+=1
    else:
        Xi-=2**(n-1-i)
        ci-=1
    print(lis[Xi%ci]+1)

Fixed submission:
import sys

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

if n==1:
    if x=="0":
        print(1)
    else:
        print(0)
    sys.exit()


lis=[0,1]

for i in range(2,n+1):
    ni=i
    cnti=0
    while ni!=0:
        if ni%2==1:
            cnti+=1
        ni=ni//2
    lis.append(lis[i%cnti]+1)

cnt=0
for i in range(len(x)):
    if x[i]=="1":
        cnt+=1

cpls=cnt+1
cmns=cnt-1

cplis=[1]
if cpls!=0:
    for i in range(n):
        cplis.append((cplis[i]*2)%cpls)
cmlis=[1]
if cmns!=0:
    for i in range(n):
        cmlis.append((cmlis[i]*2)%cmns)

cpsum=0
cmsum=0
for i in range(n):
    if x[i]=="1":
        cpsum=(cpsum+cplis[n-1-i])%cpls
        if cmns!=0:
            cmsum=(cmsum+cmlis[n-1-i])%cmns

for i in range(n):
    if x[i]=="0":
        Xi=(cpsum+cplis[n-1-i])%cpls
        print(lis[Xi]+1)
    else:
        if cmns==0:
            print(0)
        else:
            Xi=(cmsum-cmlis[n-1-i])%cmns
            print(lis[Xi]+1)