#P5357. 【模板】AC 自动机

【模板】AC 自动机

Description

You are given a text string SS and nn pattern strings T1nT_{1 \sim n}. Please find, for each pattern string TiT_i, the number of times it appears in SS.

Input Format

The first line contains a positive integer nn, representing the number of pattern strings.

The next nn lines each contain a non-empty string TiT_i consisting of lowercase English letters, where the ii-th line corresponds to TiT_i.

The last line contains a non-empty string SS consisting of lowercase English letters.

The testdata does not guarantee that any two pattern strings are different.

Output Format

Output nn lines. The ii-th line contains a non-negative integer, representing the number of times TiT_i appears in SS.

5
a
bb
aa
abaa
abaaa
abaaabaa

6
0
3
2
1

Hint

For 100%100\% of the data, 1n2×1051 \le n \le 2 \times {10}^5, the total length of T1nT_{1 \sim n} is at most 2×1052 \times {10}^5, and the length of SS is at most 2×1062 \times {10}^6.

Translated by ChatGPT 5