import Control.Applicative( (<$>))
import Data.List( sort)
import Data.Ratio( (%))
main = do
    n_ <- readLn::IO Int
    as_ <- map read . words <$> getLine
    let
	sm = sum $ toInteger <$> as_

	half = sm % 2

	sortedAs = toInteger <$> sort as_

	collect v (a:as)
	  | half-toRational v >= toRational a	= collect (v+a) as
	  | otherwise				= (v, sm-v)
	
    print . abs $ if n_ == 2
		then as_!!0 - as_!!1
		else (\(f,s) -> f-s) $ collect 0 sortedAs