#C8403. Counting Prefixes

    ID: 52382 Type: Default 1000ms 256MiB

Counting Prefixes

Counting Prefixes

This problem requires you to count the number of identifiers that start with each given prefix. You are provided with a list of identifiers and a list of prefix queries. For each prefix, determine how many identifiers begin with that prefix.

Formally, for each prefix \(p\), compute:

\(\text{count} = \sum_{i=1}^{n} \mathbf{1}_{\{s_i \text{ starts with } p\}}\)

Note: An empty prefix matches all identifiers.

inputFormat

The input is read from standard input. It is given as a series of tokens separated by whitespace:

  • The first token is an integer \(n\) representing the number of identifiers.
  • Then \(n\) identifiers, each separated by whitespace.
  • Next, an integer \(q\) representing the number of prefix queries.
  • Then \(q\) prefixes, each separated by whitespace.

outputFormat

For each of the \(q\) prefix queries, output the number of identifiers that start with the given prefix on a separate line.

## sample
5
elephant eagle elk dog deer
3
el ea d
2

1 2

</p>