import           Data.Char
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed   as U

main :: IO ()
main = do
  n <- readLn
  as <- U.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
  print $ solve as

solve :: U.Vector Int -> Int
solve as = U.minimum $ U.zipWith (\l r -> abs (l - r)) ls rs
  where
    ls = U.scanl' (+) 0 as
    rs = U.scanr (+) 0 as