import Data.List

zeroSumRanges as n = length [() | i <- [0..(n-1)], k <- [i..(n-1)] , let sum = allSum - (front !! i + back !! k) , sum == 0]
    where
        sums = scanl' (+) 0 $ as
        allSum = last sums
        front = init $ sums
        back = tail . reverse . scanl' (+) 0 $ reverse as

main = do
    n <- read <$> getLine
    as <- map read . words <$> getLine
    putStrLn . show $ zeroSumRanges as n