main = print . solve . map read . drop 1 . words =<< getContents

solve :: [Integer] -> Integer
solve xs =
    let summed = drop 1 $ scanl (+) 0 xs
    in  foldl (\ac x -> min (abs $ last summed - x - x) ac) 1000000000 $ init summed
