Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let calc sign =
        let rec loop i sum acc sign =
            if i = n then acc else
                let sum = sum + a.(i) in
                if sum * sign > 0 then loop (i + 1) sum acc (-sign) else
                    loop (i + 1) sign (acc + abs sum + 1) (-sign)
        in
        loop 0 0 0 sign
    in
    min (calc 1) (calc (-1)) |> Printf.printf "%d\n"
)