import Data.Char (ord, toUpper) head' :: [String] -> String head' str = if length str == 0 then "" else head str tail' :: [String] -> [String] tail' str = if length str == 0 then [""] else tail str leave :: Int -> [a] -> [a] leave n xs = drop (length xs - n) xs isInfixOf' :: String -> String -> Bool isInfixOf' n h | ln > lh = False | ln == lh = n `eqStr` h | ln < lh = n `eqStr` take ln h || n `isInfixOf'` tail h where ln = length n lh = length h delete' :: String -> String -> String delete' x y | lx > ly = y | x `eqStr` take lx y = drop lx y | otherwise = delete' x $ tail y where lx = length x ly = length y eqAlpha :: Char -> Char -> Bool eqAlpha c1 c2 = toUpper c1 == toUpper c2 eqStr :: String -> String -> Bool eqStr s1 s2 = and [cond1, cond2] where cond1 = length s1 == length s2 cond2 = and $ zipWith eqAlpha s1 s2 isSymbol :: Char -> Bool isSymbol c = or [cond1, cond2, cond3, cond4] where code = ord c cond1 = 32 <= code && code <= 47 cond2 = 58 <= code && code <= 64 cond3 = 91 <= code && code <= 96 cond4 = 123 <= code && code <= 126 is_digi :: (String, String) -> Bool is_digi (name, speech) = and [cond1, cond2] && or [cond3, cond4] where speech' = leave 6 speech cond1 = name == "digi" cond2 = "nyo" `isInfixOf'` speech' cond3 = and . (map isSymbol) . (delete' "nyo") $ speech' cond4 = leave 3 speech' `eqStr` "nyo" is_petit :: (String, String) -> Bool is_petit (name, speech) = and [cond1, cond2] && or [cond3, cond4] where speech' = leave 6 speech cond1 = name == "petit" cond2 = "nyu" `isInfixOf'` speech' cond3 = and . (map isSymbol) . (delete' "nyu") $ speech' cond4 = leave 3 speech' `eqStr` "nyu" is_rabi :: (String, String) -> Bool is_rabi (name, speech) = and [cond1, cond2] where cond1 = name == "rabi" cond2 = or . (map (not . isSymbol)) $ speech is_gema :: (String, String) -> Bool is_gema (name, speech) = and [cond1, cond2] && or [cond3, cond4] where speech' = leave 7 speech cond1 = name == "gema" cond2 = "gema" `isInfixOf'` speech' cond3 = and . (map isSymbol) . (delete' "gema") $ speech' cond4 = leave 4 speech' `eqStr` "gema" is_piyo :: (String, String) -> Bool is_piyo (name, speech) = and [cond1, cond2] && or [cond3, cond4] where speech' = leave 6 speech cond1 = name == "piyo" cond2 = "pyo" `isInfixOf'` speech' cond3 = and . (map isSymbol) . (delete' "pyo") $ speech' cond4 = leave 3 speech' `eqStr` "pyo" isCollect :: String -> Bool isCollect str = or $ map ($ (name, speech)) [is_digi, is_petit, is_rabi, is_gema, is_piyo] where name = (takeWhile (== ' ') str) ++ (head' . words $ str) speech = (unwords . tail' . words $ str) ++ (takeWhile (== ' ') $ reverse str) solve :: [String] -> [String] solve = map ((\x -> if x then "CORRECT (maybe)" else "WRONG!") . isCollect) main = interact $ unlines . solve . lines