#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

vll popcounts;

int getcount(int x)
{
    if (popcounts[x] != -1) return popcounts[x];

    int y = x;
    int count = 0;
    while (y > 0)
    {
        if (y % 2 == 1) count++;

        y /= 2;
    }

    int res = getcount(x % count) + 1;
    popcounts[x] = res;
    return res;
}

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

    int N;
    cin >> N;

    string X;
    cin >> X;

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

    //2のべき乗のその合計を先に計算
    map<int, vll> exps;
    map<int, ll> m;
    for (int j = -1; j <= 1; j++)
    {
        ll tmp = 0;
        int mod = count + j;
        exps[mod] = vll(N);

        if (mod > 0)
        {
            int exp = 1;

            rep(i, N)
            {
                int pos = N - 1 - i;
                exps[mod][pos] = exp;
                
                if (X[pos] == '1')
                {
                    tmp += exp;
                    tmp %= mod;
                }

                exp *= 2;
                exp %= mod;
                
            }
        }

        m[mod] = tmp;
    }

    popcounts.resize(N, -1);
    popcounts[0] = 0;
    popcounts[1] = 1;

    rep(i, N)
    {
        int count2 = count;

        //bit反転
        int x = 0;
        if (X[i] == '1')
        {
            count2--;
            x = m[count2];
            x -= exps[count2][i];
        }
        else
        {
            count2++;
            x = m[count2];
            x += exps[count2][i];
        }

        if (count2 == 0)
        {
            cout << 0<< endl;
            continue;
        }
        
        x += count2;
        x %= count2;
        cout << getcount(x) + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 9656