main = do
        _ <- getLine
        as <- map read . words <$> getLine
        let s = sum as
        print . minimum $ f as (0, s)

dist (x, y) = abs (x - y)

f [] _ = []
f (a:as) (x, y) =
         dist (x + a, y - a) : f as (x + a, y - a)

