/* Priyansh Agarwal*/
#include<bits/stdc++.h>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define nline "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define debug(x) cout << #x << " " << x <<endl;
#define set_bits __builtin_popcount
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
/*---------------------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod)
{ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
bool revsort(ll a, ll b) {return a > b;}
void swap(int &x, int &y) {int temp = x; x = y; y = temp;}
ll combination(ll n, ll r, ll m, ll* fact) {ll val1 = fact[n]; ll val2 = mminvprime(fact[r], m); ll val3 = mminvprime(fact[n - r], m); return ((val1 * val2) % m * val3) % m;}
/*--------------------------------------------------------------------------------------------------------------------------*/
ll helper(ll value)
{
	ll count = 0;
	while (value > 0)
	{
		value = value % (set_bits(value));
		count++;
	}
	return count;
}
int main()
{
	fastio();
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
	freopen("Error.txt", "w", stderr);
#endif
	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll total = 0;
	for (ll i = 0; i < n; i++)
		total += s[i] == '1';
	ll ans1 = 0;
	ll ans2 = 0;
	ll count = 0;
	for (ll i = n - 1; i >= 0; i--)
	{
		if (total - 1 > 0)
		{
			ll x = s[i] - 48;
			ans1 = (ans1 + x * expo(2, count, total - 1)) % (total - 1);
		}
		if (total + 1 > 0)
		{
			ll x = s[i] - 48;
			ans2 = (ans2 + x * expo(2, count, total + 1)) % (total + 1);
		}
		count++;
	}
	ll *ans_arr = new ll[n]();
	count = 0;
	for (ll i = n - 1; i >= 0; i--)
	{
		if (s[i] == '1' && (total - 1) > 0)
		{
			ll value1 = expo(2, count, total - 1);
			ll value2 = (ans1 - value1 + (total - 1)) % (total - 1);
			ans_arr[i] = 1;
			ans_arr[i] += helper(value2);
		}
		if (s[i] == '0')
		{
			ll value1 = expo(2, count, total + 1);
			ll value2 = (ans2 + value1) % (total + 1);
			ans_arr[i] = 1;
			ans_arr[i] += helper(value2);
		}
		count++;
	}
	for (int i = 0; i < n; i++)
		cout << ans_arr[i] << endl;
	return 0;
}


Measured memory_bytes: 5312