function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
    var N = parseInt(input[0][0], 10);
    var X = input[1][0];
    var vec_fn = [];
    var tmp;
    for (var i = 0; i < 200000; i++){
        tmp = (i + 1) % popcount(i + 1);
        if (tmp === 0) vec_fn.push(1);
        else vec_fn.push(vec_fn[tmp - 1] + 1);
    }
    var howMany1 = 0;
    for (var i = 0; i < N; i++){
        if (X.substr(i, 1) === '1') howMany1 ++;
    }

    // 1が増えたとき
    var tmpRemain1 = 1;
    var default_remain1 = 0;
    // 0が増えたとき
    var tmpRemain2 = 1;
    var default_remain2 = 0;

    v_remain1 = [];
    v_remain2 = [];

    for (var i = N - 1; i >= 0; i--){
        v_remain1.push(tmpRemain1);
        v_remain2.push(tmpRemain2);
        if (X.substr(i, 1) === '1'){
            default_remain1 += tmpRemain1;
            default_remain1 %= (howMany1 + 1);
            default_remain2 += tmpRemain2;
            default_remain2 %= (howMany1 - 1);
        }
        tmpRemain1 *= 2;
        tmpRemain1 %= (howMany1 + 1);
        tmpRemain2 *= 2;
        tmpRemain2 %= (howMany1 - 1);
    }
    var v_ans = [];
    for (var i = 0; i < N; i++){
        if (X.substr(i, 1) === '1'){
            if ((howMany1 - 1) === 0) v_ans.push(-1);
            else v_ans.push(mod(default_remain2 - v_remain2[N - i - 1], howMany1 - 1));

        } else {
            v_ans.push(mod(default_remain1 + v_remain1[N - i - 1], howMany1 + 1));
        }
    }
    for (var i = 0; i < v_ans.length; i++){
        if (v_ans[i] === -1) v_ans[i] = 0;
        else if (v_ans[i] === 0) v_ans[i] = 1;
        else v_ans[i] = vec_fn[v_ans[i] - 1] + 1;
    }
    console.log(v_ans.join("\n"));
}

function mod(i, j) {
    return (i % j) < 0 ? (i % j) + 0 + (j < 0 ? -j : j) : (i % j + 0);
}

function popcount(n) {
    var digit = n.toString(2).split("").map(e => parseInt(e, 10));
    return sum(digit);
}

sum  = function(arr) {
    var sum = 0;
    arr.forEach(function(elm) {
        sum += elm;
    });
    return sum;
};

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 