Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

By SaikatS · Limits 1s, 256 MB

One day the penguins of Madagascar found a string S... Wait... Wait. Actually the setter of the problem does not like long descriptions. So here is your problem:

You are given a string $S$ of length $N$ and some query $Q$. In each query, you are given a string $B$. You have to answer whether the string $B$ is a subsequence of $S$ or not.

A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. Subsequences for the word "apple" is “apl”, “ple”, “p” etc but “ael”, “alp” is not a subsequence of “apple”.

You have to find query $B$ is a subsequence of $S$ or not in each query.

Input

The first line contains an integer $N$ ($1 \le N \le 10^5$), the size of string $S$. The second line contains a string $S$, only lower case letter (‘a’-’z’) and the third line contains an integer $Q$ ($1 \le Q \le 10^5$), the number of queries.

Each of the next lines contains a string $B$ ($1 \le |B| \le 100$) to analyze.

Output

For each query, print $\texttt{YES}$ if $B$ is a subsequence of $S$ or print $\texttt{NO}$.

Sample

InputOutput
16
helloonetwothree
5
hello
one
hren
heeoe
oneho

YES
YES
NO
YES
NO


Statistics

63% Solution Ratio

akash740Earliest, Jul '20

md_jakariyaFastest, 0.1s

alifcsejuLightest, 1.1 MB

YouKnowWhoShortest, 626B