#P8306. Prefix Query Count

    ID: 21485 Type: Default 1000ms 256MiB

Prefix Query Count

Prefix Query Count

Given nn pattern strings s1,s2,,sns_1, s_2, \dots, s_n and qq queries, each query provides a text string tt. For each query, count the number of strings among {s1,s2,,sn}\{s_1, s_2, \dots, s_n\} for which tt is a prefix.

A string tt is a prefix of a string ss if and only if after deleting some (possibly zero) characters from the end of ss, the string becomes tt. The input is case sensitive.

inputFormat

The first line contains an integer nn, the number of pattern strings.

The following nn lines each contain a non-empty pattern string.

The next line contains an integer qq, the number of queries.

The next qq lines each contain a query string tt.

outputFormat

For each query, output on a new line the count of pattern strings that have the query string as a prefix.

sample

5
apple
application
apricot
banana
band
3
app
ban
z
2

2 0

</p>