module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let acc = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    acc.(i + 1) <- as_.(i) + acc.(i)
  done;
  let m =
    Array.fold_left (fun m a ->
      IntMap.add a (1 + try IntMap.find a m with Not_found -> 0) m) IntMap.empty acc in
  Printf.printf "%d\n" @@
  IntMap.fold (fun _ n -> ( + ) @@ n * (n - 1) / 2) m 0
