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


if one>0:
    l = [0, 1]
    for i in range(2,n):
        if i%2==0:
            l.append(1)
        else:
            l.append(l[i%bin(i).count("1")]+1)

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

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

one = x.count("1")
X = int(x, 2)

if one==1:
    for i in range(n):
        if x[i]=="1":
            print(0)
        elif i==n-1:
            print(2)
        else:
            print(1)
    
    
elif one>1:
    
    Xp = X % (one+1)
    Xm = X % (one-1)

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

    for i in range(n):
        
        if x[i]=="0":
            c = pow(2, n-i-1, one+1)
            print(f((Xp+c)%(one+1))+1)
        else:
            c = pow(2, n-i-1, one-1)
            print(f((Xm-c)%(one-1))+1)
else:
    for i in range(n):
        print(1)

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

u = X % one

l = [0, 1]
for i in range(2,n):
    if i%2==0:
        l.append(1)
    else:
        l.append(l[i%bin(i).count("1")]+1)

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

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

one = x.count("1")
X = int(x, 2)

if one==1:
    for i in range(n):
        if x[i]=="1":
            print(0)
        elif i==n-1:
            print(2)
        else:
            print(1)
    
    
elif one>1:
    
    Xp = X % (one+1)
    Xm = X % (one-1)

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

    for i in range(n):
        
        if x[i]=="0":
            c = pow(2, n-i-1, one+1)
            print(f((Xp+c)%(one+1))+1)
        else:
            c = pow(2, n-i-1, one-1)
            print(f((Xm-c)%(one-1))+1)
else:
    for i in range(n):
        print(1)

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

l = [0, 1]
for i in range(2,n):
    if i%2==0:
        l.append(1)
    else:
        c=1
        tem = i
        while tem>1:
            tem//=2
            if tem%2==1:c+=1
        l.append(l[i%c]+1)
for i in range(n):
    if x[i]=="1":
        on=one-1
    else:
        on=one+1
    t=X^(2**(n-i-1))
    print(l[t%on]+1)


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

one = x.count("1")
X = int(x, 2)

if one==1:
    for i in range(n):
        if x[i]=="1":
            print(0)
        elif i==n-1:
            print(2)
        else:
            print(1)
    
    
elif one>1:
    
    Xp = X % (one+1)
    Xm = X % (one-1)

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

    for i in range(n):
        
        if x[i]=="0":
            c = pow(2, n-i-1, one+1)
            print(f((Xp+c)%(one+1))+1)
        else:
            c = pow(2, n-i-1, one-1)
            print(f((Xm-c)%(one-1))+1)
else:
    for i in range(n):
        print(1)