Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    x=input().rstrip()
    p=x.count("1")
    minus=0
    plus=0
    numlst=[0]*n
    for i in range(n):
        number=2**i
        numlst[-i-1]=number
        if x[-i-1]=="1":
            plus+=number
            plus%=(p+1)
            if p!=1:
                minus+=number
                minus%=(p-1)

    def popcnt(x):
        cnt=str(bin(x)).count("1")
        x%=cnt
        return x

    for i in range(n):
        if x[i]=="0":
            amari=(plus+numlst[i]%(p+1))%(p+1)
            ans=1
            while amari>=1:
                amari=popcnt(amari)
                ans+=1
            print(ans)
        else:
            if p==1:
                print(0)
                continue
            amari=(minus-numlst[i]%(p-1))%(p-1)
            ans=1
            while amari>=1:
                amari=popcnt(amari)
                ans+=1
            print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
x=input().rstrip()
x10=int(x,2)
pcx=x.count("1")

plus=x10%(pcx+1)
if pcx>=2:
    minus=x10%(pcx-1)

def popcnt(x):
    cnt=1
    while x>=1:
        x%=(bin(x).count("1"))
        cnt+=1
    return cnt

for i in range(n):
    if x[i]=="0":
        amari=(plus+pow(2,n-i-1,pcx+1))%(pcx+1)
        print(popcnt(amari))
    else:
        if pcx==1:
            print(0)
        else:
            amari=(minus-pow(2,n-i-1,pcx-1))%(pcx-1)
            print(popcnt(amari))

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    x=input().rstrip()
    p=x.count("1")
    minus=0
    plus=0
    for i in range(n):
        if x[-i-1]=="1":
            plus+=2**i
            plus%=(p+1)
    if p!=1:
        for i in range(n):
            if x[-i-1]=="1":
                minus+=2**i
                minus%=(p-1)

    def popcnt(x):
        cnt=str(bin(x)).count("1")
        x%=cnt
        return x

    for i in range(n):
        if x[i]=="0":
            amari=(plus+2**(n-i-1)%(p+1))%(p+1)
            ans=1
            while amari>=1:
                amari=popcnt(amari)
                ans+=1
            print(ans)
        else:
            if p==1:
                print(0)
                continue
            amari=(minus-2**(n-i-1)%(p-1))%(p-1)
            ans=1
            while amari>=1:
                amari=popcnt(amari)
                ans+=1
            print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
x=input().rstrip()
x10=int(x,2)
pcx=x.count("1")

plus=x10%(pcx+1)
if pcx>=2:
    minus=x10%(pcx-1)

def popcnt(x):
    cnt=1
    while x>=1:
        x%=(bin(x).count("1"))
        cnt+=1
    return cnt

for i in range(n):
    if x[i]=="0":
        amari=(plus+pow(2,n-i-1,pcx+1))%(pcx+1)
        print(popcnt(amari))
    else:
        if pcx==1:
            print(0)
        else:
            amari=(minus-pow(2,n-i-1,pcx-1))%(pcx-1)
            print(popcnt(amari))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
n=int(input())
x=input().rstrip()
p=x.count("1")
minus=0
plus=0
for i in range(n):
    if x[-i-1]=="1":
        plus+=2**i
        plus%=(p+1)
if p!=1:
    for i in range(n):
        if x[-i-1]=="1":
            minus+=2**i
            minus%=(p-1)

def popcnt(x):
    cnt=str(bin(x)).count("1")
    x%=cnt
    return x

for i in range(n):
    if x[i]=="0":
        amari=(plus+2**(n-i-1)%(p+1))%(p+1)
        ans=1
        while amari>=1:
            amari=popcnt(amari)
            ans+=1
        print(ans)
    else:
        if p==1:
            print(0)
            continue
        amari=(minus-2**(n-i-1)%(p-1))%(p-1)
        ans=1
        while amari>=1:
            amari=popcnt(amari)
            ans+=1
        print(ans)

Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
x=input().rstrip()
x10=int(x,2)
pcx=x.count("1")

plus=x10%(pcx+1)
if pcx>=2:
    minus=x10%(pcx-1)

def popcnt(x):
    cnt=1
    while x>=1:
        x%=(bin(x).count("1"))
        cnt+=1
    return cnt

for i in range(n):
    if x[i]=="0":
        amari=(plus+pow(2,n-i-1,pcx+1))%(pcx+1)
        print(popcnt(amari))
    else:
        if pcx==1:
            print(0)
        else:
            amari=(minus-pow(2,n-i-1,pcx-1))%(pcx-1)
            print(popcnt(amari))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
n=int(input())
x=input().rstrip()
p=x.count("1")
numx=0
for i in range(n):
    if x[-i-1]=="1":
        numx+=2**i
if p!=1:
    minus=numx%(p-1)
plus=numx%(p+1)

def popcnt(x):
    cnt=str(bin(x)).count("1")
    x%=cnt
    return x

for i in range(n):
    if x[i]=="0":
        amari=(plus+2**(n-i-1)%(p+1))%(p+1)
        ans=1
        while amari>=1:
            amari=popcnt(amari)
            ans+=1
        print(ans)
    else:
        if p==1:
            print(0)
            continue
        amari=(minus-2**(n-i-1)%(p-1))%(p-1)
        ans=1
        while amari>=1:
            amari=popcnt(amari)
            ans+=1
        print(ans)

Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
x=input().rstrip()
x10=int(x,2)
pcx=x.count("1")

plus=x10%(pcx+1)
if pcx>=2:
    minus=x10%(pcx-1)

def popcnt(x):
    cnt=1
    while x>=1:
        x%=(bin(x).count("1"))
        cnt+=1
    return cnt

for i in range(n):
    if x[i]=="0":
        amari=(plus+pow(2,n-i-1,pcx+1))%(pcx+1)
        print(popcnt(amari))
    else:
        if pcx==1:
            print(0)
        else:
            amari=(minus-pow(2,n-i-1,pcx-1))%(pcx-1)
            print(popcnt(amari))

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n=int(input())
x=input().rstrip()
p=x.count("1")
numx=0
for i in range(n):
    if x[-i-1]=="1":
        numx+=2**i
minus=numx%(p-1)
plus=numx%(p+1)

def popcnt(x):
    cnt=str(bin(x)).count("1")
    x%=cnt
    return x

for i in range(n):
    if x[i]=="0":
        amari=(plus+2**(n-i-1)%(p+1))%(p+1)
        ans=1
        while amari>=1:
            amari=popcnt(amari)
            ans+=1
        print(ans)
    else:
        if p==1:
            print(0)
            continue
        amari=(minus-2**(n-i-1)%(p-1))%(p-1)
        ans=1
        while amari>=1:
            amari=popcnt(amari)
            ans+=1
        print(ans)

Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
x=input().rstrip()
x10=int(x,2)
pcx=x.count("1")

plus=x10%(pcx+1)
if pcx>=2:
    minus=x10%(pcx-1)

def popcnt(x):
    cnt=1
    while x>=1:
        x%=(bin(x).count("1"))
        cnt+=1
    return cnt

for i in range(n):
    if x[i]=="0":
        amari=(plus+pow(2,n-i-1,pcx+1))%(pcx+1)
        print(popcnt(amari))
    else:
        if pcx==1:
            print(0)
        else:
            amari=(minus-pow(2,n-i-1,pcx-1))%(pcx-1)
            print(popcnt(amari))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
n=int(input())
x=input().rstrip()
def popcnt(x):
    cnt=str(bin(x)).count("1")
    x%=cnt
    return x

a=0
for i in range(n):
    if x[-i-1]=="1":
        a+=2**i
for i in range(n):
    if x[i]=="1":
        b=a-2**(n-i-1)
    else:
        b=a+2**(n-i-1)
    p=0
    while b>=1:
        b=popcnt(b)
        p+=1
    print(p)

Fixed submission:
import sys
input=sys.stdin.readline
n=int(input())
x=input().rstrip()
x10=int(x,2)
pcx=x.count("1")

plus=x10%(pcx+1)
if pcx>=2:
    minus=x10%(pcx-1)

def popcnt(x):
    cnt=1
    while x>=1:
        x%=(bin(x).count("1"))
        cnt+=1
    return cnt

for i in range(n):
    if x[i]=="0":
        amari=(plus+pow(2,n-i-1,pcx+1))%(pcx+1)
        print(popcnt(amari))
    else:
        if pcx==1:
            print(0)
        else:
            amari=(minus-pow(2,n-i-1,pcx-1))%(pcx-1)
            print(popcnt(amari))