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

    let f x = if x >= 0 then x / 2 else 0 in
    
    let rec loop i r0 r1 =
        if i = n then max r0 r1 else
            if a.(i) = 0 then loop (i + 1) r0 0 else
                let r0a = max (r0 + f a.(i))       (r1 + f (a.(i) - 1)) in
                let r1a = max (r0 + f (a.(i) - 1)) (if a.(i) = 1 then 0 else r1 + f (a.(i) - 2)) in
                loop (i + 1) r0a r1a
    in
    loop 1 (f a.(0)) (f (a.(0) - 1)) |> Printf.printf "%d\n"
)