#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long c = 0;
long long p[200020], m[200020];
long long s = 0, t = 0;
int main() {
    long long n;
    string x;
    cin >> n >> x;
    for (int i = 0; i < n; i++) {
        if (x[i] == '1') {
            c++;
        }
    }
    long long o = 1;
    for (int i = n - 1; i >= 0; i--) {
        p[i] = o % (c + 1);
        o = o * 2 % (c + 1);
    }
    o = 1;
    if (c > 1) {
        for (int i = n - 1; i >= 0; i--) {
            m[i] = o % (c - 1);
            o = o * 2 % (c - 1);
        }
    }
    else {
        if (c == 1) {
            for (int i = n - 1; i >= 0; i--) {
                if (x[i] == '1') {
                    if (i == n - 1) {
                        for (int j = 0; j < n - 1; j++) {
                            cout << "1" << endl;
                        }
                        cout << "0" << endl;
                        return 0;
                    }
                    else {
                        for (int j = 0; j < n - 1; j++) {
                            if (i == j) {
                                cout << "0" << endl;
                            }
                            else {
                                cout << "1" << endl;
                            }
                        }
                        cout << "2" << endl;
                        return 0;
                    }
                }
            }
        }
        else {
            for (int j = 0; j < n; j++) {
                cout << "1" << endl;
            }
            return 0;
        }
    }
    o = 1;
    for (int i = n - 1; i >= 0; i--) {
        if (x[i] == '1') {
            s += o;
            s %= (c + 1);
        }
        o = o * 2 % (c + 1);
    }
    o = 1;
    for (int i = n - 1; i >= 0; i--) {
        if (x[i] == '1') {
            t += o;
            t %= (c - 1);
        }
        o = o * 2 % (c - 1);
    }
    long long am;
    for (int i = 0; i < n; i++) {
        if (x[i] == '0') {
            am = (s + p[i]) % (c + 1);
        }
        else {
            long long it = (t - m[i]) % (c - 1);
            while (it < 0) {
                it += (c - 1);
            }
            am = it % (c - 1);
        }
        bitset<18> bit;
        bit = am;
        long long po = 0;
        for (int i = 0; i < 18; i++) {
            if (bit[i] == 1) {
                po++;
            }
        }
        long long ans = 1;
        if (po != 0) {
            for(;;){
                if (am == 0) {
                    break;
                }
                am %= po;
                ans++;
                po = 0;
                bit = am;
                for (int i = 0; i < 18; i++) {
                    if (bit[i] == 1) {
                        po++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 6856