Problem p02609 (python)

Fixed submission:
n = int(input())
X = input()
x = int(X,2)
bitx = bin(x).count('1')
 
ans = [0]*(bitx+2)
for i in range(1,bitx+2):
    ans[i] = 1 + ans[i%bin(i).count('1')]
#print(ans)
l = []
bitp = bitx + 1
bitm = bitx - 1
xmp = 0
xmm = 0


if bitx != 1:
    for i in range(n):
        if X[i] == '1':
            xmp += pow(2, n-(i+1), bitp)
            xmm += pow(2, n-(i+1), bitm)
    for i in range(n):
        if X[i] == '1':
            xm = (xmm - pow(2,n-i-1,bitm)) % bitm
            l.append(str(1+ans[xm]))
        else:
            xm = (xmp + pow(2,n-i-1,bitp))%bitp
            l.append(str(1+ans[xm]))
 
else:
    for i in range(n):
        if X[i] == '1':
            xmp += pow(2, n-(i+1), bitp)
    for i in range(n):
        if X[i] == '1':
            l.append(str(0))
        else:
            xm = (xmp + pow(2,n-i-1,bitp))%bitp
            l.append(str(1+ans[xm]))
 
print('\n'.join(l))

Buggy submission (verdict: Runtime Error):
n = int(input())
X = input()
x = int(X,2)
bitx = bin(x).count('1')
 
ans = [0]*(bitx+1)
for i in range(1,len(ans)):
    ans[i] = 1 + ans[i%bin(i).count('1')]
#print(ans)
l = []
bitp = bitx + 1
bitm = bitx - 1
xmp = 0
xmm = 0
 
for i in range(n):
    if X[i] == '1':
        xmp += pow(2, n-(i+1), bitp)
        xmm += pow(2, n-(i+1), bitm)
        
for i in range(n):
    if X[i] == '1':
        if bitm == 0:
            l.append(str(0))
        else:
        	xm = (xmm - pow(2,n-i-1,bitm)) % bitm
        	l.append(str(1+ans[xm]))
    else:
        xm = (xmp + pow(2,n-i-1,bitp))%bitp
        l.append(str(1+ans[xm]))

    #print(1+ans[t])
print('\n'.join(l))

Buggy submission (verdict: Runtime Error):
n = int(input())
X = input()
x = int(X,2)
bitx = bin(x).count('1')
 
ans = [0]*(bitx+2)
for i in range(1,bitx+2):
    ans[i] = 1 + ans[i%bin(i).count('1')]
#print(ans)
l = []
bitp = bitx + 1
bitm = bitx - 1
xmp = 0
xmm = 0

for i in range(n):
    if X[i] == '1':
        xmp += pow(2, n-(i+1), bitp)
        xmm += pow(2, n-(i+1), bitm)
if bitx != 1:
    for i in range(n):
        if X[i] == '1':
            xm = (xmm - pow(2,n-i-1,bitm)) % bitm
            l.append(str(1+ans[xm]))
        else:
            xm = (xmp + pow(2,n-i-1,bitp))%bitp
            l.append(str(1+ans[xm]))

else:
    for i in range(n):
        if X[i] == '1':
            l.append(str(0))
        else:
            xm = (xmp + pow(2,n-i-1,bitp))%bitp
            l.append(str(1+ans[xm]))

print('\n'.join(l))

Buggy submission (verdict: Runtime Error):
n = int(input())
X = input()
x = int(X,2)
bitx = bin(x).count('1')
 
ans = [0]*(bitx+2)
for i in range(1,bitx+2):
    ans[i] = 1 + ans[i%bin(i).count('1')]
#print(ans)
l = []
bitp = bitx + 1
bitm = bitx - 1
xmp = 0
xmm = 0
for i in range(n):
    if X[i] == '1':
        xmp += pow(2, n-(i+1), bitp)
        xmm += pow(2, n-(i+1), bitm)
if bitx != 1:
    for i in range(n):
        if X[i] == '1':
            xm = (xmm - pow(2,n-i-1)) % bitm
            l.append(str(1+ans[xm]))
        else:
            xm = (xmp + pow(2,n-i-1))%bitp
            l.append(str(1+ans[xm]))

else:
    for i in range(n):
        if X[i] == '1':
            l.append(str(0))
        else:
            xm = (xmp + pow(2,n-i-1))%bitp
            l.append(str(1+ans[xm]))

print('\n'.join(l))

Buggy submission (verdict: Runtime Error):
n = int(input())
x = int(input(),2)
bitx = bin(x).count('1')
 
ans = [0]*(bitx+1)
for i in range(1,bitx+1):
    ans[i] = 1 + ans[i%bin(i).count('1')]
#print(ans)
l = []
bitp = bitx + 1
bitm = bitx - 1
xmp = x % bitp
xmm = x % bitm
if bitx != 1:
    for i in range(n):
        if x>>(n-i-1)&1:
            xm = (xmm - pow(2,n-i-1)) % bitm
            l.append(str(1+ans[xm]))
        else:
            xm = (xmp + pow(2,n-i-1))%bitp
            l.append(str(1+ans[xm]))

else:
    for i in range(n):
        if x>>(n-i-1)&1:
            l.append(str(0))
        else:
            xm = (xmp + pow(2,n-i-1))%bitp
            l.append(str(1+ans[xm]))

print('\n'.join(l))

Buggy submission (verdict: Runtime Error):
n = int(input())
x = int(input(),2)
bitx = bin(x).count('1')

ans = [0]*(bitx+1)
for i in range(1,bitx+1):
    ans[i] = 1 + ans[i%bin(i).count('1')]
#print(ans)
l = []
if bitx != 1:
    for i in range(n):
        y = x^(1<<(n-i-1))
        if y>>(n-i-1)&1:
            l.append(str(1+ans[y % bitx+1]))
        else:
            l.append(str(1+ans[y % bitx-1]))
else:
    for i in range(n):
        y = x^(1<<(n-i-1))
        if y>>(n-i-1)&1:
            l.append(str(1+ans[y % bitx+1]))
        else:
            l.append(str(0))
    #print(1+ans[t])
print('\n'.join(l))

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
x = int(input(),2)
if bin(x).count('1')+1 >= 1000:
    sys.setrecursionlimit(bin(x).count('1')+1)

ans = [0]*(bin(x).count('1')+1)
for i in range(1,len(ans)):
    ans[i] = 1 + ans[i%bin(i).count('1')]
#print(ans)
l = []
for i in range(n):
    y = x^(1<<(n-i-1))
    t = y % bin(y).count('1')
    l.append(str(1+ans[t]))
    #print(1+ans[t])
print('\n'.join(l))

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
x = int(input(),2)
if bin(x).count('1')+1 > 1000:
    sys.setrecursionlimit(bin(x).count('1')+1)
    
ans = [0]*(bin(x).count('1')+1)
for i in range(1,len(ans)):
    ans[i] = 1 + ans[i%bin(i).count('1')]
#print(ans)
for i in range(n):
    y = x^(1<<(n-i-1))
    t = y % bin(y).count('1')
    print(1+ans[t])

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

ans = [0]*(str(bin(x)).count('1')+1)
for i in range(1,len(ans)):
    ans[i] = 1 + ans[i%str(bin(i)).count('1')]
#print(ans)
for i in range(n):
    y = x^(1<<(n-i-1))
    t = y % str(bin(y)).count('1')
    print(1+ans[t])

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
'''再帰
def f(n):
    t = int(n,2) % list(n).count('1')
    if t == 0:
        return 1
    else:
        return f(str(bin(t))) + 1
'''
def f(n):
    
    t = int(n,2) % list(n).count('1')
    cnt = 1
    while(t):
        t = t % str(bin(t)).count('1')
        cnt += 1
        #print(cnt)
    return cnt

for i in range(n):
    xb = list(x)
    xb[i] = '0' if xb[i] == '1' else '1'
    print(f(''.join(xb)))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2000)

n = int(input())
x = input()

def f(n):
    t = int(n,2) % list(n).count('1')
    if t == 0:
        return 1
    else:
        return f(str(bin(t))) + 1

for i in range(n):
    xb = list(x)
    xb[i] = '0' if xb[i] == '1' else '1'
    print(f(''.join(xb)))

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

def f(n):
    t = int(n,2) % list(n).count('1')
    if t == 0:
        return 1
    else:
        return f(str(bin(t))) + 1

for i in range(n):
    xb = list(x)
    xb[i] = '0' if xb[i] == '1' else '1'
    print(f(''.join(xb)))