import Data.List

main = do
  _ <- getLine
  li <- getLine
  let ws = map read $ words li
  let answer = compute ws
  print answer

compute ws = minimum ds
  where
    t = sum ws
    ss = scanl1 (+) ws
    ds = map (\x -> abs (x+x-t)) ss
