import Control.Applicative import Data.Bool (bool) import Data.Vector.Unboxed (Vector, (!), (//)) import qualified Data.Vector.Unboxed as V main :: IO () main = getLine >> solve <$> f <*> f >>= putStrLn where f = map read <$> words <$> getLine solve :: [Int] -> [Int] -> String solve as bs = bool "YES" "NO" $ any g [1 .. 100] where vi = V.replicate 101 0 :: Vector Int f v (p, i) = v // [(i, v ! i + p)] v = foldl f vi (zip as bs) pk = v ! 0 g i = pk < v ! i