#include <bits/stdc++.h>

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

ll M;

class modulo {
public:
    ll data;

    modulo(ll data = 0) : data(data % M) {
    }

    modulo operator+(const modulo &x) const {
        return modulo(data + x.data);
    }

    modulo operator-(const modulo &x) const {
        return modulo(data + (M - x.data));
    }

    modulo operator*(const modulo &x) const {
        return modulo(data * x.data);
    }

    modulo operator/(const modulo &x) const {
        return modulo(data * x.inv().data);
    }

    modulo operator+=(const modulo &x) {
        return data = (data + x.data) % M;
    }

    modulo operator-=(const modulo &x) {
        return data = (data + (M - x.data)) % M;
    }

    modulo operator*=(const modulo &x) {
        return data = (data * x.data) % M;
    }

    modulo operator/=(const modulo &x) {
        return data = (data * x.inv().data) % M;
    }

    modulo inv() const {
        return _pow(M - 2);
    }

    template <class Integer>
    modulo operator^(Integer n) const {
        if (n >= 0) {
            return _pow(n);
        } else {
            return _pow(M - 1 - (-n) % (M - 1));
        }
    }

    friend std::ostream& operator<<(std::ostream &os, const modulo &x) {
        os << x.data;
        return os;
    }

private:
    template <class NonNegativeInteger>
    modulo _pow(NonNegativeInteger n) const {
        modulo result(1);
        modulo x(*this);
        while (n) {
            if (n & 1) {
                result *= x;
            }
            x *= x;
            n >>= 1;
        }
        return result;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    string X;
    cin >> N >> X;

    int s = 0;
    REP(i, N) {
        if (X[i] == '1') {
            s += 1;
        }
    }

    vector<int> a(N + 1);
    FOR(i, 1, N) {
        a[i] = 1 + a[i % __builtin_popcount(i)];
    }

    PRINT(s);
    if (s == 1) {
        M = s + 1;
        modulo z1 = 0;
        REP(i, N) {
            if (X[N - 1 - i] == '1') {
                z1 += (modulo(2) ^ i);
            }
        }

        RREP(i, N) {
            int ans;
            if (X[N - 1 - i] == '0') {
                M = s + 1;
                modulo w = z1 + (modulo(2) ^ i);
                ans = a[w.data] + 1;
            } else {
                ans = 0;
            }
            cout << ans << '\n';
        }
        cout << flush;

        return 0;
    }

    M = s + 1;
    modulo z1 = 0;
    REP(i, N) {
        if (X[N - 1 - i] == '1') {
            z1 += (modulo(2) ^ i);
        }
    }

    M = s - 1;
    modulo z2 = 0;
    REP(i, N) {
        if (X[N - 1 - i] == '1') {
            z2 += (modulo(2) ^ i);
        }
    }

    PRINT(z1);
    PRINT(z2);

    RREP(i, N) {
        int ans;
        if (X[N - 1 - i] == '0') {
            M = s + 1;
            modulo w = z1 + (modulo(2) ^ i);
            ans = a[w.data];
        } else {
            M = s - 1;
            modulo w = z2 - (modulo(2) ^ i);
            ans = a[w.data];
        }
        ans += 1;
        cout << ans << '\n';
    }
    cout << flush;

    return 0;
}


Measured memory_bytes: 4372