Scanf.scanf "%d %s" (fun n x ->
    let rec loop i acc =
        if i = n then acc else
            if x.[i] = '1' then loop (i + 1) (acc + 1)
                           else loop (i + 1) acc
    in
    let bits = loop 0 0 in
    let calc i =
        let initialmod =
            if bits = 1 && x.[i] = '1' then 0 else
            if bits = 0 && x.[i] = '0' then 0 else
                let bits = if x.[i] = '1' then bits - 1 else bits + 1 in
                let rec loop pos rest =
                    if pos = n then rest else
                        let rest = rest * 2 + (if x.[pos] = '1' then 1 else 0) in
                        let rest = if i = pos then rest lxor 1 else rest in
                        let rest = rest mod bits in
                        loop (pos + 1) rest
                in
                loop 0 0
        in
        let popcount a =
            let rec loop rest acc =
                if rest = 0 then acc else loop (rest lsr 1) (acc + (rest land 1))
            in
            loop a 0
        in
        let rec phase2 md count =
            if md = 0 then count else
                let md = md mod (popcount md) in
                phase2 md (count + 1)
        in
        phase2 initialmod 1
    in
    for i = 0 to n - 1 do
        Printf.printf "%d\n" @@ calc i
    done
)