import Data.List

main = do
    n <- getLine
    list <- readArray getLine
    let cumList = cumulativeSum list [0]
    let l = map (\x -> div (x*(x-1)) 2) (map length $ group $ qSort cumList)
    print $ sum l
readArray::IO String -> IO [Int]
readArray = fmap $ map read . words
--累積和
cumulativeSum:: [Int]->[Int]->[Int]
cumulativeSum [] list = list
cumulativeSum (x:xs) sumList = cumulativeSum xs (sumList++[x + last sumList])
--クイックソート
qSort::[Int] -> [Int]
qSort [] = []
qSort (x:xs)
    | xs == [] = [x]
    | otherwise = qSort [y|y<-xs, y < x] ++ [x] ++ qSort [z|z<-xs, z >= x]