10315: CF EDU - Suffix Array - Step 3 - B. Counting Substrings
[Creator : ]
Description
Now try to modify the algorithm to solve the following problem.
Given a string $t$ and $n$ queries, each query is a string $s_i$. For each request you need to count how many times the string $s_i$ occurs as a substring in $t$.
Input
The first line of input contains the string $t\ (1≤|t|≤300,000)$.
The second line contains an integer $n$, the number of queries $(1≤n≤300,000)$.
The following $n$ lines contain one non-empty line $s_i$ each. The sum of the lengths of all strings $s_i$ does not exceed $300,000$.
All strings consist of lowercase English letters.
Output
For each request print one integer, the number of times the string $s_i$ occurs as a substring in $t$.
Sample 1 Input
ababba
3
ba
baba
abba
Sample 1 Output
2
0
1
Sample 2 Input
itmouniversity
3
it
more
university
Sample 2 Output
2
0
1
Sample 3 Input
aaa
2
a
aa
Sample 3 Output
3
2