using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        string s = sc.Next();
        int count = s.Where(c => c == '1').Count();

        if (count == 0)
        {
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(1);
            }
            return;
        }

        int[] answers = new int[count + 10];
        for (int i = 1; i < count + 10; i++)
        {
            int num = i;
            int answer = 0;
            while (num != 0)
            {
                string str = Convert.ToString(num, 2);
                num = num % str.Where(c => c == '1').Count();
                answer++;
            }

            answers[i] = answer;
        }

        long totalA = 0;
        long totalB = 0;
        int currentA = 1;
        int currentB = 1;
        for (int i = 0; i < n; i++)
        {
            string c = s.Substring(n - i - 1, 1);
            if (c == "1")
            {
                if (count != 1)
                {
                    totalA += currentA % (count - 1);
                    totalA = totalA % (count - 1);
                }
                totalB += currentB % (count + 1);
                totalB = totalB % (count + 1);
            }
            if (count != 1)
            {
                currentA *= 2;
                currentA = currentA % (count - 1);
            }
            currentB *= 2;
            currentB = currentB % (count + 1);
        }

        currentA = 1;
        currentB = 1;
        List<int> numbers = new List<int>();
        for (int i = 0; i < n; i++)
        {
            string c = s.Substring(n - i - 1, 1);
            if (c == "1")
            {
                if (count == 1)
                {
                    numbers.Add(0);
                }
                else
                {
                    long tmp = totalA - currentA % (count - 1);
                    tmp = tmp % (count - 1);
                    if (tmp < 0)
                    {
                        tmp += (count - 1);
                    }
                    numbers.Add(answers[tmp] + 1);
                }
            }
            else
            {
                long tmp = totalB + currentB % (count + 1);
                tmp = tmp % (count + 1);
                numbers.Add(answers[tmp] + 1);
            }
            if (count != 1)
            {
                currentA *= 2;
                currentA = currentA % (count - 1);
            }
            currentB *= 2;
            currentB = currentB % (count + 1);
        }

        numbers.Reverse();
        foreach (var ans in numbers)
        {
            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 43580