#C3422. Subsequence Matching

    ID: 46848 Type: Default 1000ms 256MiB

Subsequence Matching

Subsequence Matching

Given a string \(s\) and a list of words \(W\), your task is to determine how many words in \(W\) are subsequences of \(s\). A subsequence is a sequence that can be derived from \(s\) by deleting zero or more characters without changing the order of the remaining characters.

For example, if \(s = \texttt{abcde}\) and \(W = [\texttt{a}, \texttt{bb}, \texttt{acd}, \texttt{ace}]\), then the count of matching subsequences is 3 because "a", "acd", and "ace" are valid subsequences, while "bb" is not.

The problem requires you to read input from standard input (stdin) and print output to standard output (stdout).

inputFormat

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

  1. The first line contains the string \(s\).
  2. The second line contains an integer \(n\), the number of words.
  3. The next \(n\) lines each contain a word.

outputFormat

Output a single integer to stdout representing the count of words that are subsequences of \(s\).

## sample
abcde
4
a
bb
acd
ace
3