-- Question C Time Over

import Control.Applicative
import Control.Monad

main = do
  n <- readLn ::IO Int
  xs <- (map read . words) <$> getLine 
  putStr $ show ( minimum (memo xs n) )
  
sunuke xs i = sum ( take i xs)
araisan xs i = sum ( drop i xs)

memo xs n = [abs( (sunuke xs i)-(araisan xs i) ) | i <- [1..(n-1)] ] 