open Batteries
let n = read_int ()
let a = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ fun a -> a
let dp = Array.init n (fun _ -> 0)

let rec loop i =
  if i >= n then () else (dp.(i) <- dp.(i-1) + a.(i); loop (i+1))

let _ = dp.(0) <- a.(0); loop 1

let rec i_loop i =
  let rec j_loop j =
    if j >= n then 0 else
    (if dp.(j) - dp.(i) = 0 then 1 + (j_loop @@ j+1) else j_loop @@ j+1)
  in if i >= n-1 then 0 else
  (
    (j_loop @@ i+1) + (i_loop @@ i+1)
  )

let _ = Printf.printf "%d\n" @@ i_loop 0