pub struct ModUtil {
    fact: Vec<usize>,
    inv_fact: Vec<usize>,
    module: usize,
}

#[allow(dead_code)]
impl ModUtil {
    pub fn new(size: usize, module: usize) -> ModUtil {
        let mut fact = vec![0; size + 1];
        let mut inv_fact = vec![0; size + 1];
        fact[0] = 1;
        for i in 1..size + 1 {
            fact[i] = i * fact[i - 1] % module;
        }
        inv_fact[0] = 1;
        for i in 1..size + 1 {
            inv_fact[i] = ModUtil::mod_pow(fact[i], module - 2, module);
        }
        ModUtil {
            fact: fact,
            inv_fact: inv_fact,
            module: module,
        }
    }

    pub fn permutation(&self, n: usize, k: usize) -> usize {
        assert!(n >= k);
        self.fact[n] % self.module * self.inv_fact(n - k) % self.module
    }
    pub fn combination(&self, n: usize, k: usize) -> usize {
        assert!(n >= k);
        self.fact[n] * self.inv_fact[k] % self.module * self.inv_fact[n - k] % self.module
    }

    pub fn fact(&self, x: usize) -> usize {
        self.fact[x]
    }
    pub fn inv(&self, x: usize) -> usize {
        ModUtil::mod_pow(x, self.module - 2, self.module)
    }
    pub fn inv_fact(&self, x: usize) -> usize {
        self.inv_fact[x]
    }

    pub fn mod_pow(x: usize, n: usize, module: usize) -> usize {
        if n == 0 {
            return 1;
        }
        let mut res: usize = ModUtil::mod_pow(x, n >> 1, module) % module;
        res = (res * res) % module;
        if n & 1 == 1 {
            res *= x;
        }
        res % module
    }
}

#[cfg(test)]
mod test {
    use super::*;
    #[test]
    fn test_mod_util() {
        const MOD: usize = 1e9 as usize + 7;
        let mod_util = ModUtil::new(1000, MOD);
        //fact
        assert_eq!(mod_util.fact(5), 120);
        assert_eq!(mod_util.fact(10), 3628800);
        assert_eq!(mod_util.fact(500), 688653593);
        assert_eq!(mod_util.fact(1000), 641419708);
        //combination
        assert_eq!(mod_util.combination(5, 3), 10);
        assert_eq!(mod_util.combination(10, 2), 45);
        assert_eq!(mod_util.combination(1000, 500), 159835829);
        //permutation
        assert_eq!(mod_util.permutation(5, 3), 60);
        assert_eq!(mod_util.permutation(10, 3), 720);
        assert_eq!(mod_util.permutation(1000, 999), 641419708);

        //inv fact
        for i in 1..1000 {
            let one = mod_util.fact(i) * mod_util.inv_fact(i) % MOD;
            assert_eq!(one, 1);
        }
    }
}

#[derive(Default)]
//NOTE
//declare variables to reduce the number of parameters for dp and dfs etc.
struct Solver {}

const MAX_N: usize = 200010;
impl Solver {
    fn solve(&mut self) {
        let stdin = std::io::stdin();
        let mut scn = Scanner {
            stdin: stdin.lock(),
        };
        let n: usize = scn.read();
        let x: Vec<_> = scn.chars();
        let mut bit_cnt = 0;
        let mut cnts = vec![0; MAX_N];
        for x in 1..MAX_N {
            let bit = x.count_ones() as usize;
            cnts[x] = cnts[x % bit] + 1;
        }

        x.iter().for_each(|x| {
            if *x == '1' {
                bit_cnt += 1;
            }
        });
        //p1, p2, p3
        let p1 = bit_cnt + 1;
        let p2 = if bit_cnt == 1 { 1 } else { bit_cnt - 1 };
        let zero = if bit_cnt == 1 {
            true
        } else {
            false
        };

        let mut m1 = 0;
        let mut m2 = 0;
        x.iter().for_each(|x| {
            m1 *= 2;
            m2 *= 2;
            if *x == '1' {
                m1 += 1;
                m2 += 1;
            }
            m1 %= p1;
            m2 %= p2;
        });
        let mut results = vec![0; n];
        for (idx, b) in x.iter().rev().enumerate() {
            if *b == '1' {
                let a = ModUtil::mod_pow(2, idx, p2);
                let cnt = (m2 + p2 - a) % p2;
                if !zero {
                    results[idx] = cnts[cnt] + 1;
                } else {
                    results[idx] = 0;
                }
                
            } else {
                let a = ModUtil::mod_pow(2, idx, p1);
                let cnt = (m1 + p1 + a) % p1;
                results[idx] = cnts[cnt] + 1;
            }
        }
        results.reverse();

        for x in results.iter() {
            println!("{}", x);
        }
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| {
            let mut solver = Solver::default();
            solver.solve()
        })
        .unwrap()
        .join()
        .unwrap();
}
pub mod utils {
    const DYX: [(isize, isize); 8] = [
        (0, 1),   //right
        (1, 0),   //down
        (0, -1),  //left
        (-1, 0),  //top
        (1, 1),   //down right
        (-1, 1),  //top right
        (1, -1),  //down left
        (-1, -1), //top left
    ];

    pub fn try_adj(y: usize, x: usize, dir: usize, h: usize, w: usize) -> Option<(usize, usize)> {
        let ny = y as isize + DYX[dir].0;
        let nx = x as isize + DYX[dir].1;
        if ny >= 0 && nx >= 0 {
            let ny = ny as usize;
            let nx = nx as usize;
            if ny < h && nx < w {
                Some((ny, nx))
            } else {
                None
            }
        } else {
            None
        }
    }
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 3436