main = interact main'

main' :: String -> String
main'
    = show . f . map read . words . head . lines

f :: [Integer] -> Integer
f x = g [] x 0 (sum x)

g :: [Integer] -> [Integer] -> Integer -> Integer -> Integer
g _ [] x _ = x
g xl (x:xr) suml sumr
    = min (g (x:xl) xr (suml+x) (sumr-x)) (abs (sumr - suml))