main :: IO () main = interact $ solve . map read . words f :: [(Int, Int)] -> (Int, Int) f xs = foldr (\x acc -> if snd x == 0 then ((fst acc) + 1, snd acc) else (fst acc, (snd acc) + 1)) (0, 0) xs solve :: [Int] -> String solve (n:xs) = if (s - t) >= 0 then "YES" else "NO" where ys = take n xs zs = drop n xs ws = zip ys zs (s, t) = f ws