import qualified Data.ByteString.Lazy.Char8 as B                                
import Data.Maybe                                                               
import qualified Data.IntMap as IM                                              
                                                                                
bsReadInts :: B.ByteString -> [Int]                                             
bsReadInts = map (fst . fromJust . B.readInt) . B.words                         
                                                                                
solve :: Int -> [Int] -> Int                                                    
solve n as =                                                                    
  s                                                                             
  where                                                                         
    fsum = scanl (+) 0 as                                                       
    im = foldr op IM.empty fsum                                                 
      where op n im = IM.alter upd n im                                         
              where upd Nothing  = Just 1                                       
                    upd (Just c) = Just (c+1)                                   
    s = foldr op 0 im                                                           
      where op x a = x - 1 + a                                                  
                                                                                
main = do                                                                       
  conts <- B.getContents                                                        
  let n : as = bsReadInts conts                                                 
      answer = solve n as                                                       
  putStrLn (show answer)                                                        