#K42942. Subsequence Finder

    ID: 27199 Type: Default 1000ms 256MiB

Subsequence Finder

Subsequence Finder

Given a string s and a list of candidate words, your task is to determine which candidate words are subsequences of s. A subsequence is defined as a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. In other words, for a candidate word to be a subsequence of s, all characters of the candidate must appear in s in the same order.

If none of the candidate words is a subsequence of s, output NO.

inputFormat

The input is read from standard input (stdin).

The first line contains the string s.
The second line contains an integer n, representing the number of candidate words.
The following n lines each contain one candidate word.

outputFormat

Output the candidate words that are subsequences of s in the order they appear in the input, each printed on a new line. If there are none, print NO.## sample

abcde
3
a
bb
ace
a

ace

</p>