import Control.Applicative import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.List import Data.Char (isSpace) import Data.Vector (Vector, (!), (//)) import qualified Data.Vector as V import Data.IntSet (IntSet) import qualified Data.IntSet as IS main :: IO () main = solve <$> f <*> g >>= putStrLn where f = readil B.readInt <$> B.getLine g = readiv B.readInt <$> B.getLine solve :: [Int] -> Vector Int -> String solve [n, k] v | ct <= k && even (k - ct) = "YES" | otherwise = "NO" where (ct, _) = V.ifoldl' f (0, IS.empty) v f (ct, mm) i x | i+1 == x = (ct, mm) | otherwise = count (ct, mm) i count (ct, mm) i | IS.member (v ! i - 1) mm = (ct, IS.insert i mm) | otherwise = count (ct+1, IS.insert i mm) (v ! i - 1) readil :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a] readil f = unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s') readiv :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> Vector a readiv f = V.unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s')