module P = Map.Make(struct type t = int let compare = (-) end)
let _ = Scanf.scanf "%d" @@ fun n ->
  Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0))
  |> Array.fold_left (fun (v, (s, m)) x ->
      let c = try P.find (s+x) m with | _ -> 0 in
      (v+c, (s+x, P.add (s+x) (c+1) m))) (0, (0, P.singleton 0 1))
  |> fst |> Printf.printf "%d\n"