#include <bits/stdc++.h>
#define len(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define chmax(x, v) x = max((x), (v))
#define chmin(x, v) x = min((x), (v))
using namespace std;
using ll = long long;

const int upTo = 2e5 + 5;
int f[upTo];
int p2[2][upTo];
int md[2];
int tot[2];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	for (char c : s) md[0] += (c == '1');
	--md[0]; md[1] = md[0]+2;

	if (md[0] == 0) ++md[0];
	p2[0][0] = 1 % md[0];
	p2[1][0] = 1 % md[1];
	for (int x = 1; x < upTo; ++x) {
		f[x] = 1 + f[x % __builtin_popcount(x)];
		p2[0][x] = (2*p2[0][x-1])%md[0];
		p2[1][x] = (2*p2[1][x-1])%md[1];
	}
	for (int i = 0; i < n; ++i) {
		if (s[i] == '1') {
			tot[0] = (tot[0]+p2[0][n-1-i])%md[0];
			tot[1] = (tot[1]+p2[1][n-1-i])%md[1];
		}
	}
	for (int i = 0; i < n; ++i) {
		if (s[i] == '0') {
			int x = (tot[1]+p2[1][n-1-i])%md[1];
			cout << 1+f[x] << "\n";
		} else {
			if (md[1] == 2) { cout << "0\n"; continue; }
			int x = (tot[0]-p2[0][n-1-i]+md[0])%md[0];
			cout << 1+f[x] << "\n";
		}
	}
}
