Problems > Dictionary Match Count

Dictionary Match Count

Difficulty: 2200 6000 ms 128 MB

strings aho-corasick

Given a dictionary of P patterns and a text T, print the total number of pattern occurrences in T (each pattern counted every time it appears; duplicate patterns count each copy).

Input: the first line has P; the next P lines are the patterns; the following line is the text T.

Output: the total occurrence count.

Constraints:

  • 1 ≤ P ≤ 104
  • total pattern length ≤ 105
  • 1 ≤ |T| ≤ 105

Sample Tests

Input 1
2
ab
bc
abcbc
Output 1
3
Input 2
1
xy
abc
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.