import Data.List
import Control.Applicative

listsumcut :: Int->[Int]->[Int]->[Int]
listsumcut s (x:xs) accum
    |length xs == 1 = x:accum
    |sum accum <= s = listsumcut s xs $ x:accum
    |otherwise = accum

solverpre1 :: [Int]->[Int] -> Int
solverpre1 list list2 = abs $ 2* (sum $ list2) - (sum list)

solverpre2 :: [Int]->[Int]-> Int
solverpre2 list list2 = abs $ 2* (sum $ tail list2) - (sum list)

solver (x:y:[]) = abs (x-y)
solver list = let ac = listsumcut (sum list `div` 2) list [] in minimum (solverpre1 list ac, solverpre2 list ac)


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

