Practice on Toph

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

Penguins of Madagascar

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 SS of length NN and some query QQ. In each query, you are given a string BB. You have to answer whether the string BB is a subsequence of SS 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 BB is a subsequence of SS or not in each query.

Input

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

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

Output

For each query, print YES\texttt{YES} if BB is a subsequence of SS or print NO\texttt{NO}.

Sample

InputOutput
16
helloonetwothree
5
hello
one
hren
heeoe
oneho
YES
YES
NO
YES
NO

Discussion

Statistics


63% Solution Ratio

akash740Earliest, Jul '20

md_jakariyaFastest, 0.1s

alifcsejuLightest, 1.1 MB

YouKnowWhoShortest, 626B

Submit

Login to submit

Related Contests

Toph uses cookies. By continuing you agree to our Cookie Policy.