import Data.List

main = do
    n <- getLine
    list <- readArray getLine
    let res = sum $ map (\x -> div (x*(x-1)) 2) (map length $ group $ sort $ cumulativeSum list [0])
    print res
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])