#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


///////////////////////////////////////////////////
#include <map>


int prepare(vi &shita, vi &ue, const string &s, int N)
{
    int pop = 0;
    for (size_t i = 0; i < s.size(); i++)
        pop += (s[i] - '0');

    int k_ue = 1, k_shita = 1;
    int m_ue = 0, m_shita = 0;

    if (pop == 1)
        for (int i = 0; i <= N; i++)
            shita[i] = 0;

    size_t i = N;
    while (i-- > 0)
    {
        if (pop > 1)
        {
            shita[i] = k_shita;
            k_shita = (k_shita * 2) % (pop - 1);
            m_shita = (m_shita + (s[i] - '0') * shita[i]) % (pop - 1);
        }
        
        ue[i] = k_ue;
        k_ue = (k_ue * 2) % (pop + 1);
        m_ue = (m_ue + (s[i] - '0') * ue[i]) % (pop + 1);
    }
    shita[N] = m_shita;
    ue[N] = m_ue;
    return pop;
}

int main()
{
    int N;
    string X;
    io >> N >> X;

//    N = 200000;
//    for (int i = 0; i < N; i++)
//    {
//        X.push_back('0');
//    }

    vi s(N+1), u(N+1);
    int pop = prepare(s, u, X, N);

    vi aans(N);

    for (int i = 0; i < N; i++)
    {
        int ans, mm;
        if (X[i] == '0')
        {
            int mod = pop + 1;
            ans = 1;
            mm = (u[N] + u[i]) % mod;
        }
        else if (pop == 1)
        {
            ans = 0;
            mm = 0;
        }
        else
        {
            int mod = pop - 1;
            ans = 1;
            mm = ((s[N] - s[i]) % mod + mod) % mod;
        }

        if (mm < 0) return 3;

        //if (i == 21)
        //{
        //    printf("ans=%d, mm=%d, pop=%d\n", ans, mm, pop);
        //    printf("s[N]=%d, s[i]=%d\n", s[N], s[i]);
        //}

        while (mm > 0)
        {
            mm = mm % __builtin_popcount(mm);
            ++ans;
        }
        aans[i] = ans;
    }
    
    for (int i = 0; i < N; i++)
        io << aans[i] << BR;
    
}


Measured memory_bytes: 6048