open Batteries
let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let a_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in

  let rev_cumsum l =
    let rec aux last res = function
      | [] -> res
      | hd :: tl -> 
        let last = last + hd in
        aux last (last::res) tl
    in
    aux 0 [] l
  in
  let l = List.rev (rev_cumsum a_lst) in
  let aux sign =
    let _,res,_ =
      List.fold_left (fun (cum, cnt, sign) x -> 
          match sign with
          | `Plus -> if x + cum <= 0 then let x = x+cum in ((cum+1-x), (cnt+1-x), `Minus) else (cum,cnt,`Minus)
          | `Minus -> if x + cum >= 0 then let x = x+cum in ((cum+(-1-x)), (cnt-(-1-x)), `Plus) else (cum,cnt,`Plus)
        ) (0,0,sign) l
    in
    res
  in

  let ans1 = aux `Plus in
  let ans2 = aux `Minus in
  Printf.printf "%d\n" @@
  if ans1 > ans2 then ans2 else ans1

