main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- map read . words <$> getLine :: IO [Int]
  print $ solve as

solve :: [Int] -> Int
solve as = minimum $ map (abs . (s -) . (2 *)) ss
  where
    s = sum as
    ss = scanl1 (+) $ init as
