#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int v[2][200010], res[200010];

int f(int n)
{
    int res=0;
    while (n>0) {
        n%=__builtin_popcount(n);
        ++res;
    }
    return res;
}

int main()
{
    int n; cin>>n;
    string x; cin>>x;
    int d=count(begin(x), end(x), '1');

    for(int i=0; i<1+(d>1); ++i) {
        v[i][0]=1;
        for(int j=0; j<n; ++j)
            v[i][j+1]=v[i][j]*2%(i ? d-1 : d+1);
    }

    int r0=0,r1=0;
    for(auto& c: x) r0=(r0*2+(c-'0'))%(d+1);
    if (d>1) for(auto& c: x) r1=(r1*2+(c-'0'))%(d-1);
    reverse(begin(x), end(x));
    for(int i=0; i<n; ++i) {
        char& c=x[i];
        if (c=='0') {
            int t=(r0+v[0][i])%(d+1);
            res[i]=f(t)+1;
        }
        else {
            if (d>1) {
                int t=(r1-v[1][i]+d-1)%(d-1);
                res[i]=f(t)+1;
            }
        }
    }
    reverse(res, res+n);
    for(int i=0; i<n; ++i) cout<<res[i]<<'\n';
}
