#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll p[N];
int pre[N],bk[N],ans[N];
int n;
char s[N];
int get(int x)
{
    int ans=0;
    while(x)
        x=x%__builtin_popcount(x),ans++;
    return ans;
}
void solve(int x,int sum)
{
    if(sum<=0) return;
    p[0]=1;for(int i=1;i<N;i++) p[i]=p[i-1]*2%sum;
    for(int i=1;i<=n;i++)
        pre[i]=(pre[i-1]+(s[i]=='1')*p[i-1])%sum;
    for(int i=n;i>=1;i--)
        bk[i]=(bk[i+1]+(s[i]=='1')*p[i-1])%sum;
    for(int i=1;i<=n;i++)
        if(x==1&&s[i]=='1')
    {
        int res=(pre[i-1]+bk[i+1])%sum;
        ans[i]=1+get(res);
    }
    else if(x==0&&s[i]=='0')
    {
        int res=(pre[i-1]+bk[i+1]+p[i-1])%sum;
        ans[i]=1+get(res);
    }
}
int main()
{
    scanf("%d%s",&n,s+1);
    reverse(s+1,s+1+n);
    int sum=0;
    for(int i=1;i<=n;i++) sum+=s[i]=='1';
    solve(1,sum-1);
    solve(0,sum+1);
    reverse(ans+1,ans+1+n);
    for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
}
