(* O(n) *)
open Array
open Hashtbl
let n = Scanf.scanf " %d" @@ (+) 0
let a_s = init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let sums = make (n + 1) 0
let h = create @@ n + 1
let f s = try let c = find h s in replace h s @@ c + 1 with _ -> add h s 1
let _ =
  iteri (fun i a -> sums.(i + 1) <- sums.(i) + a) a_s;
  Array.iter f sums;
  fold (fun s c acc -> acc + if c > 1 then c * (c - 1) / 2 else 0) h 0 |> Printf.printf "%d\n"