using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace D_AISING2020
{
    class MainClass
    {

        static int[] s, f;


        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            int n = s[0];
            string x = ReadLine();

            f = new int[n + 1];

            var popcnt = 0;
            var xc = x.ToCharArray();
            popcnt = xc.Count(x => x == '1');

            var modplus = popcnt + 1;
            var modminus = popcnt - 1;

            // WriteLine("modplus : {0}  modminus : {1}",modplus,modminus);

            var allmodplus = 0;
            var allmodminus = 0;

            var binmodplus = new int[n];
            var binmodminus = new int[n];



            for (int i = 0; i < s[0]; i++)
            {
                var d = n - i - 1;
                if (i == 0)
                {
                    binmodplus[0] = 1 % modplus;
                    binmodminus[0] = modminus > 0 ? 1 % modminus : 0;


                }
                else
                {
                    binmodplus[i] = binmodplus[i - 1] * 2 % modplus;
                    binmodminus[i] = modminus > 0 ? binmodminus[i - 1] * 2 % modminus : 0;
                }
            }

            var prebinplus = 1;
            var prebinminus = 1;

            for (int i = n - 1; i >= 0; i--)
            {
                if (xc[i] == '1')
                {
                    allmodplus = (allmodplus + prebinplus) % modplus;
                    allmodminus = modminus > 0 ? (allmodminus + prebinminus) % modminus: allmodminus;
                }
                prebinplus = (prebinplus * 2) % modplus;
                prebinminus = modminus > 0 ? (prebinminus * 2) % modminus:prebinminus;
            }

            // WriteLine("allmodplus : {0} allmodminus : {1}", allmodplus, allmodminus);

            for (int i = 0; i < n; i++)
            {

                var ans = 0;
                var cnt = 0;
                if (xc[i] == '1')
                {
                    if(modminus>0){
                        cnt++;
                        ans = (allmodminus-binmodminus[n-i-1])%modminus;
                    ans = ans < 0 ? ans + modminus : ans;

                    }
                }
                else
                {
                    cnt ++;
                    ans = (allmodplus + binmodplus[n - i - 1]) % modplus;
                    // WriteLine("i : {0}  xc[i] : {1} allmodplus : {2} binmodplus : {3}", i, xc[i], allmodplus, binmodminus[n - i - 1]);
                }
                WriteLine(cnt + FuncCnt(ans));
            }
            return;

        }

        public static int FuncCnt(int x)
        {
            // WriteLine("FuncCnt : {0}", x);
            if (x == 0)
            {
                return 0;
            }
            if (f[x] != 0)
            {
                return f[x];
            }

            var popcnt = 0;

            var xstr = Convert.ToString(x, 2);
            var xstrc = xstr.ToCharArray();
            popcnt = xstrc.Count(x => x == '1');

            f[x] = FuncCnt(x % popcnt) + 1;
            return f[x];
        }





        public static int LowerBound<T>(T[] a, T v)
        {
            return LowerBound(a, v, Comparer<T>.Default);
        }

        public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res == -1) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
        public static int UpperBound<T>(T[] a, T v)
        {
            return UpperBound(a, v, Comparer<T>.Default);
        }

        public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res <= 0) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
    }
}


Measured memory_bytes: 34108