main :: IO ()
main = do
  n <- getLine
  wn <- map (read :: String -> Int) . words <$> getLine
  print $ ans wn

ans :: [Int] -> Int
ans wn = snd $ foldl func (allW,allW) wn where
  func (a,m) w = (a-2*w,min m $ abs (a-2*w))
  allW = sum wn