main=do
 n<-readLn
 a<-map read.words<$>getLine
 print(g (n-1) 1 (abs((sum (tail a))-(head a))) (head a) (sum(tail a)) (tail a))
  where g n i f s b a | n==i      = f
                      | otherwise = g n (i+1) (min f (abs ((s+(head a))-(b-(head a))))) (s+(head a)) (b-(head a)) (tail a)