main = do
  n <- getLine
  a <- (map read . words) <$> getLine
  putStrLn .show $ solve a

solve:: [Int] -> Int
solve a = solve' (sum a) a

solve' to (a:as) = cho to a (abs (to - a - a)) as

cho:: Int -> Int -> Int -> [Int] -> Int
cho to su d [] = d
cho to su d (a:as)
  | as == [] = d
  | otherwise = min d $ cho to (su + a) (abs (to - su - su - a - a)) as 
