main = do
  _ <- getLine
  as <- map read . words <$> getLine
  print $ solve 0 s as s
    where s = (abs $ sum as)

solve _ _ [] _ p = p
solve x y (a:as) p
  | q < p = solve (x + a) (y - a) as q
  | otherwise = solve (x + a) (y - a) as p
    where q = abs (x - y + 2 * a)