// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long N = lread();
    string X = sread();
    auto pcnt = X.map!"a == '1'"().sum();
    long bit(long i, long m)
    {
        return memoize!(powmod!long)(2L, N - i - 1, m);
    }

    long Xm;
    long Xdec;
    long Xinc;
    foreach (i; 0 .. N)
        if (X[i] == '1')
        {
            Xinc += bit(i, pcnt + 1);
            Xinc %= pcnt + 1;
            if (1 < pcnt)
            {
                Xdec += bit(i, pcnt - 1);
                Xdec %= pcnt - 1;
            }
            Xm += bit(i, pcnt);
            Xm %= pcnt;
        }

    long eval(long x)
    {
        if (x == 0)
            return 0;
        return eval(x % popcnt(x)) + 1;
    }

    foreach (i; 0 .. N)
    {
        if (X[i] == '0')
        {
            long x = (Xinc + bit(i, pcnt + 1)) % (pcnt + 1);
            writeln(eval(x) + (X != "0"));
        }
        else
        {
            if (pcnt == 1)
            {
                writeln(0);
                continue;
            }
            long x = (pcnt - 1 + Xdec - bit(i, pcnt - 1)) % (pcnt - 1);
            writeln(eval(x) + (X != "0"));
        }
    }
}

/// x^^n % m
T powmod(T = long)(T x, T n, T m = 10 ^^ 9 + 7)
{
    if (n < 1)
        return 1;
    if (n & 1)
    {
        return x * powmod(x, n - 1, m) % m;
    }
    T tmp = powmod(x, n / 2, m);
    return tmp * tmp % m;
}
