//2020年4月17日現在

#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }
template <class T, class... A>
void printd(const T &first, const A &... rest) { cout << fixed << setprecision(15) << first; prints_rest(rest...); }


namespace {
	// printElems(&a[0], &a[n]);　みたいな感じで使う。
	void printElems(const int* begin, const int* end)
	{
		for (const int* p = begin; p != end; ++p) {
			cout << *p << ' ';
		}
		cout << endl;
	}
}

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define FOR(i,j,n) for(int i=j; i < n; i++)
#define souatari(i,j,n) rep1(i,n-1)rep(j,i)
#define souatari1(i,j,n) for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef array<int,3> arr3;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const ll BIG = 1LL<<60;

//----------------------------------------------


ll ans[200005];
ll anstmp[200005];
ll onelist[200005];
ll zerolist[200005];

int popcount(int tmp){
	int cnt = 0;
	rep(i,31){
		if((tmp&1<<i))cnt++;
	}
	return cnt;
}


ll popdiv(ll tmp){
	int cnt = 0;
	while(tmp!=0){
		cnt++;
		int tmpcnt = popcount(tmp);
		tmp %= tmpcnt;
	}
	return cnt;
}





int main(){
	ll n;
	string x;
	cin >> n;
	cin >> x;
	ll popcnt = 0;
	rep(i,n)if(x[i] == '1')popcnt++;
	ll one = popcnt+1;
	onelist[0] = 1%one;
	rep1(i,n-1){
		onelist[i] = (onelist[i-1]*2)%one;
	}

	ll alltmp = 0;
	rep(i,n){
		if(x[n-1-i] == '1'){
			alltmp+=onelist[i];
			alltmp%=one;
		}
	}
	rep(i,n){
		if(x[n-1-i] == '0'){
			anstmp[i] = (alltmp+onelist[i])%one;
			ans[i] = 1;
		}
	}

	ll zero = popcnt-1;

if(zero!=0){

	zerolist[0] = 1%zero;
	rep1(i,n-1){
		zerolist[i] = (zerolist[i-1]*2)%zero;
	}
	ll alltmpz = 0;
	rep(i,n){
		if(x[n-1-i] == '1'){
			alltmpz+=zerolist[i];
			alltmpz%=zero;
		}
	}
	rep(i,n){
		if(x[n-1-i] == '1'){

			anstmp[i] = (alltmpz-zerolist[i]);
			if(anstmp[i]<0) anstmp[i]+=zero;
			anstmp[i]%=zero;
			ans[i] = 1;
		}
	}
}
/*
prints("onelist");
rep(i,n) cout << onelist[i] << ' ';
prints();

	rep(i,n)prints(anstmp[i]);
*/
	rep(i,n){
		ans[i]+=popdiv(anstmp[i]);
	}
	repr(i,n){
		prints(ans[i]);
	}




	return 0;
}




Measured memory_bytes: 10000