import Control.Monad
import Data.List

main = do
    n <- readLn :: IO Int
    wn <- map read . words <$> getLine :: IO [Int]
    let s = sum wn
    print $ head $ sort $ map (\x -> abs (x - abs (x - s))) $ tail $  scanl (+) 0 wn
