main = do
	n <- read <$> getLine :: IO Int
	sticks <- map read.words <$> getLine :: IO [Int]
	putStrLn.show $ cost sticks

cost :: [Int] -> Int
cost sticks = minimum $ map calc dividedSticks where
	dividedSticks =  map (flip splitAt sticks) [1..length sticks-1]
	calc (a,b) = abs (sum a - sum b)