Buggy python submission (verdict: Runtime Error):
n = int(input())
x = int(input(),2)
# b = int(2**(n-1))
pc = 0
d = []
c = x
for i in range(n):
    d.append(c&1)
    if c&1 == 1:
        pc += 1
    c=c>>1

mp =  x%(pc+1)
mm = x%(pc-1)
# print(x,pc,mp,mm)
for i in range(n):
    if d[-i-1]==0:
        m = 1
        temp = (mp+pow(2,n-i-1,pc+1)) % (pc+1)
    else:
        m = -1
        temp = (mm-pow(2,n-i-1,pc+1)) % (pc-1)
    # temppc = pc+m
    # temp = x^b
    ans = 1
    # print(temp,x,b)
    # print(temp,mp,pc,pow(2,n-i,pc+1))
    while temp:
        
        c = temp
        temppc = 0
        while c:
            if c&1 == 1:
                temppc += 1
            c=c>>1
        # print(temp)
        # print(i,temp,ans,temppc)
        # print(temp)
        # s = str(bin(temp))
        # print(temp,popcount(temp))
        if temppc == 0:
            break
        temp = temp % temppc
        ans += 1
        # c = temp
        # temppc = 0
        # while c:
        #     if c&1 == 1:
        #         temppc += 1
        #     c=c>>1
        # print(temp,s)
        # break
    # b=b>>1
    print(ans)

Fixed submission:
n = int(input())
x = int(input(),2)
# b = int(2**(n-1))
pc = 0
d = []
c = x
for i in range(n):
    d.append(c&1)
    if c&1 == 1:
        pc += 1
    c=c>>1

mp =  x%(pc+1)
if pc == 1:
    mm = -1
else:
    mm = x%(pc-1)
# print(x,pc,mp,mm)
for i in range(n):
    if d[-i-1]==0:
        m = 1
        temp = (mp+pow(2,n-i-1,pc+1)) % (pc+1)
        ans = 1
    else:
        if mm == -1:
            temp = 0
            ans = 0
        else:    
            m = -1
            temp = (mm-pow(2,n-i-1,pc-1)) % (pc-1)
            ans = 1
    # temppc = pc+m
    # temp = x^b
    # ans = 1
    # print(temp)
    # print(temp,mm,pc,pow(2,n-i,pc+1),(mm-pow(2,n-i-1,pc+1)) % (pc-1))
    while temp:
        
        c = temp
        temppc = 0
        while c:
            if c&1 == 1:
                temppc += 1
            c=c>>1
        # print(temp)
        # print(i,temp,ans,temppc)
        # print(temp)
        # s = str(bin(temp))
        # print(temp,popcount(temp))
        if temppc == 0:
            break
        temp = temp % temppc
        ans += 1
        # c = temp
        # temppc = 0
        # while c:
        #     if c&1 == 1:
        #         temppc += 1
        #     c=c>>1
        # print(temp,s)
        # break
    # b=b>>1
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = int(input(),2)
b = int(2**(n-1))
pc = 0
d = []
c = x
for i in range(n):
    d.append(c&1)
    if c&1 == 1:
        pc += 1
    c=c>>1
# print(pc,d)
for i in range(n):
    if d[-i-1]==0:
        m = 1
    else:
        m = -1
    temppc = pc+m
    temp = x^b
    ans = 0
    # print(temp,x,b)
    while temp:
        # print(temp)
        # print(i,temp,ans,temppc)
        # print(temp)
        # s = str(bin(temp))
        # print(temp,popcount(temp))
        if temppc == 0:
            break
        temp = temp % temppc
        ans += 1
        c = temp
        temppc = 0
        while c:
            if c&1 == 1:
                temppc += 1
            c=c>>1
        # print(temp,s)
        # break
    b=b>>1
    print(ans)

Fixed submission:
n = int(input())
x = int(input(),2)
# b = int(2**(n-1))
pc = 0
d = []
c = x
for i in range(n):
    d.append(c&1)
    if c&1 == 1:
        pc += 1
    c=c>>1

mp =  x%(pc+1)
if pc == 1:
    mm = -1
else:
    mm = x%(pc-1)
# print(x,pc,mp,mm)
for i in range(n):
    if d[-i-1]==0:
        m = 1
        temp = (mp+pow(2,n-i-1,pc+1)) % (pc+1)
        ans = 1
    else:
        if mm == -1:
            temp = 0
            ans = 0
        else:    
            m = -1
            temp = (mm-pow(2,n-i-1,pc-1)) % (pc-1)
            ans = 1
    # temppc = pc+m
    # temp = x^b
    # ans = 1
    # print(temp)
    # print(temp,mm,pc,pow(2,n-i,pc+1),(mm-pow(2,n-i-1,pc+1)) % (pc-1))
    while temp:
        
        c = temp
        temppc = 0
        while c:
            if c&1 == 1:
                temppc += 1
            c=c>>1
        # print(temp)
        # print(i,temp,ans,temppc)
        # print(temp)
        # s = str(bin(temp))
        # print(temp,popcount(temp))
        if temppc == 0:
            break
        temp = temp % temppc
        ans += 1
        # c = temp
        # temppc = 0
        # while c:
        #     if c&1 == 1:
        #         temppc += 1
        #     c=c>>1
        # print(temp,s)
        # break
    # b=b>>1
    print(ans)