main :: IO ()
main = do
    _ <- readLn :: IO Int
    as <- (map read . words) <$> getLine
    print $ solve as

-- |
--
-- >>> solve [1, -3, 1, 0]
-- 4
--
-- >>> solve [3, -6, 4, -5, 7]
-- 0
--
-- >>> solve [-1, 4, 3, 2, -5, 4]
-- 8
solve :: [Int] -> Int
solve [] = 0
solve (a0:as) = min x y
  where
    x = solve' (0,  1, a0, as)
    y = solve' (0, -1, a0, as)

solve' :: (Int, Int, Int, [Int]) -> Int
solve' (x, _, _, []) = x
solve' (x, u, s, a0:as) = solve' (x + abs k, -u, s' + k, as)
  where
    s' = s + a0
    k = if u * s' <= 0 then u - s' else 0
