import Prelude hiding (tail, length, map, splitAt, (++), (!!)) import Data.Vector (!!) :: Vector a -> Int -> a v !! x = v ! (pred x) swap :: Vector a -> Int -> Int -> Vector a swap xs a b = fst t1 ++ singleton (xs !! j) ++ fst t2 ++ singleton (xs !! i) ++ t3 where i = min a b j = max a b t1 = splitAt (pred i) xs t2 = splitAt (pred $ j - i) (tail . snd $ t1) t3 = tail . snd $ t2 rep :: Integral a => Vector Int -> Vector Int -> Int -> a -> a rep ds idxs i cnt | i > length ds = cnt | ds !! i == i = rep ds idxs (succ i) cnt | otherwise = rep (swap ds i (idxs !! i)) (swap idxs (ds !! i) (ds !! (idxs !! i))) (succ i) (succ cnt) solve :: Integral a => Int -> a -> Vector Int -> Bool solve n k ds | cnt <= k && even (k - cnt) = True | otherwise = False where Just idxs = fmap (fmap succ) . sequenceA $ (\x -> findIndex (== x)) <$> generate n succ <*> pure ds cnt = rep ds idxs 1 0 main = do [n, k] <- fmap read . words <$> getLine ds <- fromList . fmap read . words <$> getLine putStrLn $ case solve n k ds of True -> "YES" False -> "NO"