calc :: [Int] -> Int -> [Int]
calc _ 0  = []
calc xs n = abs (sum (take n xs) - sum (drop n xs)) : calc xs (n - 1)

main :: IO ()
main = do
  n <- readLn :: IO Int
  xs <- map read . words <$> getLine :: IO [Int]
  print $ minimum $ calc xs n
