#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

uint mod = 1;
struct Modint{
    uint num = 0;
    Modint() noexcept {}
    Modint(const Modint &x) noexcept : num(x.num){}
    inline operator ll() const noexcept { return num; }
    inline Modint& operator+=(Modint x) noexcept { num += x.num; if(num >= mod) num -= mod; return *this; }
    inline Modint& operator++() noexcept { if(num == mod - 1) num = 0; else num++; return *this; }
    inline Modint operator++(int) noexcept { Modint ans(*this); operator++(); return ans; }
    inline Modint operator-() const noexcept { return Modint(0) -= *this; }
    inline Modint operator-(Modint x) const noexcept { return Modint(*this) -= x; }
    inline Modint& operator-=(Modint x) noexcept { if(num < x.num) num += mod; num -= x.num; return *this; }
    inline Modint& operator--() noexcept { if(num == 0) num = mod - 1; else num--; return *this; }
    inline Modint operator--(int) noexcept { Modint ans(*this); operator--(); return ans; }
    inline Modint& operator*=(Modint x) noexcept { num = ull(num) * x.num % mod; return *this; }
    inline Modint& operator/=(Modint x) noexcept { return operator*=(x.inv()); }
    template<class T> Modint(T x) noexcept {
        using U = typename conditional<sizeof(T) >= 4, T, int>::type;
        U y = x; y %= U(mod); if(y < 0) y += mod; num = uint(y);
    }
    template<class T> inline Modint operator+(T x) const noexcept { return Modint(*this) += x; }
    template<class T> inline Modint& operator+=(T x) noexcept { return operator+=(Modint(x)); }
    template<class T> inline Modint operator-(T x) const noexcept { return Modint(*this) -= x; }
    template<class T> inline Modint& operator-=(T x) noexcept { return operator-=(Modint(x)); }
    template<class T> inline Modint operator*(T x) const noexcept { return Modint(*this) *= x; }
    template<class T> inline Modint& operator*=(T x) noexcept { return operator*=(Modint(x)); }
    template<class T> inline Modint operator/(T x) const noexcept { return Modint(*this) /= x; }
    template<class T> inline Modint& operator/=(T x) noexcept { return operator/=(Modint(x)); }
    inline Modint inv() const noexcept { ll x = 0, y = 0; extgcd(num, mod, x, y); return x; }
    static inline ll extgcd(ll a, ll b, ll &x, ll &y) noexcept { ll g = a; x = 1; y = 0; if(b){ g = extgcd(b, a % b, y, x); y -= a / b * x; } return g; }
    inline Modint pow(ull x) const noexcept { Modint ans = 1, cnt = *this; while(x){ if(x & 1) ans *= cnt; cnt *= cnt; x /= 2; } return ans; }
};
inline Modint operator""_M(ull x) noexcept { return Modint(x); }



signed main(){
    ll n;
    string s;
    cin >> n >> s;
    for(auto& i : s) i -= '0';
    ll k = reduce(s.begin(), s.end(), 0);
    reverse(s.begin(), s.end());
    Modint low = 0, high = 0;
    if(k > 1){
        mod = k - 1;
        for(ll i = 0; i < s.size(); i++) if(s[i]){
            low += 2_M .pow(i);
        }
    }
    {
        mod = k + 1;
        for(ll i = 0; i < s.size(); i++) if(s[i]){
            high += 2_M .pow(i);
        }
    }
    for(ll i = s.size(); i-- ; ){
        ll x, ans = 1;
        if(s[i]){
            if(k == 1){
                cout << 0 << endl;
                continue;
            }
            mod = k - 1;
            x = low - 2_M .pow(i);
        }
        else{
            mod = k + 1;
            x = high + 2_M .pow(i);
        }
        while(x){
            x %= __builtin_popcountll(x);
            ans++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3700