#include <bits/stdc++.h>
#define pb push_back
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define INF 300000000000001
#define ll_max 9000000000000000000
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long int ll;
typedef long double ld;
typedef vector<pair<ll,ll> > vll;
typedef vector<int> vi;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll N = 200001;
const ll M = log2(N);

struct point {
    ll x, y, i;
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cerr << word << " = " << a << endl;
    debug(s, args...);
}

ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    if(n & 1) return fast_exp(x, n - 1) * x % mod;
    else
    {
        ll ans = fast_exp(x, n / 2);
        return ans * ans % mod;
    }
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n, m, x, y, ans = 0;
        cin >> n;
        ll a[n + 1];
        a[0] = 0;
        for(int i = 1; i <= n; i++)
        {
            x = i;
            y = 0;
            while(x > 0)
            {
                m = __builtin_popcount(x);
                x = x % m;
                y++;
            }
            a[i] = y;
        }
        string s;
        cin >> s;
        x = 1;
        y = 1;
        ll b[2] = {};
        m = 0;
        for(int i = n - 1; i > -1; i--) if(s[i] == '1') m++;
        if(m <= 1)
        {
            if(m == 0)
            {
                for(int i = 0; i < n; i++) cout << 1 << "\n";
            }
            else
            {
                for(int i = n - 1; i > -1; i--)
                {
                    if(s[i] == '1')
                    {
                        b[1] = (b[1] + y) % (m + 1);
                    }
                    y = y * 2 % (m + 1);
                }
                vector<pair<int,int>> v;
                y = 1;
                for(int i = n - 1; i > -1; i--)
                {
                    if(s[i] == '1')
                    {
                        v.pb({0, 0});
                    }
                    else
                    {
                        v.pb({(b[1] + y) % (m + 1), 1});
                    }
                    y = y * 2 % (m + 1);
                }
                for(int i = n - 1; i > -1; i--) cout << a[v[i].ff] + v[i].ss << "\n";
            }
        }
        else
        {
            for(int i = n - 1; i > -1; i--)
            {
                if(s[i] == '1')
                {
                    b[0] = (b[0] + x) % (m - 1);
                    b[1] = (b[1] + y) % (m + 1);
                }
                x = x * 2 % (m - 1);
                y = y * 2 % (m + 1);
            }
            vector<int> v;
            x = 1;
            y = 1;
            for(int i = n - 1; i > -1; i--)
            {
                if(s[i] == '1')
                {
                    v.pb((b[0] - x + m - 1) % (m - 1));
                }
                else
                {
                    v.pb((b[1] + y) % (m + 1));
                }
                x = x * 2 % (m - 1);
                y = y * 2 % (m + 1);
            }
            for(int i = n - 1; i > -1; i--) cout << a[v[i]] + 1 << "\n";
        }
        //cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 7128