import Control.Applicative
import Data.List

main = do
  _ <- getLine
  as <- (map read) . words <$> getLine

  print $ sum $ zipWith (\a b -> abs (a-b)) as (f 0 as)
  
  where
    f _ [] = []
    f sum (x:xs)
      | sum < 0 = if sum + x > 0 then x : f (sum+x) xs else (1-sum) : f 1 xs
      | sum > 0 = if sum + x < 0 then x : f (sum+x) xs else (-1-sum) : f (-1) xs
      | sum == 0 = x : f x xs
