main = do
  _ <- getLine
  as <- map read . words <$> getLine
  print . minimum . diffsum . subsum $ as
 
subsum :: [Int] -> [Int]
subsum [] = []
subsum (x:xs) = x : (map (+ x) (subsum xs))
 
diffsum xs = [ abs (2 * x - s) | x <- xs ]
  where s = last xs