import qualified Data.Vector.Unboxed as VU
import Data.ByteString.Char8 as B
import Data.Char
import Control.Monad

solve vec a b i
    | i == 1 = diff
    | otherwise = min diff (solve vec (a-v) (b+v) (i-1))
    where
        v = vec VU.! i
        diff = abs $ (a-v) - (b+v)

main = do
    n <- readLn :: IO Int
    xs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    print $ solve xs (VU.sum xs) 0 (n-1)