import Data.List (intersect, (\\)) parseAnswer :: [String] -> [String] -> [String] parseAnswer cds (a : b : c : d : yn : _) | yn == "YES" = intersect [a, b, c, d] cds | otherwise = cds \\ [a, b, c, d] main :: IO () main = do let c0s = map (show :: Int -> String) [0 .. 9] _ <- getLine putStrLn . head . foldl parseAnswer c0s . map words . lines =<< getContents