import Control.Monad import Data.List main = do n <- readLn ws <- replicateM n $ words <$> getLine putStrLn . show $ solve ws solve :: [[String]] -> Int solve ws = read $ head $ foldl intersect ["0","1","2","3","4","5","6","7","8","9"] ws' where ws' = map check ws :: [[String]] check :: [String] -> [String] check xs = if e == "NO" then filter (\n -> not (elem n xs')) ["0","1","2","3","4","5","6","7","8","9"] else xs' where xs' = take 4 xs :: [String] e = xs !! 4 :: String