Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in

    let rec loop i carry acc =
        if i = n then acc else
            if a.(i) = 0 then loop (i + 1) 0 acc else
                let t = (carry + a.(i)) / 2 in
                let carry = (carry + a.(i)) mod 2 in
                loop (i + 1) carry (acc + t)
    in
    loop 0 0 0 |> Printf.printf "%d\n"
)