Killjee and bug

0

0 votes
Hard
Problem

Killjee being very afraid of bugs is trying to eliminate all the bugs from his world. In Killjee's world bugs are substrings of Killjee's special strings.

Killjee has N special strings and Q buggy strings. He wants you to find how many times every bug is found in KIlljee's special strings.

Note that a bug can occur more than once in a single special string.

INPUT CONSTRAINTS

  • 1N,Q105
  • 1 Sum of length of special strings 105
  • 1 Sum of length of buggy strings 106

INPUT FORMAT

First line of input contains a single integer N, number of special strings. N line follows each containing a special string. Next line contains a single string Q, Q lines follow each containing a bug.

OUTPUT FORMAT

Print Q lines each containing number of times ith bug occurs in Killjee's world.

Sample Input
2
aba
ab
2
a
ab
Sample Output
3
2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For 1st query "a" occur twice in 1st special string and once in 2nd special string,

For 2nd query "ab" occur once in both the special strings.

Editor Image

?