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

-- |
--
-- >>> solve [1 .. 6]
-- 1
--
-- >>> solve [10, -10]
-- 20
solve :: [Int] -> Int
solve as = minimum $ map (\x -> abs $ x - (s-x)) $ scanl1 (+) (init as)
  where s = sum as
