import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Array as A
import Data.Bits (shiftR)

main :: IO ()
main = do
  (n : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  as <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    as' = A.listArray (0, n) . scanl (+) 0 $ as :: A.Array Int Int
    l = as' A.! n
    i = binarySearch l n as' :: Int
  print $ min (l - 2 * (as' A.! i)) (2 * (as' A.! succ i) - l)

binarySearch :: Int -> Int -> A.Array Int Int -> Int
binarySearch l n as = binarySearch' 0 n
  where
    h = halve l
    binarySearch' i j | j == succ i = i
                      | as A.! m <= h = binarySearch' m j
                      | otherwise = binarySearch' i m
      where
        m = halve (i + j)

halve :: Int -> Int
halve = flip shiftR 1

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
