#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/quo.hpp
#ifndef QUO_H
#define QUO_H

/*
a == tools::quo(a, b) * b + tools::mod(a, b)
0 <= tools::mod(a, b) < std::abs(b)
*/

namespace tools {
  template <typename T>
  constexpr T quo(const T& lhs, const T& rhs) {
    return lhs > static_cast<T>(0)
      ? lhs / rhs
      : rhs > static_cast<T>(0)
        ? -((-lhs - 1 + rhs) / rhs)
        : (-lhs - 1 + -rhs) / -rhs;
  }
}

#endif

// lib/bitcount.hpp
#ifndef BITCOUNT_HPP
#define BITCOUNT_HPP


namespace tools {
  ::std::uint32_t bitcount(::std::uint32_t x);
  ::std::uint64_t bitcount(::std::uint64_t x);
  ::std::int32_t bitcount(::std::int32_t x);
  ::std::int64_t bitcount(::std::int64_t x);
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


using i64 = ::std::int_fast64_t;
using u64 = ::std::uint_fast64_t;
using i32 = ::std::int_fast32_t;
using u32 = ::std::uint_fast32_t;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// lib/mod.hpp
#ifndef MOD_HPP
#define MOD_HPP


/*
a == tools::quo(a, b) * b + tools::mod(a, b)
0 <= tools::mod(a, b) < std::abs(b)
*/

namespace tools {
  template <typename T>
  constexpr T mod(const T& lhs, const T& rhs) {
    return lhs - ::tools::quo(lhs, rhs) * rhs;
  }
}

#endif

// lib/bitcount.cpp

namespace tools {
  ::std::uint32_t bitcount(::std::uint32_t x) {
    x = (x & static_cast<::std::uint32_t>(0x55555555ull)) + (x >> static_cast<::std::uint32_t>(1) & static_cast<::std::uint32_t>(0x55555555ull));
    x = (x & static_cast<::std::uint32_t>(0x33333333ull)) + (x >> static_cast<::std::uint32_t>(2) & static_cast<::std::uint32_t>(0x33333333ull));
    x = (x & static_cast<::std::uint32_t>(0x0f0f0f0full)) + (x >> static_cast<::std::uint32_t>(4) & static_cast<::std::uint32_t>(0x0f0f0f0full));
    x = (x & static_cast<::std::uint32_t>(0x00ff00ffull)) + (x >> static_cast<::std::uint32_t>(8) & static_cast<::std::uint32_t>(0x00ff00ffull));
    return (x & static_cast<::std::uint32_t>(0x0000ffffull)) + (x >> static_cast<::std::uint32_t>(16) & static_cast<::std::uint32_t>(0x0000ffffull));
  }

  ::std::uint64_t bitcount(::std::uint64_t x) {
    x = (x & static_cast<::std::uint64_t>(0x5555555555555555ull)) + (x >> static_cast<::std::uint64_t>(1) & static_cast<::std::uint64_t>(0x5555555555555555ull));
    x = (x & static_cast<::std::uint64_t>(0x3333333333333333ull)) + (x >> static_cast<::std::uint64_t>(2) & static_cast<::std::uint64_t>(0x3333333333333333ull));
    x = (x & static_cast<::std::uint64_t>(0x0f0f0f0f0f0f0f0full)) + (x >> static_cast<::std::uint64_t>(4) & static_cast<::std::uint64_t>(0x0f0f0f0f0f0f0f0full));
    x = (x & static_cast<::std::uint64_t>(0x00ff00ff00ff00ffull)) + (x >> static_cast<::std::uint64_t>(8) & static_cast<::std::uint64_t>(0x00ff00ff00ff00ffull));
    x = (x & static_cast<::std::uint64_t>(0x0000ffff0000ffffull)) + (x >> static_cast<::std::uint64_t>(16) & static_cast<::std::uint64_t>(0x0000ffff0000ffffull));
    return (x & static_cast<::std::uint64_t>(0x00000000ffffffffull)) + (x >> static_cast<::std::uint64_t>(32) & static_cast<::std::uint64_t>(0x00000000ffffffffull));
  }

  ::std::int32_t bitcount(::std::int32_t x) {
    return static_cast<::std::int32_t>(::tools::bitcount(static_cast<::std::uint32_t>(x)));
  }

  ::std::int64_t bitcount(::std::int64_t x) {
    return static_cast<::std::int64_t>(::tools::bitcount(static_cast<::std::uint64_t>(x)));
  }
}

// main.cpp

i64 f(const i64& n) {
  return n == 0 ? 0 : f(n % tools::bitcount(n)) + 1;
}

int main() {
  i64 N;
  std::string X;
  std::cin >> N >> X;

  const i64 popcount = std::count(X.begin(), X.end(), '1');
  if (popcount >= 2) {
    const i64 R0 = popcount + 1;

    std::vector<i64> pow2_mod_R0(N);
    pow2_mod_R0[0] = tools::mod<i64>(1, R0);
    for (i64 i = 1; i < N; ++i) {
      pow2_mod_R0[i] = tools::mod(pow2_mod_R0[i - 1] * 2, R0);
    }

    i64 X_mod_R0 = 0;
    for (i64 i = 0; i < N; ++i) {
      if (X[i] == '1') {
        X_mod_R0 = tools::mod(X_mod_R0 + pow2_mod_R0[N - i - 1], R0);
      }
    }

    const i64 R1 = popcount - 1;

    std::vector<i64> pow2_mod_R1(N);
    pow2_mod_R1[0] = tools::mod<i64>(1, R1);
    for (i64 i = 1; i < N; ++i) {
      pow2_mod_R1[i] = tools::mod(pow2_mod_R1[i - 1] * 2, R1);
    }

    i64 X_mod_R1 = 0;
    for (i64 i = 0; i < N; ++i) {
      if (X[i] == '1') {
        X_mod_R1 = tools::mod(X_mod_R1 + pow2_mod_R1[N - i - 1], R1);
      }
    }

    for (i64 i = 0; i < N; ++i) {
      std::cout << f(X[i] == '0' ? tools::mod(X_mod_R0 + pow2_mod_R0[N - i - 1], R0) : tools::mod(X_mod_R1 - pow2_mod_R1[N - i - 1], R1)) + 1 << std::endl;
    }
  } else if (popcount == 1) {
    const i64 R0 = popcount + 1;

    std::vector<i64> pow2_mod_R0(N);
    pow2_mod_R0[0] = tools::mod<i64>(1, R0);
    for (i64 i = 1; i < N; ++i) {
      pow2_mod_R0[i] = tools::mod(pow2_mod_R0[i - 1] * 2, R0);
    }

    i64 X_mod_R0 = 0;
    for (i64 i = 0; i < N; ++i) {
      if (X[i] == '1') {
        X_mod_R0 = tools::mod(X_mod_R0 + pow2_mod_R0[N - i - 1], R0);
      }
    }

    for (i64 i = 0; i < N; ++i) {
      std::cout << (X[i] == '0' ? f(tools::mod(X_mod_R0 + pow2_mod_R0[N - i - 1], R0)) + 1 : 0) << std::endl;
    }
  } else {
    for (i64 i = 0; i < N; ++i) {
      std::cout << 1 << std::endl;
    }
  }

  return 0;
}

Measured memory_bytes: 6808