
solve as l r
  | l == r = l
  | abs (sum ll-sum lr) < abs (sum rl-sum rr) = solve as l ((l+r)`div`2)
  | otherwise = solve as ((l+r)`div`2) r
  where
    (ll,lr) = splitAt l as
    (rl,rr) = splitAt r as


main :: IO ()
main = do
  _ <- read <$> getLine :: IO Int
  as <- map read.words <$> getLine :: IO [Int]
  let (l,r) = splitAt (solve as 1 (length as-1)) as
  print $ abs $ sum l - sum r
