Buggy python submission (verdict: Runtime Error):
n=int(input())
x=list(map(int,list(input())))
def popcount(x):
  ret=0
  while x:
    if x%2==1:ret+=1
    x//=2
  return ret
def f(x):
  ret=0
  while x:
    x%=popcount(x)
    ret+=1
  return ret
from collections import Counter
xpop=Counter(x)[1]
xint_mi,xint_pl=0,0
for i,y in enumerate(x):
  xint_mi+=(pow(2,n-i-1,xpop-1)*y)%(xpop-1)
  xint_mi%=(xpop-1)
  xint_pl+=(pow(2,n-i-1,xpop+1)*y)%(xpop+1)
  xint_pl%=(xpop+1)


for i,y in enumerate(x):
  if y:
    yint=xint_mi-pow(2,n-i-1,xpop-1)
    ypop=xpop-1
    yint%=ypop
  else:
    yint=xint_pl+pow(2,n-i-1,xpop+1)
    ypop=xpop+1
    yint%=ypop
  #print(yint,ypop)
  print(f(yint)+1)


Fixed submission:
n=int(input())
x=input()
import sys
sys.setrecursionlimit(10**7)
if n==1:
  print(0 if x=='1' else 1)
  exit()
def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
if pcx==0:
  for _ in range(n):
    print(1)
else:
  x0,x1=0,0
  for i in range(n):
    if x[i]=='1':
      if pcx!=1:
        x0+=pow(2,n-1-i,pcx-1)
        x0%=pcx-1
      x1+=pow(2,n-1-i,pcx+1)
      x1%=pcx+1
  for i in range(n):
    ans=0
    if x[i]=='1':
      if pcx==1:
        print(0)
      else:
        xx=x0-pow(2,n-1-i,pcx-1)
        xx%=pcx-1
        print(func(xx)+1)
    else:
      xx=x1+pow(2,n-1-i,pcx+1)
      xx%=pcx+1
      print(func(xx)+1)

Buggy python submission (verdict: Runtime Error):
n=int(input())
x=list(map(int,list(input())))
def popcount(x):
  ret=0
  while x:
    if x%2==1:ret+=1
    x//=2
  return ret
def f(x):
  ret=0
  while x:
    x%=popcount(x)
    ret+=1
  return ret
from collections import Counter
xpop=Counter(x)[1]

xint_mi=sum([(pow(2,n-i-1,xpop-1)*y)%(xpop-1) for i,y in enumerate(x)])
xint_pl=sum([(pow(2,n-i-1,xpop+1)*y)%(xpop+1) for i,y in enumerate(x)])

for i,y in enumerate(x):
  if y:
    yint=xint_mi-pow(2,n-i-1,xpop-1)
    ypop=xpop-1
    yint%=ypop
  else:
    yint=xint_pl+pow(2,n-i-1,xpop+1)
    ypop=xpop+1
    yint%=ypop
  #print(yint,ypop)
  print(f(yint)+1)


Fixed submission:
n=int(input())
x=input()
import sys
sys.setrecursionlimit(10**7)
if n==1:
  print(0 if x=='1' else 1)
  exit()
def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
if pcx==0:
  for _ in range(n):
    print(1)
else:
  x0,x1=0,0
  for i in range(n):
    if x[i]=='1':
      if pcx!=1:
        x0+=pow(2,n-1-i,pcx-1)
        x0%=pcx-1
      x1+=pow(2,n-1-i,pcx+1)
      x1%=pcx+1
  for i in range(n):
    ans=0
    if x[i]=='1':
      if pcx==1:
        print(0)
      else:
        xx=x0-pow(2,n-1-i,pcx-1)
        xx%=pcx-1
        print(func(xx)+1)
    else:
      xx=x1+pow(2,n-1-i,pcx+1)
      xx%=pcx+1
      print(func(xx)+1)

Buggy python submission (verdict: Runtime Error):
n=int(input())
x=list(map(int,list(input())))
def popcount(x):
  ret=0
  while x:
    if x%2==1:ret+=1
    x//=2
  return ret
def f(x):
  ret=0
  while x:
    x%=popcount(x)
    ret+=1
  return ret
from collections import Counter
xpop=Counter(x)[1]

xint_mi=sum([(pow(2,n-i-1,xpop-1,xpop-1)*y)%(xpop-1) for i,y in enumerate(x)])
xint_pl=sum([(pow(2,n-i-1,xpop+1,xpop+1)*y)%(xpop+1) for i,y in enumerate(x)])

for i,y in enumerate(x):
  if y:
    yint=xint_mi-pow(2,n-i-1)
    ypop=xpop-1
    yint%=ypop
  else:
    yint=xint_pl+pow(2,n-i-1)
    ypop=xpop+1
    yint%=ypop
  #print(yint,ypop)
  print(f(yint)+1)


Fixed submission:
n=int(input())
x=input()
import sys
sys.setrecursionlimit(10**7)
if n==1:
  print(0 if x=='1' else 1)
  exit()
def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
if pcx==0:
  for _ in range(n):
    print(1)
else:
  x0,x1=0,0
  for i in range(n):
    if x[i]=='1':
      if pcx!=1:
        x0+=pow(2,n-1-i,pcx-1)
        x0%=pcx-1
      x1+=pow(2,n-1-i,pcx+1)
      x1%=pcx+1
  for i in range(n):
    ans=0
    if x[i]=='1':
      if pcx==1:
        print(0)
      else:
        xx=x0-pow(2,n-1-i,pcx-1)
        xx%=pcx-1
        print(func(xx)+1)
    else:
      xx=x1+pow(2,n-1-i,pcx+1)
      xx%=pcx+1
      print(func(xx)+1)

Buggy python submission (verdict: Runtime Error):
n=int(input())
x=list(map(int,list(input())))
def popcount(x):
  ret=0
  while x:
    if x%2==1:ret+=1
    x//=2
  return ret
def f(x):
  ret=0
  while x:
    x%=popcount(x)
    ret+=1
  return ret
from collections import Counter
xpop=Counter(x)[1]

xint_mi=sum([(pow(2,n-i-1,xpop-1,xpop-1)*y)%(xpop-1) for i,y in enumerate(x)])
xint_pl=sum([(pow(2,n-i-1,xpop+1,xpop+1)*y)%(xpop+1) for i,y in enumerate(x)])

for i,y in enumerate(x):
  if y:
    yint=xint_mi-pow(2,n-i-1)
    ypop=xpop-1
    yint%=ypop
  else:
    yint=xint_pl+pow(2,n-i-1)
    ypop=xpop+1
    yint%=ypop
  #print(yint,ypop)
  print(f(yint)+1)


Fixed submission:
n=int(input())
x=input()
import sys
sys.setrecursionlimit(10**7)
if n==1:
  print(0 if x=='1' else 1)
  exit()
def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
if pcx==0:
  for _ in range(n):
    print(1)
else:
  x0,x1=0,0
  for i in range(n):
    if x[i]=='1':
      if pcx!=1:
        x0+=pow(2,n-1-i,pcx-1)
        x0%=pcx-1
      x1+=pow(2,n-1-i,pcx+1)
      x1%=pcx+1
  for i in range(n):
    ans=0
    if x[i]=='1':
      if pcx==1:
        print(0)
      else:
        xx=x0-pow(2,n-1-i,pcx-1)
        xx%=pcx-1
        print(func(xx)+1)
    else:
      xx=x1+pow(2,n-1-i,pcx+1)
      xx%=pcx+1
      print(func(xx)+1)

Buggy python submission (verdict: Runtime Error):
n=int(input())
x=list(map(int,list(input())))
def popcount(x):
  ret=0
  while x:
    if x%2==1:ret+=1
    x//=2
  return ret
def f(x):
  ret=0
  while x:
    x%=popcount(x)
    ret+=1
  return ret
from collections import Counter
xpop=Counter(x)[1]

xint_mi=sum([(pow(2,n-i-1,xpop-1)*y)%(xpop-1) for i,y in enumerate(x)])
xint_pl=sum([(pow(2,n-i-1,xpop+1)*y)%(xpop+1) for i,y in enumerate(x)])

for i,y in enumerate(x):
  if y:
    yint=xint_mi-pow(2,n-i-1)
    ypop=xpop-1
    yint%=ypop
  else:
    yint=xint_pl+pow(2,n-i-1)
    ypop=xpop+1
    yint%=ypop
  #print(yint,ypop)
  print(f(yint)+1)


Fixed submission:
n=int(input())
x=input()
import sys
sys.setrecursionlimit(10**7)
if n==1:
  print(0 if x=='1' else 1)
  exit()
def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
if pcx==0:
  for _ in range(n):
    print(1)
else:
  x0,x1=0,0
  for i in range(n):
    if x[i]=='1':
      if pcx!=1:
        x0+=pow(2,n-1-i,pcx-1)
        x0%=pcx-1
      x1+=pow(2,n-1-i,pcx+1)
      x1%=pcx+1
  for i in range(n):
    ans=0
    if x[i]=='1':
      if pcx==1:
        print(0)
      else:
        xx=x0-pow(2,n-1-i,pcx-1)
        xx%=pcx-1
        print(func(xx)+1)
    else:
      xx=x1+pow(2,n-1-i,pcx+1)
      xx%=pcx+1
      print(func(xx)+1)

Buggy python submission (verdict: Runtime Error):
n=int(input())
x=list(map(int,list(input())))
def popcount(x):
  ret=0
  while x:
    if x%2==1:ret+=1
    x//=2
  return ret
def f(x):
  ret=0
  while x:
    x%=popcount(x)
    ret+=1
  return ret
from collections import Counter
xpop=Counter(x)[1]
xint=sum([pow(2,n-i-1)*y for i,y in enumerate(x)])
for i,y in enumerate(x):
  if y:
    yint=xint-pow(2,n-i-1)
    ypop=xpop-1
  else:
    yint=xint+pow(2,n-i-1)
    ypop=xpop+1
  #print(yint,ypop)
  yint%=ypop
  print(f(yint)+1)


Fixed submission:
n=int(input())
x=input()
import sys
sys.setrecursionlimit(10**7)
if n==1:
  print(0 if x=='1' else 1)
  exit()
def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
if pcx==0:
  for _ in range(n):
    print(1)
else:
  x0,x1=0,0
  for i in range(n):
    if x[i]=='1':
      if pcx!=1:
        x0+=pow(2,n-1-i,pcx-1)
        x0%=pcx-1
      x1+=pow(2,n-1-i,pcx+1)
      x1%=pcx+1
  for i in range(n):
    ans=0
    if x[i]=='1':
      if pcx==1:
        print(0)
      else:
        xx=x0-pow(2,n-1-i,pcx-1)
        xx%=pcx-1
        print(func(xx)+1)
    else:
      xx=x1+pow(2,n-1-i,pcx+1)
      xx%=pcx+1
      print(func(xx)+1)

Buggy python submission (verdict: Runtime Error):
n=int(input())
x=input()
import sys
sys.setrecursionlimit(10**7)
if n==1:
  print(1 if x=='1' else 0)
  exit()
def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
if pcx==0:
  for _ in range(n):
    print(1)
else:
  x0,x1=0,0
  
  for i in range(n):
    if x[i]=='1':
      #if pcx!=1:
      x0+=pow(2,n-1-i,pcx-1)
      x0%=pcx-1
      x1+=pow(2,n-1-i,pcx+1)
      x1%=pcx+1
  for i in range(n):
    ans=0
    if x[i]=='1':
      if pcx==1:
        print(0)
      else:
        xx=x0-pow(2,n-1-i,pcx-1)
        xx%=pcx-1
        print(func(xx)+1)
    else:
      xx=x1+pow(2,n-1-i,pcx+1)
      xx%=pcx+1
      print(func(xx)+1)


Fixed submission:
n=int(input())
x=input()
import sys
sys.setrecursionlimit(10**7)
if n==1:
  print(0 if x=='1' else 1)
  exit()
def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
if pcx==0:
  for _ in range(n):
    print(1)
else:
  x0,x1=0,0
  for i in range(n):
    if x[i]=='1':
      if pcx!=1:
        x0+=pow(2,n-1-i,pcx-1)
        x0%=pcx-1
      x1+=pow(2,n-1-i,pcx+1)
      x1%=pcx+1
  for i in range(n):
    ans=0
    if x[i]=='1':
      if pcx==1:
        print(0)
      else:
        xx=x0-pow(2,n-1-i,pcx-1)
        xx%=pcx-1
        print(func(xx)+1)
    else:
      xx=x1+pow(2,n-1-i,pcx+1)
      xx%=pcx+1
      print(func(xx)+1)

Buggy python submission (verdict: Runtime Error):
n=int(input())
x=input()
import sys
sys.setrecursionlimit(10**7)

def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
x0,x1=0,0
for i in range(n):
  if x[i]=='1':
    x0+=pow(2,n-1-i,pcx-1)
    x0%=pcx-1
    x1+=pow(2,n-1-i,pcx+1)
    x1%=pcx+1
for i in range(n):
  ans=0
  if x[i]=='1':
    xx=x0-pow(2,n-1-i,pcx-1)
    xx%=pcx-1
    print(func(xx)+1)
  else:
    xx=x1+pow(2,n-1-i,pcx+1)
    xx%=pcx+1
    print(func(xx)+1)


Fixed submission:
n=int(input())
x=input()
import sys
sys.setrecursionlimit(10**7)
if n==1:
  print(0 if x=='1' else 1)
  exit()
def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
if pcx==0:
  for _ in range(n):
    print(1)
else:
  x0,x1=0,0
  for i in range(n):
    if x[i]=='1':
      if pcx!=1:
        x0+=pow(2,n-1-i,pcx-1)
        x0%=pcx-1
      x1+=pow(2,n-1-i,pcx+1)
      x1%=pcx+1
  for i in range(n):
    ans=0
    if x[i]=='1':
      if pcx==1:
        print(0)
      else:
        xx=x0-pow(2,n-1-i,pcx-1)
        xx%=pcx-1
        print(func(xx)+1)
    else:
      xx=x1+pow(2,n-1-i,pcx+1)
      xx%=pcx+1
      print(func(xx)+1)

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

def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
x0,x1=0,0
for i in range(n):
  if x[i]=='1':
    x0+=pow(2,n-1-i,pcx-1)
    x0%=pcx-1
    x1+=pow(2,n-1-i,pcx+1)
    x1%=pcx+1
for i in range(n):
  ans=0
  if x[i]=='1':
    xx=x0-pow(2,n-1-i,pcx-1)
    xx%=pcx-1
    print(func(xx)+1)
  else:
    xx=x1+pow(2,n-1-i,pcx+1)
    xx%=pcx+1
    print(func(xx)+1)


Fixed submission:
n=int(input())
x=input()
import sys
sys.setrecursionlimit(10**7)
if n==1:
  print(0 if x=='1' else 1)
  exit()
def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
if pcx==0:
  for _ in range(n):
    print(1)
else:
  x0,x1=0,0
  for i in range(n):
    if x[i]=='1':
      if pcx!=1:
        x0+=pow(2,n-1-i,pcx-1)
        x0%=pcx-1
      x1+=pow(2,n-1-i,pcx+1)
      x1%=pcx+1
  for i in range(n):
    ans=0
    if x[i]=='1':
      if pcx==1:
        print(0)
      else:
        xx=x0-pow(2,n-1-i,pcx-1)
        xx%=pcx-1
        print(func(xx)+1)
    else:
      xx=x1+pow(2,n-1-i,pcx+1)
      xx%=pcx+1
      print(func(xx)+1)

Buggy python submission (verdict: Runtime Error):
n=int(input())
x=input()
memo={}
import sys
sys.setrecursionlimit(10**7)

def func(m,i):
  if m in memo:
    return memo[m]
  elif m%i==0:
    memo[m]=1
    return 1
  else:
    ret=0
    mm=m%i
    ii=bin(mm).count('1')
    ret+=func(mm,ii)+1
    memo[m]=ret
    return ret

c=x.count('1')
xx=0
for i in range(n):
  xx+=pow(2,i)*int(x[-1-i])
for i in range(n):
  if x[i]=='0':
    xxx=xx+pow(2,n-1-i)
    cc=c+1
  else:
    xxx=xx-pow(2,n-1-i)
    cc=c-1
  print(func(xxx,cc))
#print(memo)


Fixed submission:
n=int(input())
x=input()
import sys
sys.setrecursionlimit(10**7)
if n==1:
  print(0 if x=='1' else 1)
  exit()
def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
if pcx==0:
  for _ in range(n):
    print(1)
else:
  x0,x1=0,0
  for i in range(n):
    if x[i]=='1':
      if pcx!=1:
        x0+=pow(2,n-1-i,pcx-1)
        x0%=pcx-1
      x1+=pow(2,n-1-i,pcx+1)
      x1%=pcx+1
  for i in range(n):
    ans=0
    if x[i]=='1':
      if pcx==1:
        print(0)
      else:
        xx=x0-pow(2,n-1-i,pcx-1)
        xx%=pcx-1
        print(func(xx)+1)
    else:
      xx=x1+pow(2,n-1-i,pcx+1)
      xx%=pcx+1
      print(func(xx)+1)

Buggy python submission (verdict: Runtime Error):
n=int(input())
x=input()
memo={}

def func(m,i):
  if m in memo:
    return memo[m]
  elif m%i==0:
    memo[m]=1
    return 1
  else:
    ret=0
    mm=m%i
    ii=bin(mm).count('1')
    ret+=func(mm,ii)+1
    memo[m]=ret
    return ret

c=x.count('1')
xx=0
for i in range(n):
  xx+=pow(2,i)*int(x[-1-i])
for i in range(n):
  if x[i]=='0':
    xxx=xx+pow(2,n-1-i)
    cc=c+1
  else:
    xxx=xx-pow(2,n-1-i)
    cc=c-1
  print(func(xxx,cc))
#print(memo)

Fixed submission:
n=int(input())
x=input()
import sys
sys.setrecursionlimit(10**7)
if n==1:
  print(0 if x=='1' else 1)
  exit()
def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
if pcx==0:
  for _ in range(n):
    print(1)
else:
  x0,x1=0,0
  for i in range(n):
    if x[i]=='1':
      if pcx!=1:
        x0+=pow(2,n-1-i,pcx-1)
        x0%=pcx-1
      x1+=pow(2,n-1-i,pcx+1)
      x1%=pcx+1
  for i in range(n):
    ans=0
    if x[i]=='1':
      if pcx==1:
        print(0)
      else:
        xx=x0-pow(2,n-1-i,pcx-1)
        xx%=pcx-1
        print(func(xx)+1)
    else:
      xx=x1+pow(2,n-1-i,pcx+1)
      xx%=pcx+1
      print(func(xx)+1)