import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
		int bits = 0;
		String x = I.next();
		for (int i = 0; i < N; i++) {
			 if (x.charAt(i)=='1') bits++;
		}
		long cur = 1;
		int lo = bits-1;
		int hi = bits+1;
		long[] dpMore = new long[N]; //2^i mod(number of bits +- 1)  
		long[] dpLess = new long[N];
		
		for (int i = 0; i < N; i++) { //i denotes the current power of 2 and dp[i] holds 
			//the remainder when 2^i is divided by hi
			dpMore[i]=cur;
			cur*=2;
			cur%=hi;
		}
		
		cur=1; //Reset silly
		if (lo>0) {
			for (int i = 0; i < N; i++) {
				dpLess[i]=cur;
				//O.pln(dpLess[i]);
				cur*=2;
				cur%=lo;
			}
		}
		long totBig = 0;
		long totLess = 0;
		for (int i = 0; i < N; i++) {
			if (x.charAt(i)=='1')totBig+=dpMore[N-i-1];
		}
		for (int i = 0; i < N; i++) {
			if (x.charAt(i)=='1')totLess+=dpLess[N-i-1];
		}
		totBig%=hi;
		if (lo>0) totLess%=lo;
		
		for (int i = 0; i < N; i++) {
			int ans = 0;
			if (x.charAt(i)=='0') {
				ans++;
				long curnum = totBig+dpMore[N-i-1]; //Adjusting for right to left binary traversal
				curnum%=hi;
				while (curnum>0) {
					curnum%=pop(curnum);
					ans++;
				}
			}else {
				if (bits-1==0) ans=0;
				else {
					long curnum = totLess-dpLess[N-i-1];
					curnum%=lo;
					if (curnum<0) curnum+=lo;
					ans++;
					while (curnum>0) {
						curnum%=pop(curnum);
						ans++;
					}
				}
			} 
			O.pln(ans);
		}
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
	}
}

Measured memory_bytes: 62012