#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;

int ctoi(char c) {
	return c - '0';
}

ll two_pow(ll b, ll base) {
	ll ans = 1;
	rep(i, b) {
		ans *= 2;
		ans %= base;
	}

	return  ans;
}

const int M = 200005;
int N;
class Pop {
private:
	vector<int> SmallerMaxN;
	bitset<20> bs;
	vector<ll> smallerbox;
	vector<ll> powmin;
	vector<ll> powmax;
public:
	Pop() {
		SmallerMaxN.resize(M);
		SmallerMaxN[1] = 1;
		smallerbox.resize(N);
		for (int i = 1; i < M; i++) {
			SmallerMaxN[i] = calc(i);
		}
	}

	int calc(int x) {
		if (x == 0) return 1;
		if (SmallerMaxN[x] != 0) {
			return SmallerMaxN[x];
		}
		else {
			bs = x;
			int y = x % bs.count();

			if (SmallerMaxN[y] != 0) {
				SmallerMaxN[x] = SmallerMaxN[y] + 1;
				return SmallerMaxN[x];
			}
			else if (y == 0) {
				return 1;
			}
			else {
				SmallerMaxN[y] = calc(y) + 1;
				return -1;
			}
		}

	}

	void solve(string s) {
		ll basemin, basemax;
		ll N_bmin=0, N_bmax=0;
		ll base = 0;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == '1') base++;
		}
		basemin = base - 1;
		basemax = base + 1;

		powmin.resize(N), powmax.resize(N);

		powmin[0] = 1, powmax[0] = 1;
		for (int i = 1;basemin != 0 && i < s.size(); i++) {
			powmin[i] = powmin[i - 1] * 2;
			powmin[i] %= basemin;

			powmax[i] = powmax[i - 1] * 2;
			powmax[i] %= basemax;
		}

		for (int i = 0; i < s.size(); i++) {
			N_bmin += ctoi(s[i]) * powmin[s.size() - 1 - i];
			N_bmax += ctoi(s[i]) * powmax[s.size() -1-i];
		}
		N_bmax %= basemax;
		if (basemin != 0) {
			N_bmin %= basemin;
		}
		

		ll temp;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == '0') {
				temp = N_bmax;
				temp += powmax[s.size() - i-1];
				temp %= basemax;
				smallerbox[i] = temp;
			}
			else {
				temp = N_bmin;
				temp -= powmin[s.size() - 1 - i];
				if (temp < 0) temp += basemin;
				if (basemin == 0) {
					smallerbox[i] = -1;
				}
				else {
					smallerbox[i] = temp;
				}
			}
		}

		for (int i = 0; i < s.size(); i++) {
			if (smallerbox[i] != -1) {
				cout << SmallerMaxN[smallerbox[i]] + 1 << endl;
			}
			else {
				cout << 0 << endl;
			}
			
		}

	}
};

signed main() {
	cin >> N;
	string s; cin >> s;

	Pop pp;
	pp.solve(s);

}

Measured memory_bytes: 9128