#C13310. Subsequence Extraction

    ID: 42835 Type: Default 1000ms 256MiB

Subsequence Extraction

Subsequence Extraction

Given a list of strings and a target string, your task is to extract all strings from the list that can be formed by deleting some characters (possibly none) from the target string without reordering the remaining characters. In other words, a string s is a subsequence of the target string t if there exist indices \(1 \le i_1 < i_2 < \cdots < i_{|s|} \le |t|\) such that \(s[k] = t[i_k]\) for every valid index \(k\).

For example, given the list ["abc", "ac", "b"] and the target string "abc", all strings in the list are valid because:

  • "abc" is identical to the target.
  • "ac" can be obtained by removing the second character 'b' from "abc".
  • "b" is a subsequence since it appears in order.

Your solution should read from standard input and output the valid subsequences to standard output.

inputFormat

The input is read from stdin and has the following format:

  1. An integer n representing the number of strings in the list.
  2. n lines follow, each containing a non-empty string.
  3. A final line containing the target string.

You can assume that all strings consist of printable characters and have length at most 100.

outputFormat

Output all strings from the input list that are subsequences of the target string, each on its own line, in the same order as they appear in the input. If no string qualifies, output nothing.

## sample
3
abc
ac
b
abc
abc

ac b

</p>