/*
    Author : DemonStar
*/

#pragma GCC optimize("Ofast")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define loop(i, n) for(ll i = 0; i < n; i++)
#define pl pair<ll, ll>
#define vl vector<ll>
#define endl '\n'
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
    for (auto &i : t) os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &t : v) is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
    for (pair<T1, T2> &t : v) is >> t.first >> t.second;
    return is;
}

const ll mod = 1e9 + 7;

ll modpow(ll n, ll p, ll m) {
    ll ans = 1;
    while (p) {
        if (p & 1) (ans *= n) %= m;
        (n *= n) %= m, p /= 2;
    }
    return ans;
}

ll calc(ll rem) {
    ll ans = 0;
    while (true) {
        ll x =  __builtin_popcountl(rem);
        if (!x) break;
        rem %= x;
        ans++;
    }
    return ans;
}

int main()
{

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    fast;
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll c = 0, rem = 0;
    for (auto x : s) c += (x == '1');
    vector<vl> pre(2, vl(n + 1, 0)), suf(2, vl(n + 2, 0));
    for (int i = n - 1, p = 0; ~i; i--, p++) {
        if (s[i] == '0') continue;
        if (c > 1) {
            pre[0][i + 1] = modpow(2, p, c - 1);
            suf[0][i + 1] = pre[0][i + 1];
        }
        pre[1][i + 1] = modpow(2, p, c + 1);
        suf[1][i + 1] = pre[1][i + 1];
        debug(i, p, pre[1][i + 1], pre[0][i + 1]);
    }
    debug(pre);
    for (int i = 1; i <= n; i++) {
        if (c > 1) (pre[0][i] += pre[0][i - 1]) %= c - 1;
        (pre[1][i] += pre[1][i - 1]) %= c + 1;
    }
    for (int i = n - 1; i; i--) {
        if (c > 1) {
            (suf[0][i] += suf[0][i + 1]) %= c - 1;
        }
        (suf[1][i] += suf[1][i + 1]) %= c + 1;
    }
    debug(pre);
    debug(suf);
    for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
            ll rem = (modpow(2, n - i - 1, c + 1) + pre[1][i] + suf[1][i + 2]) % (c + 1);
            cout << 1 + calc(rem) << endl;
        }
        else {
            if (c == 1) {
                cout << 0 << endl;
                continue;
            }
            ll rem = (pre[0][i] + suf[0][i + 2]) % (c - 1);
            cout << 1 + calc(rem) << endl;
        }
    }

#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s";
#endif

    return 0;
}

Measured memory_bytes: 11296