Language - MarisaOJ: Marisa Online Judge

Language

Time limit: 1000 ms
Memory limit: 256 MB
In the language of a certain country, there are $n$ words. A sentence in this language must be represented by concatenating some words from this language, and a word can be used multiple times. For example, if the language has three words `ma`, `ri`, `sa`, then `marisa` is a valid sentence, `ririri` is also valid, but `maris` is not. Given $q$ queries, each query is a string $S$, check whether this string is a valid sentence in this language or not. ### Input - The first line consists of two integers $n, q$. - The next $n$ lines, each line is a word in this language. - The next $q$ lines, each line is a string $S$, a query. ### Output - For each query, print `YES` on a separate line if the string is a valid sentence in this language; otherwise, print `NO`. ### Constraints - $1 \le n, q \le 10^5$. - $1 \le \sum{|S|} \le 10^5$. - All strings consist only of lowercase letters. The length of each word in this language does not exceed $10$. ### Example Input: ``` 3 5 ma ri sa marisa sarima rias mamasa ririririma ``` Output: ``` YES YES NO YES YES ```