import Control.Monad import Data.List import Data.Char main = do s <- getLine getLine cs <- lines <$> getContents print (searchString s cs) searchString s = sum . map (match s) match s c = length (filter (== (hash c)) (hashp (length c) s)) hash c = sum (zipWith (*) (map (\e -> ord e - 65) c) (iterate (*26) 1)) hashp l s = unfoldr (\s -> guard (length s >= l) >> Just (hash (take l s), tail s)) s