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

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

solve :: U.Vector Int -> Int
solve = U.minimum . U.map abs . (U.zipWith (-) <$> U.scanl' (+) 0 <*> U.scanr (+) 0)