• + 0 comments

    Haskell

    module Main where
    
    import Control.Monad (replicateM, replicateM_)
    import qualified Data.Map as M
    
    main :: IO ()
    main = do
        n <- readLn :: IO Int
        ds <- replicateM n getLine
        let dm = M.fromListWith (+) $ map (\s -> (s,1)) ds
        q <- readLn :: IO Int
        replicateM_ q $ do
            s <- getLine
            print $ M.findWithDefault 0 s dm