Scanf.scanf "%d %s" (fun n a ->
    let a = Array.init n (fun i -> int_of_char a.[i] - 49) in

    let bits k =
        let rec loop i acc =
            if i = 0 || i land 1 = 1 then acc else loop (i lsr 1) (acc + 1)
        in
        loop k 0
    in

    let calc aa =
        let l = Array.length aa in
        let rec loop a b acc ev =
            if a < 0 then ev else
                let ev = if acc > 0 then ev else ev lxor aa.(a) in
                let acc = acc + bits a - bits b in
                loop (a - 1) (b + 1) acc ev
        in
        loop (l - 1) 1 0 0
    in
    Printf.printf "%d\n" @@
    if calc a mod 2 = 1 then 1 else
        if Array.exists (fun a -> a = 1) a then 0 else
            calc (Array.map (fun a -> a / 2) a) * 2
)