Problem:
Score : 400 points

Problem Statement

Let \mathrm{popcount}(n) be the number of 1s in the binary representation of n.
For example, \mathrm{popcount}(3) = 2, \mathrm{popcount}(7) = 3, and \mathrm{popcount}(0) = 0.

Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0: "replace n with the remainder when n is divided by \mathrm{popcount}(n)." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.)

For example, when n=7, it becomes 0 after two operations, as follows:

\mathrm{popcount}(7)=3, so we divide 7 by 3 and replace it with the remainder, 1.

\mathrm{popcount}(1)=1, so we divide 1 by 1 and replace it with the remainder, 0.

You are given an integer X with N digits in binary.
For each integer i such that 1 \leq i \leq N, let X_i be what X becomes when the i-th bit from the top is inverted.
Find f(X_1), f(X_2), \ldots, f(X_N).

Constraints

1 \leq N \leq 2 \times 10^5

X is an integer with N digits in binary, possibly with leading zeros.

Input

Input is given from Standard Input in the following format:

N
X

Output

Print N lines. The i-th line should contain the value f(X_i).

Sample Input 1

3
011

Sample Output 1

2
1
1

X_1 = 7, which will change as follows: 7 \rightarrow 1 \rightarrow 0. Thus, f(7) = 2.

X_2 = 1, which will change as follows: 1 \rightarrow 0. Thus, f(1) = 1.

X_3 = 2, which will change as follows: 2 \rightarrow 0. Thus, f(2) = 1.

Sample Input 2

23
00110111001011011001110

Sample Output 2

2
1
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
3

Solution in Rust (1.42.0) (judge verdict: Wrong Answer)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
prog_comp::init!();

unsafe fn solve(#[allow(unused_variables)] io: &mut Io) {
    let n = io.ru();
    let x = io.rc();

    let ones = x.iter().filter(|d| **d == '1').count() as isize;
    let mut x_mod_ones = [0isize; 2];

    let mut t0 = vec![0isize; n];
    t0[n - 1] = 1;
    for i in (0..n - 1).rev() {
        t0[i] = (t0[i + 1] * 2) % (ones + 1);
    }
    for i in 0..n {
        if x[i] == '1' {
            x_mod_ones[0] = (t0[i] + x_mod_ones[0]) % (ones + 1);
        }
    }

    let mut t1 = vec![0isize; n];
    if ones >= 2 {
        t1[n - 1] = 1;
        for i in (0..n - 1).rev() {
            t1[i] = (t1[i + 1] * 2) % (ones - 1);
        }
        for i in 0..n {
            if x[i] == '1' {
                x_mod_ones[1] = (t1[i] + x_mod_ones[1]) % (ones - 1);
            }
        }
    }

    'outer: for i in 0..n {
        let ones = if x[i] == '1' { ones - 1 } else { ones + 1 };

        if ones == 0 {
            for _ in 0..n {
                io.w(0);
                return;
            }
        }

        let mut xi_mod_ones = if x[i] == '1' {
            (x_mod_ones[1] + ones - t1[i]) % ones
        } else {
            (x_mod_ones[0] + t0[i]) % ones
        };

        for j in 1.. {
            if xi_mod_ones == 0 {
                io.w(j);
                continue 'outer;
            }
            xi_mod_ones = xi_mod_ones % xi_mod_ones.count_ones() as isize;
        }
    }
}
*/

fn main() {
    let exe = "/tmp/bin1DCE1698";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";