main = do
  n <- readLn
  as <- map read . words <$> getLine
  print . minimum . diffsum . subsum $ as

subsum [] = 0
subsum (x:xs) = x : map (+ x) $ subsum xs

diffsum xs = [ abs (2 * x - s) | x <- xs ]
  where s = last xs



