Buggy python submission (verdict: Time Limit Exceeded):
def p(x):
  return bin(x).count('1')

def f(x):
  if x == 0:
    return 0
  return f(x%p(x)) + 1

N = int(input())
X = input()
cnt = X.count('1')
x = int(X,2)
a = x % (cnt + 1)
if cnt != 1:
  b = x % (cnt - 1)

for i in range(N):
  if X[i] == '0':
    k = (a + 2**(N-i-1) % (cnt + 1))%(cnt+1)
  else:
    if cnt == 1:
      print(0)
      continue
    k = (b - 2**(N-i-1) % (cnt - 1))%(cnt-1)
  print(f(k)+1)

Fixed submission:
def p(x):
  return bin(x).count('1')

def f(x):
  if x == 0:
    return 0
  return f(x%p(x)) + 1

N = int(input())
X = input()
cnt = X.count('1')
x = int(X,2)
a = x % (cnt + 1)
if cnt != 1:
  b = x % (cnt - 1)

for i in range(N):
  if X[i] == '0':
    k = a
    k += pow(2,N-i-1,cnt+1)
    k %= cnt+1
  else:
    if cnt == 1:
      print(0)
      continue
    k = b
    k -= pow(2,N-i-1,cnt-1) 
    k %= cnt-1  
  print(f(k)+1)

Buggy python submission (verdict: Time Limit Exceeded):
def p(x):
  return bin(x).count('1')

def f(x):
  if x == 0:
    return 0
  return f(x%p(x)) + 1

N = int(input())
X = input()
cnt = X.count('1')
x = int(X,2)
a = x % (cnt + 1)
if cnt != 1:
  b = x % (cnt - 1)

for i in range(N):
  if X[i] == '0':
    k = (a + 2**(N-i-1) % (cnt + 1)) % (cnt + 1)
  if X[i] == '1':
    if cnt == 1:
      print(0)
      continue
    k = (b - 2**(N-i-1) % (cnt - 1)) % (cnt - 1)  
  print(f(k)+1)

Fixed submission:
def p(x):
  return bin(x).count('1')

def f(x):
  if x == 0:
    return 0
  return f(x%p(x)) + 1

N = int(input())
X = input()
cnt = X.count('1')
x = int(X,2)
a = x % (cnt + 1)
if cnt != 1:
  b = x % (cnt - 1)

for i in range(N):
  if X[i] == '0':
    k = a
    k += pow(2,N-i-1,cnt+1)
    k %= cnt+1
  else:
    if cnt == 1:
      print(0)
      continue
    k = b
    k -= pow(2,N-i-1,cnt-1) 
    k %= cnt-1  
  print(f(k)+1)

Buggy python submission (verdict: Time Limit Exceeded):
def p(x):
  return bin(x).count('1')

def f(x):
  if x == 0:
    return 0
  return f(x%p(x)) + 1

N = int(input())
X = input()
cnt = X.count('1')
x = int(X,2)
a = x % (cnt + 1)
if cnt != 1:
  b = x % (cnt - 1)

for i in range(N):
  if X[i] == '0':
    k = (a + 2**(N-i-1) % (cnt + 1)) % (cnt + 1)
  if X[i] == '1':
    if cnt == 1:
      print(0)
      continue
    k = (b - 2**(N-i-1) % (cnt - 1)) % (cnt - 1)  
  print(f(k)+1)

Fixed submission:
def p(x):
  return bin(x).count('1')

def f(x):
  if x == 0:
    return 0
  return f(x%p(x)) + 1

N = int(input())
X = input()
cnt = X.count('1')
x = int(X,2)
a = x % (cnt + 1)
if cnt != 1:
  b = x % (cnt - 1)

for i in range(N):
  if X[i] == '0':
    k = a
    k += pow(2,N-i-1,cnt+1)
    k %= cnt+1
  else:
    if cnt == 1:
      print(0)
      continue
    k = b
    k -= pow(2,N-i-1,cnt-1) 
    k %= cnt-1  
  print(f(k)+1)

Buggy python submission (verdict: Runtime Error):
def p(x):
  a = list(bin(x))
  return a.count('1')

def f(x):
  if x == 0:
    return 0
  return f(x%p(x)) + 1

N = int(input())
X = input()
##最初の操作だけこっちでやっちゃう
cnt = X.count('1')
x = int(X,2)
a = x % (cnt + 1)
b = x % (cnt - 1)

t = [0] * N ##tは一回X[i]をp(X[i])で割った余りで置き換えた配列
for i in range(N):
  if X[i] == '0':
    t[i] = (a + 2**(N-i-1) % (cnt + 1)) % (cnt + 1)
  if X[i] == '1':
    if cnt == 1:
      t[i] = 0
      continue
    t[i] = (b - 2**(N-i-1) % (cnt - 1)) % (cnt - 1)  
  

result = []
for j in range(N):
  result.append(1 + f(t[j]))
print(*result, sep='\n')

Fixed submission:
def p(x):
  return bin(x).count('1')

def f(x):
  if x == 0:
    return 0
  return f(x%p(x)) + 1

N = int(input())
X = input()
cnt = X.count('1')
x = int(X,2)
a = x % (cnt + 1)
if cnt != 1:
  b = x % (cnt - 1)

for i in range(N):
  if X[i] == '0':
    k = a
    k += pow(2,N-i-1,cnt+1)
    k %= cnt+1
  else:
    if cnt == 1:
      print(0)
      continue
    k = b
    k -= pow(2,N-i-1,cnt-1) 
    k %= cnt-1  
  print(f(k)+1)

Buggy python submission (verdict: Runtime Error):
def f(x):
  if p(x) == 0:
    return 0
  if x % p(x) == 0:
    return 1
  return f(x%p(x)) + 1

def p(x):
  a = list(bin(x))
  return a.count('1')
  
N = int(input())
X = input()
##最初の操作だけこっちでやっちゃう
cnt = X.count('1')
x = int(X,2)
a = x % (cnt + 1)
b = x % (cnt - 1)

t = [0] * N ##tは一回X[i]をp(X[i])で割った余りで置き換えた配列
for i in range(N):
  if X[i] == '0':
    t[i] = (a + 2**i % (cnt + 1)) % (cnt + 1)
  if X[i] == '1':
    t[i] = (b - 2**i % (cnt - 1)) % (cnt - 1)  
  

result = []
for j in range(N):
  result.append(1 + f(t[j]))
print(*result, sep='\n')

Fixed submission:
def p(x):
  return bin(x).count('1')

def f(x):
  if x == 0:
    return 0
  return f(x%p(x)) + 1

N = int(input())
X = input()
cnt = X.count('1')
x = int(X,2)
a = x % (cnt + 1)
if cnt != 1:
  b = x % (cnt - 1)

for i in range(N):
  if X[i] == '0':
    k = a
    k += pow(2,N-i-1,cnt+1)
    k %= cnt+1
  else:
    if cnt == 1:
      print(0)
      continue
    k = b
    k -= pow(2,N-i-1,cnt-1) 
    k %= cnt-1  
  print(f(k)+1)

Buggy python submission (verdict: Runtime Error):
def f(x):
  if x % p(x) == 0:
    return 1
  return f(x%p(x)) + 1

def p(x):
  a = list(bin(x))
  return a.count('1')
  
N = int(input())
X = input()
A = [0] * N
for i in range(N):
  if X[i] == '1':
    A[i] = int(X,2) - 2**(N-i-1)
  else:
    A[i] = int(X,2) + 2**(N-i-1)
for j in A:
  print(f(j))

Fixed submission:
def p(x):
  return bin(x).count('1')

def f(x):
  if x == 0:
    return 0
  return f(x%p(x)) + 1

N = int(input())
X = input()
cnt = X.count('1')
x = int(X,2)
a = x % (cnt + 1)
if cnt != 1:
  b = x % (cnt - 1)

for i in range(N):
  if X[i] == '0':
    k = a
    k += pow(2,N-i-1,cnt+1)
    k %= cnt+1
  else:
    if cnt == 1:
      print(0)
      continue
    k = b
    k -= pow(2,N-i-1,cnt-1) 
    k %= cnt-1  
  print(f(k)+1)