import Control.Applicative ((<$>), (<*>)) import Control.Monad (replicateM, guard) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.List (unfoldr, foldl', find) import Data.Char (isSpace) import Data.Vector (Vector, (!), (//)) import qualified Data.Vector as V main :: IO () main = do [n, m] <- readil B.readInt <$> B.getLine solve n <$> (readil B.readInt <$> B.getLine) <*> replicateM m (readil B.readInt <$> B.getLine) >>= putStrLn solve :: Int -> [Int] -> [[Int]] -> String solve n al es = maybe "NO" (const "YES") $ find kdmt ls where g = mkg n es av = V.fromList al ls = do i <- [1..n] j <- g ! i k <- g ! j guard $ i /= k return (av ! (i-1), av ! (j-1), av ! (k-1)) mkg :: Int -> [[Int]] -> Vector [Int] mkg n es = foldl' f (V.replicate (n+1) []) es where f v [x, y] = v // [(x, y : v ! x),(y, x : v ! y)] kdmt :: (Int, Int, Int) -> Bool kdmt (x, y, z) = x /= z && ((y > x && y > z) || (y < x && y < z)) 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')