main = do
  _ <- getLine
  xs <- map read . words <$> getLine
  print $ solve 0 s xs (sum xs)
 
solve _ _ [] _ p = p
solve x y (z:zs) p
  | q < p = solve (x + z) (y - z) zs q
  | otherwise = solve (x + z) (y - z) zs p
    where q = abs (x - y + 2 * z)