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

def popcount(l):
    return bin(l).count("1")
def count(l):
    res = 0
    while l != 0:
        p = popcount(l)
        l %= p
        res += 1
    return res
m = popcount(x)
x_plus = x%(m+1)
x_minus = x%(m-1)
lis_plus = [0]*n
lis_minus = [0]*n
for i in range(n):
    if i == 0:
        lis_plus[i] = 1%(m+1)
        if m != 1:
            lis_minus[i] = 1%(m-1)
    else:
        lis_plus[i] = lis_plus[i-1]*2%(m+1)
        if m != 1:
            lis_minus[i] = lis_minus[i-1]*2%(m-1)
for i in range(n):
    if (x >> (n-i-1)) & 1:
        if m == 1:
            print(0)
        else:
            print(count((x_minus - lis_minus[-i-1])%(m-1)) + 1)
    else:
        print(count((x_plus + lis_plus[-i-1])%(m+1)) + 1)

Fixed submission:
n = int(input())
x = int(input(),2)

def popcount(l):
    return bin(l).count("1")
def count(l):
    res = 0
    while l != 0:
        p = popcount(l)
        l %= p
        res += 1
    return res
m = popcount(x)
x_plus = x%(m+1)
if m != 1:
    x_minus = x%(m-1)
else:
    x_minus = 1
lis_plus = [0]*n
lis_minus = [0]*n
for i in range(n):
    if i == 0:
        lis_plus[i] = 1%(m+1)
        if m != 1:
            lis_minus[i] = 1%(m-1)
    else:
        lis_plus[i] = lis_plus[i-1]*2%(m+1)
        if m != 1:
            lis_minus[i] = lis_minus[i-1]*2%(m-1)
for i in range(n):
    if (x >> (n-i-1)) & 1:
        if m == 1:
            print(0)
        else:
            print(count((x_minus - lis_minus[-i-1])%(m-1)) + 1)
    else:
        print(count((x_plus + lis_plus[-i-1])%(m+1)) + 1)

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

def popcount(l):
    return bin(l).count("1")
def count(l):
    res = 0
    while l != 0:
        p = popcount(l)
        l %= p
        res += 1
    return res
m = popcount(x)
x_plus = x%(m+1)
x_minus = x%(m-1)
lis_plus = []
lis_minus = []
for i in range(n):
    if i == 0:
        lis_plus.append(1%(m+1))
        if m != 1:
            lis_minus.append(1%(m-1))
    else:
        lis_plus.append(lis_plus[-1]*2%(m+1))
        if m != 1:
            lis_minus.append(lis_minus[-1]*2%(m-1))
for i in range(n):
    if (x >> (n-i-1)) & 1:
        if m == 1:
            print(0)
        else:
            print(count((x_minus - lis_minus[-i-1])%(m-1)) + 1)
    else:
        print(count((x_plus + lis_plus[-i-1])%(m+1)) + 1)

Fixed submission:
n = int(input())
x = int(input(),2)

def popcount(l):
    return bin(l).count("1")
def count(l):
    res = 0
    while l != 0:
        p = popcount(l)
        l %= p
        res += 1
    return res
m = popcount(x)
x_plus = x%(m+1)
if m != 1:
    x_minus = x%(m-1)
else:
    x_minus = 1
lis_plus = [0]*n
lis_minus = [0]*n
for i in range(n):
    if i == 0:
        lis_plus[i] = 1%(m+1)
        if m != 1:
            lis_minus[i] = 1%(m-1)
    else:
        lis_plus[i] = lis_plus[i-1]*2%(m+1)
        if m != 1:
            lis_minus[i] = lis_minus[i-1]*2%(m-1)
for i in range(n):
    if (x >> (n-i-1)) & 1:
        if m == 1:
            print(0)
        else:
            print(count((x_minus - lis_minus[-i-1])%(m-1)) + 1)
    else:
        print(count((x_plus + lis_plus[-i-1])%(m+1)) + 1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = input()
x_int = int(x, 2)
xi = []
for i in range(n):
    if x[i] == "0":
        xi.append(x_int + 2**(n-i-1))
    else:
        xi.append(x_int - 2**(n-i-1))
def popcount(m):
    return bin(m).count("1")
for i in range(len(xi)):
    m = xi[i]
    ans = 0
    while m != 0:
        m %= popcount(m)
        ans += 1
    print(ans)

Fixed submission:
n = int(input())
x = int(input(),2)

def popcount(l):
    return bin(l).count("1")
def count(l):
    res = 0
    while l != 0:
        p = popcount(l)
        l %= p
        res += 1
    return res
m = popcount(x)
x_plus = x%(m+1)
if m != 1:
    x_minus = x%(m-1)
else:
    x_minus = 1
lis_plus = [0]*n
lis_minus = [0]*n
for i in range(n):
    if i == 0:
        lis_plus[i] = 1%(m+1)
        if m != 1:
            lis_minus[i] = 1%(m-1)
    else:
        lis_plus[i] = lis_plus[i-1]*2%(m+1)
        if m != 1:
            lis_minus[i] = lis_minus[i-1]*2%(m-1)
for i in range(n):
    if (x >> (n-i-1)) & 1:
        if m == 1:
            print(0)
        else:
            print(count((x_minus - lis_minus[-i-1])%(m-1)) + 1)
    else:
        print(count((x_plus + lis_plus[-i-1])%(m+1)) + 1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = input()
xlis = []
for i in range(n):
    xlis.append(x[i])
xi = []
def flip(m):
    if m == "1":
        return "0"
    else:
        return "1"
for i in range(n):
    if i == 0:
        xlis[i] = flip(xlis[i])
        xi.append("".join(xlis))
    else:
        xlis[i-1] = flip(xlis[i-1])
        xlis[i] = flip(xlis[i])
        xi.append("".join(xlis))
def popcount(m):
    return bin(m).count("1")
for i in range(len(xi)):
    xi[i] = int(xi[i], 2)
for i in range(len(xi)):
    m = xi[i]
    ans = 0
    while m != 0:
        m %= popcount(m)
        ans += 1
    print(ans)

Fixed submission:
n = int(input())
x = int(input(),2)

def popcount(l):
    return bin(l).count("1")
def count(l):
    res = 0
    while l != 0:
        p = popcount(l)
        l %= p
        res += 1
    return res
m = popcount(x)
x_plus = x%(m+1)
if m != 1:
    x_minus = x%(m-1)
else:
    x_minus = 1
lis_plus = [0]*n
lis_minus = [0]*n
for i in range(n):
    if i == 0:
        lis_plus[i] = 1%(m+1)
        if m != 1:
            lis_minus[i] = 1%(m-1)
    else:
        lis_plus[i] = lis_plus[i-1]*2%(m+1)
        if m != 1:
            lis_minus[i] = lis_minus[i-1]*2%(m-1)
for i in range(n):
    if (x >> (n-i-1)) & 1:
        if m == 1:
            print(0)
        else:
            print(count((x_minus - lis_minus[-i-1])%(m-1)) + 1)
    else:
        print(count((x_plus + lis_plus[-i-1])%(m+1)) + 1)