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 ws = U.minimum $ U.map (\x -> abs (2 * x - s)) $ U.scanl' (+) 0 ws
  where
    s = U.sum ws