import qualified Data.ByteString.Char8 as B import Data.IntMap.Strict ((!)) import qualified Data.IntMap.Strict as M import Data.Maybe import Data.Bool import Data.List main = do [_,k] <- map read . words <$> getLine ds <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine putStrLn $ bool "NO" "YES" (anata k ds) anata :: Integer -> [Int] -> Bool anata k ds = nmin <= k && even (k - nmin) where im = M.fromDistinctAscList (zip [1..] ds) nmin = countCycle 0 im countCycle n im | M.null im = n | otherwise = countCycle (n+n') im'' where ((k,v),im') = M.deleteFindMin im (n',im'') = deleteCycle k v (0, im') deleteCycle k v (n,im) | k == v = (n,im) | otherwise = deleteCycle k (im!v) (n+1, M.delete v im)