Buggy python submission (verdict: Time Limit Exceeded):
def solve(N,X):
    ans = []
    cnt = X.count("1")

    for i in range(N):
        if X[i] == "1":
            X[i] = "0"
            ans.append(cal(X,cnt-1,0))
            X[i] = "1"
        else:
            X[i] = "1"
            ans.append(cal(X,cnt+1,0))
            X[i] = "0"

    return ans

def cal(X,cnt,rec):
    if cnt == 0:
        return rec
    else:
        amari = 0
        for i in range(len(X)):
            if X[i] == "1":
                amari += pow(2,len(X)-i-1,cnt)
                amari %= cnt
        b = bin(amari)[2:]
        Y = [b[i] for i in range(len(b))]
        cnt = Y.count("1")
        return cal(Y,cnt,rec+1)

def main():
    N = int(input())
    X = list(input())

    ans = solve(N,X)
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()


Fixed submission:
def solve(N,X):
    ans = []
    cnt = X.count("1")
    rem_ori = [0,0]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem_ori[0] += pow(2,N-i-1,cnt-1)
                rem_ori[0] %= (cnt-1)
            else:
                rem_ori[0] = 0
            rem_ori[1] += pow(2,N-i-1,cnt+1)
            rem_ori[1] %= (cnt+1)

    rem = [(rem_ori[0] if X[i] == "1" else rem_ori[1]) for i in range(N)]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem[i] -= pow(2,N-i-1,cnt-1)
                rem[i] %= (cnt-1)
                ans.append(cal(rem[i],1))
            else:
                ans.append(0)
        else:
            rem[i] += pow(2,N-i-1,cnt+1)
            rem[i] %= (cnt+1)
            ans.append(cal(rem[i],1))

    return ans

def cal(rem,rec):
    if rem == 0:
        return rec
    else:
        b = bin(rem)[2:]
        cnt = b.count("1")
        rem %= cnt
        return cal(rem,rec+1)

def main():
    N = int(input())
    X = input()

    ans = solve(N,X)
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N,X):
    ans = []
    cnt = X.count("1")

    for i in range(N):
        if X[i] == "1":
            X[i] = "0"
            ans.append(cal(X,cnt-1,0))
            X[i] = "1"
        else:
            X[i] = "1"
            ans.append(cal(X,cnt+1,0))
            X[i] = "0"

    return ans

def cal(X,cnt,rec):
    if cnt == 0:
        return rec
    else:
        amari = 0
        for i in range(len(X)):
            if X[i] == "1":
                amari += pow(2,len(X)-i-1,cnt)
                amari %= cnt
        b = bin(amari)[2:]
        Y = [b[i] for i in range(len(b))]
        cnt = Y.count("1")
        return cal(Y,cnt,rec+1)

def main():
    N = int(input())
    X = list(input())

    ans = solve(N,X)
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()


Fixed submission:
def solve(N,X):
    ans = []
    cnt = X.count("1")
    rem_ori = [0,0]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem_ori[0] += pow(2,N-i-1,cnt-1)
                rem_ori[0] %= (cnt-1)
            else:
                rem_ori[0] = 0
            rem_ori[1] += pow(2,N-i-1,cnt+1)
            rem_ori[1] %= (cnt+1)

    rem = [(rem_ori[0] if X[i] == "1" else rem_ori[1]) for i in range(N)]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem[i] -= pow(2,N-i-1,cnt-1)
                rem[i] %= (cnt-1)
                ans.append(cal(rem[i],1))
            else:
                ans.append(0)
        else:
            rem[i] += pow(2,N-i-1,cnt+1)
            rem[i] %= (cnt+1)
            ans.append(cal(rem[i],1))

    return ans

def cal(rem,rec):
    if rem == 0:
        return rec
    else:
        b = bin(rem)[2:]
        cnt = b.count("1")
        rem %= cnt
        return cal(rem,rec+1)

def main():
    N = int(input())
    X = input()

    ans = solve(N,X)
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N,x):
    ans = []
    cnt = 0
    for i in range(N):
        if 2**i & x != 0:
            cnt += 1

    ans_dict = {}
    for i in range(10**3):
        ans_dict[i] = cal(i,0,{})

    for i in range(N):
        x ^= 2**(N-i-1)
        ans.append(cal(x,0,ans_dict))
        x ^= 2**(N-i-1)
    return ans

def cal(x,rec,ans_dict):
    if x in ans_dict:
        return ans_dict[x] + rec
    else:
        cnt,dig = 0,0
        while 2**dig <= x:
            if 2**dig & x != 0:
                cnt += 1
            dig += 1

        if cnt == 0:
            return rec
        else:
            amari = 0
            for i in range(dig):
                if x & 2**i != 0:
                    amari += pow(2,i,cnt)
                    amari %= cnt
            return cal(amari,rec+1,ans_dict)

def main():
    N = int(input())
    X = input()

    x = 0
    for i in range(N):
        if X[i] == "1":
            x += pow(2,N-i-1)

    ans = solve(N,x)
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()


Fixed submission:
def solve(N,X):
    ans = []
    cnt = X.count("1")
    rem_ori = [0,0]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem_ori[0] += pow(2,N-i-1,cnt-1)
                rem_ori[0] %= (cnt-1)
            else:
                rem_ori[0] = 0
            rem_ori[1] += pow(2,N-i-1,cnt+1)
            rem_ori[1] %= (cnt+1)

    rem = [(rem_ori[0] if X[i] == "1" else rem_ori[1]) for i in range(N)]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem[i] -= pow(2,N-i-1,cnt-1)
                rem[i] %= (cnt-1)
                ans.append(cal(rem[i],1))
            else:
                ans.append(0)
        else:
            rem[i] += pow(2,N-i-1,cnt+1)
            rem[i] %= (cnt+1)
            ans.append(cal(rem[i],1))

    return ans

def cal(rem,rec):
    if rem == 0:
        return rec
    else:
        b = bin(rem)[2:]
        cnt = b.count("1")
        rem %= cnt
        return cal(rem,rec+1)

def main():
    N = int(input())
    X = input()

    ans = solve(N,X)
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N,x):
    ans = []
    cnt = 0
    for i in range(N):
        if 2**i & x != 0:
            cnt += 1

    for i in range(N):
        x ^= 2**(N-i-1)
        ans.append(cal(x,0))
        x ^= 2**(N-i-1)
    return ans

def cal(x,rec):
    cnt,dig = 0,0
    while 2**dig <= x:
        if 2**dig & x != 0:
            cnt += 1
        dig += 1

    if cnt == 0:
        return rec
    else:
        amari = 0
        for i in range(dig):
            if x & 2**i != 0:
                amari += pow(2,i,cnt)
                amari %= cnt
        return cal(amari,rec+1)

def main():
    N = int(input())
    X = input()

    x = 0
    for i in range(N):
        if X[i] == "1":
            x += pow(2,N-i-1)

    ans = solve(N,x)
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()


Fixed submission:
def solve(N,X):
    ans = []
    cnt = X.count("1")
    rem_ori = [0,0]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem_ori[0] += pow(2,N-i-1,cnt-1)
                rem_ori[0] %= (cnt-1)
            else:
                rem_ori[0] = 0
            rem_ori[1] += pow(2,N-i-1,cnt+1)
            rem_ori[1] %= (cnt+1)

    rem = [(rem_ori[0] if X[i] == "1" else rem_ori[1]) for i in range(N)]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem[i] -= pow(2,N-i-1,cnt-1)
                rem[i] %= (cnt-1)
                ans.append(cal(rem[i],1))
            else:
                ans.append(0)
        else:
            rem[i] += pow(2,N-i-1,cnt+1)
            rem[i] %= (cnt+1)
            ans.append(cal(rem[i],1))

    return ans

def cal(rem,rec):
    if rem == 0:
        return rec
    else:
        b = bin(rem)[2:]
        cnt = b.count("1")
        rem %= cnt
        return cal(rem,rec+1)

def main():
    N = int(input())
    X = input()

    ans = solve(N,X)
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N,X):
    ans = []
    cnt = X.count("1")

    for i in range(N):
        if X[i] == "1":
            X[i] = "0"
            ans.append(cal(X,0))
            X[i] = "1"
        else:
            X[i] = "1"
            ans.append(cal(X,0))
            X[i] = "0"
    return ans

def cal(X,rec):
    cnt = X.count("1")
    if cnt == 0:
        return rec
    else:
        amari = 0
        for i in range(len(X)):
            if X[i] == "1":
                amari += pow(2,len(X)-i-1,cnt)
                amari %= cnt
        b = bin(amari)[2:]
        Y = [b[i] for i in range(len(b))]
        return cal(Y,rec+1)

def main():
    N = int(input())
    X = list(input())

    ans = solve(N,X)
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()


Fixed submission:
def solve(N,X):
    ans = []
    cnt = X.count("1")
    rem_ori = [0,0]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem_ori[0] += pow(2,N-i-1,cnt-1)
                rem_ori[0] %= (cnt-1)
            else:
                rem_ori[0] = 0
            rem_ori[1] += pow(2,N-i-1,cnt+1)
            rem_ori[1] %= (cnt+1)

    rem = [(rem_ori[0] if X[i] == "1" else rem_ori[1]) for i in range(N)]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem[i] -= pow(2,N-i-1,cnt-1)
                rem[i] %= (cnt-1)
                ans.append(cal(rem[i],1))
            else:
                ans.append(0)
        else:
            rem[i] += pow(2,N-i-1,cnt+1)
            rem[i] %= (cnt+1)
            ans.append(cal(rem[i],1))

    return ans

def cal(rem,rec):
    if rem == 0:
        return rec
    else:
        b = bin(rem)[2:]
        cnt = b.count("1")
        rem %= cnt
        return cal(rem,rec+1)

def main():
    N = int(input())
    X = input()

    ans = solve(N,X)
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N,X):
    ans = []
    cnt = X.count("1")

    for i in range(N):
        if X[i] == "1":
            X[i] = "0"
            ans.append(cal(X,0))
            X[i] = "1"
        else:
            X[i] = "1"
            ans.append(cal(X,0))
            X[i] = "0"
    return ans

def cal(X,rec):
    cnt = X.count("1")
    if cnt == 0:
        return rec
    else:
        amari = 0
        for i in range(len(X)):
            if X[i] == "1":
                amari += pow(2,len(X)-i-1,cnt)
                amari %= cnt
        b = bin(amari)[2:]
        Y = [b[i] for i in range(len(b))]
        return cal(Y,rec+1)

def main():
    N = int(input())
    X = list(input())

    ans = solve(N,X)
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()


Fixed submission:
def solve(N,X):
    ans = []
    cnt = X.count("1")
    rem_ori = [0,0]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem_ori[0] += pow(2,N-i-1,cnt-1)
                rem_ori[0] %= (cnt-1)
            else:
                rem_ori[0] = 0
            rem_ori[1] += pow(2,N-i-1,cnt+1)
            rem_ori[1] %= (cnt+1)

    rem = [(rem_ori[0] if X[i] == "1" else rem_ori[1]) for i in range(N)]
    for i in range(N):
        if X[i] == "1":
            if cnt != 1:
                rem[i] -= pow(2,N-i-1,cnt-1)
                rem[i] %= (cnt-1)
                ans.append(cal(rem[i],1))
            else:
                ans.append(0)
        else:
            rem[i] += pow(2,N-i-1,cnt+1)
            rem[i] %= (cnt+1)
            ans.append(cal(rem[i],1))

    return ans

def cal(rem,rec):
    if rem == 0:
        return rec
    else:
        b = bin(rem)[2:]
        cnt = b.count("1")
        rem %= cnt
        return cal(rem,rec+1)

def main():
    N = int(input())
    X = input()

    ans = solve(N,X)
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()