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

solve :: (Int, Int, [Int]) -> Int
solve (x, 0, 0:as) = min (solve (x+1, 1, as)) (solve (x+1, -1, as))
solve (x, _, []) = x
solve (x, s, a0:as) = solve (x+k, s + a0 + k, as)
    where
      m = if s > 0 then -1 else 1
      k = m - (s + a0)
