{-# LANGUAGE BangPatterns #-}
import Data.List
import Control.Applicative

listsumcut :: [Int]->[Int]->[Int]
listsumcut [x] accum =accum
listsumcut !(x:xs) !(!a:!accum) = listsumcut xs $ (a+2*x):a:accum

solver (x:y:[]) = abs (x-y)
solver (x:xs) = minimum $ map abs $ listsumcut xs [x-(sum xs)]


main :: IO ()
main = do
    -- スペース区切り整数の入力
    getLine
    list <- map read . words <$> getLine
    -- 出力
    putStrLn $ show $ solver list

