#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long int lli;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<pll> vop;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define REP(i,a,b) for( long long i=a;i<b;i++)
#define REPR(i,a,b) for(int i=a;i>=b;i--)
#define adb(a) for(auto ii:a) cout << ii << " "; cout << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define endl "\n"
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define PI 3.14159265358979323846
const ll MAXN = 100007;
const ll p = 1000000007;

struct LessSecond
{
    template<typename T, typename U>
    bool operator()(const std::pair<T, U> &x, const std::pair<T, U> &y) const
    {
        return x.second < y.second;
    }
};

ll power(ll a, ll b, ll m) { ll ans = 1; a = a % m; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; }

ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); }

ll modInverse(ll a, ll m) { ll g = __gcd(a, m); return power(a, m - 2, m); }


int main()
{

    fastIO;
    int test = 1;
    //cin >> test;
    while (test--)
    {
        int n;
        string s;
        cin >> n >> s;
        int c = 0;
        REP(i, 0, n) if (s[i] == '1') c++;
        int k1 = c - 1, k2 = c + 1;
        int pwrTwo1[n];
        if (k1 > 0) {
            pwrTwo1[0] = 1 % k1;
            //cout << pwrTwo1[0] << " ";
            for (int i = 1; i < n; i++)
            {
                pwrTwo1[i] = pwrTwo1[i - 1] * (2 % k1);
                pwrTwo1[i] %= k1;
                //cout << pwrTwo1[i] << " ";
            }
        }
        int pwrTwo2[n];
        pwrTwo2[0] = 1 % k2;
        //cout << pwrTwo2[0] << " ";
        for (int i = 1; i < n; i++)
        {
            pwrTwo2[i] = pwrTwo2[i - 1] * (2 % k2);
            pwrTwo2[i] %= k2;
            //cout << pwrTwo2[i] << " ";
        }
        int res1 = 0, res2 = 0;
        int i = 0, j = n - 1;
        if (k1 > 0) {
            while (i < n)
            {

                // If current bit is 1
                if (s[j] == '1')
                {

                    // Add the current power of 2
                    res1 += (pwrTwo1[i]);
                    res1 %= k1;
                }
                i++;
                j--;
            }
        }
        i = 0, j = n - 1;
        while (i < n)
        {

            // If current bit is 1
            if (s[j] == '1')
            {

                // Add the current power of 2
                res2 += (pwrTwo2[i]);
                res2 %= k2;
            }
            i++;
            j--;
        }
        vi ans;
        REPR(i, n - 1, 0)
        {
            if (s[i] == '1')
            {
                int y = 0;
                if (k1 > 0)
                {
                    int x = res1 - pwrTwo1[n - 1 - i];
                    x = ((x % k1) + k1) % k1;
                    y++;
                    while (x > 0)
                    {
                        x = x % (__builtin_popcount(x));
                        y++;
                    }
                }
                ans.PB(y);
            }
            else
            {
                int y = 0;
                int x = res2 + pwrTwo2[n - 1 - i];
                x = x % k2;
                //x = ((x % k1) + k1) % k1;
                y++;
                while (x > 0)
                {
                    x = x % (__builtin_popcount(x));
                    y++;
                }
                ans.PB(y);
            }
        }
        reverse(all(ans));
        REP(i, 0, n) cout << ans[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 5980