#K56567. Counting Subsequences

    ID: 30227 Type: Default 1000ms 256MiB

Counting Subsequences

Counting Subsequences

You are given a string (S) and a list of words. Your task is to count the number of words in the list that are subsequences of (S). A subsequence is a sequence that can be derived from another sequence by deleting some (or no) characters without changing the order of the remaining characters.

For example, if (S = "abc") and the list of words is ["a", "b", "c", "d", "ac"], then the answer is 4 because "a", "b", "c", and "ac" are subsequences of (S).

inputFormat

The input is given via standard input (stdin) in 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 following (N) lines each contain one word from the list.

outputFormat

Output a single integer to the standard output (stdout) representing the number of words that are subsequences of (S).## sample

abc
5
a
b
c
d
ac
4