#include <iostream>
#include <string>
using namespace std;

int main()
{
    int n;
    cin >> n;
    string x;
    cin >> x;
    int k = 0;
    for(int i = 0; i < n; i++) k += x[i] - '0';
    int l = max(k - 1, 1), r = k + 1;
    int s = 0, t = 0;
    int d = 1, e = 1;
    for(int i = n - 1; i >= 0; i--){
        s = (s + d * (x[i] - '0')) % l;
        t = (t + e * (x[i] - '0')) % r;
        d = d * 2 % l;
        e = e * 2 % r;
    }
    int p[200005];
    d = 1;
    e = 1;
    for(int i = n - 1; i >= 0; i--){
        if(x[i] == '0'){
            p[i] = (t + e) % r;
        }
        else{
            p[i] = (s + l - d) % l;
        }
        d = d * 2 % l;
        e = e * 2 % r;
    }
    for(int i = 0; i < n; i++){
        int ans = 1;
        if(x[i] == '1' && r == 2){
            cout << 0 << endl;
            continue;
        }
        while(p[i]){
            int c = 0;
            for(int j = 0; j <= 20; j++){
                if((p[i] >> j) & 1) c++;
            }
            p[i] %= c;
            ans++;
        }
        cout << ans << endl;
    }
}
