import Control.Applicative
import Control.Monad
import qualified Data.List
import qualified Data.Char
import Debug.Trace

main ::IO()
main = do
  n <- read <$> getLine :: IO Int
  ws <- map read . words <$> getLine :: IO [Int]
  putStrLn $ show $ solve ws

solve :: [Int] -> Int 
solve ws =
  -- traceShow slws $
  -- traceShow srws $
  ans
  where
    slws = scanl (+) 0 ws
    srws = scanr (+) 0 ws
    ans = minimum $ zipWith (\a b -> abs (a-b)) slws srws