#include <bits/stdc++.h>
// #include "/usr/local/include/cxx_pretty_print/cxx_pretty_print.hpp"
 
using namespace std;
/* type aliases */
using i32 = int32_t; using ui32 = uint32_t; using i64 = int64_t; using ui64 = uint64_t; using i128 = __int128;
using f32 = float;   using f64  = double;   using f80 = long double;
using PII = pair<i32, i32>; using PLL = pair<i64, i64>; using PFF = pair<f32, f32>; using PDD = pair<f64, f64>;
using VB  = vector<bool>;   using VS  = vector<string>;
using VI  = vector<i32>;    using VL  = vector<i64>;    using VF  = vector<f32>;    using VD  = vector<f64>;
using VVI = vector<VI>;     using VVL = vector<VL>;     using VVF = vector<VF>;     using VVD = vector<VD>;
using VPI = vector<PII>;    using VPL = vector<PLL>;    using VPF = vector<PFF>;    using VPD = vector<PDD>;
/* constants */
constexpr i64 mod = 1000000007;                                // 10^9+7
constexpr i64 inf = 9000000000000000000;                       // 9*10^18
/* macros */
#define MAX(c)        *max_element(ALL(c))
#define MIN(c)        *min_element(ALL(c))
#define SIZE(c)       (i64)((c).size())                        // unsined int (size_t) -> int64_t
#define ALL(c)        (c).begin(), (c).end()
#define RALL(c)       (c).rbegin(), (c).rend()
#define REP(i, n)     for (i64 i=0; i<(i64)(n); ++i)           // 0 to n-1
#define REPD(i, n)    for (i64 i=(i64)(n)-1; i>=0; --i)        // n-1 to 0
/* debug */
#define debug(x)      cerr << #x << ": " << (x) << '\n'
#define debugvec(v)   for (size_t _ = 0; _ < (v).size(); ++_) {cerr << #v << '[' << _ << "]: " << (v)[_] << '\n';}
/* useful output */
auto print = [](auto x) {cout << (x) << '\n';};
template <class T> void printvec(T v, string sep=" ", string end="\n") {REP(i, SIZE(v)-1) cout << v[i] << sep; cout << v[SIZE(v)-1] << end;}
/* useful input */
VS splitstr(string s, char delim=' ') {VS v; string buf; stringstream ss{s}; while (getline(ss, buf, delim)) v.push_back(buf); return v;}
 
 
void simulate(VI& sim) {
    i32 n = SIZE(sim);
    for (i32 i = 1; i < n; ++ i) {
        sim.at(i) = sim.at(i % __builtin_popcount(i)) + 1;
    }
}
 
 
void Main() {
    i32 n;
    string s;
    cin >> n >> s;
    i32 popcnt{};
    REP(i, n) if (s.at(i) == '1') ++popcnt;
 
    VI modpowincf(n, 1);    // modpowincf[i] = (2 ^ i) % (popcnt + 1)
    if (popcnt != n) {
        for (i32 i = 1; i < n; ++i) {
            modpowincf.at(i) = (modpowincf.at(i-1) << 1) % (popcnt + 1);
        }
    }
 
    VI modpowdecf(n, 1);
    if (popcnt - 1 != 0) {
        for (i32 i = 1; i < n; ++i) {
            modpowdecf.at(i) = (modpowdecf.at(i-1) << 1) % (popcnt - 1);
        }
    }
 
    
    i32 incfver{}, decfver{};
    REP(i, n) {
        i32 j = n - 1 - i;
        if (s.at(i) == '1') {
            if (popcnt != n) incfver = (incfver + modpowincf.at(j)) % (popcnt + 1);
            if (popcnt - 1 != 0) decfver = (decfver + modpowdecf.at(j)) % (popcnt - 1);
        }
    }
 
    VI sim(n, 0);
    simulate(sim);
    
    REP(i, n) {
        // s[i] のビットを反転させて処理回数を計算する
        i32 j = n - 1 - i;
        i32 ans{};
        if (s.at(i) == '1') {
            // debug(i);
            // debug(decfver);
            if (popcnt - 1 != 0) {
                i32 num = (decfver + (popcnt - 1) - modpowdecf.at(j)) % (popcnt - 1);
                ans += 1 + sim.at(num);
            }
        } else {
            // debug(i);
            // debug(incfver);
            i32 num = (incfver + modpowincf.at(j)) % (popcnt + 1);
            ans += 1 + sim.at(num);
        }
        print(ans);
    }
}
 
 
signed main() {
    cin.tie(nullptr);                                         // cin と cout の tie を切り高速化
    cout << fixed << setprecision(15);                        // 浮動小数点数が 1e-006 のように表示されることを防ぐ
    Main();
}

Measured memory_bytes: 5960