main :: IO()
main = do
  getLine
  lis <- words <$> getLine
  let numlis = map read lis
  print $ solve numlis 0


solve :: [Int] -> Int -> Int
solve [] x = 0
solve (x:xs) 0 = solve xs x
solve (x:xs) m
  | m > 0 = max 0 (sum+1) + solve xs (min sum (-1))
  | m < 0 = max 0 (1-sum) + solve xs (max sum 1)
  where sum = m+x
