#include <bits/stdc++.h>
using namespace std;

int a[2][222222], s[2];
int f(int i) {
    int j = 0;
    for(; i; j++)
        i %= __builtin_popcount(i);
    return j;
}
int main() {
    int n;
    string x;
    cin >> n >> x;
    int c = count(x.begin(), x.end(), '1');
    for(int i = 0; i < 2; i++) {
        int d = i ? c + 1 : c - 1;
        if(d <= 0)
            continue;
        a[i][n - 1] = 1 % d;
        if(x[n - 1] & 1)
            s[i] = a[i][n - 1];
        for(int j = n - 1; j--;) {
            a[i][j] = a[i][j + 1] * 2 % d;
            if(x[j] & 1)
                (s[i] += a[i][j]) %= d;
        }
    }
    for(int i = 0; i < n; i++) {
        int d = x[i] & 1 ? c - 1 : c + 1;
        if(!d) {
            cout << "0\n";
            continue;
        }
        if(x[i] & 1)
            cout << f((s[0] - a[0][i] + d) % d) + 1 << '\n';
        else
            cout << f((s[1] + a[1][i]) % d) + 1 << '\n';
    }
    return 0;
}
