open Batteries

module Int64map = Map.Make(Int64)

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

  let arr = Array.make a 0L in
  for i = 0 to a-1-1 do
    let c = Scanf.scanf "%Ld " (fun c -> c) in
    Array.set arr i c
  done;
  let c = Scanf.scanf "%Ld\n" (fun c -> c) in
  Array.set arr (a-1) c;

  let arr2 = Array.make a 0L in
  for i=0 to a-1 do
    arr2.(i) <- (Int64.add arr.(i) (if i<>0 then arr2.(i-1) else 0L));
  done;

  let arr2 = Array.append arr2 [|0L|] in

  let nc2 n =
    if n < 2L then 0L else Int64.div (Int64.mul n (Int64.sub n 1L)) 2L
  in

  let m = ref Int64map.empty in

  Array.iter (fun x ->
      m := Int64map.add x (Int64.add (Int64map.find_default 0L x !m) 1L) !m;
      ()
    ) arr2;

  let mm = Int64map.map (nc2) !m in
  let cnt = Int64map.fold (fun k v1 v2 -> Int64.add v1 v2) mm 0L in

  print_endline (Int64.to_string cnt)


