solve :: [Int] -> [Int] -> [Int]
solve _ [_] = []
solve s1 (s:s2) = result:solve (s:s1) s2
  where result = abs $ sum (s:s1) - sum s2

main :: IO ()
main = do
  getLine
  ws <- map read . words <$> getLine
  print . minimum $ solve [] ws
