n = gets.chomp.to_i
x = gets.chomp
xi = x.to_i

memo = {}

def exec(n)
  c = 0
  tmp = n
  while tmp != 0
    c += 1 if tmp % 2 == 1
    tmp /= 2
  end

  n % c
end

solver = ->(i) do
  del = 2 ** (n-i-1)
  num = s[i] == '0' ? xi + del : xi - del

  ans = 0
  arr = []

  tmp = num

  while tmp != 0
    if memo[num]
      ans += memo[num]
      break
    end
    ans += 1
    arr << tmp
    tmp = exec(tmp)
  end

  arr.each do |v|
    memo[v] = ans
    ans -= 1
  end

  memo[num]
end

n.times do |i|
  puts solver(i)
end
