#P3808. AC 自动机(简单版)

AC 自动机(简单版)

Description

Given nn pattern strings sis_i and a text string tt, count how many distinct pattern strings appear in the text. Two pattern strings are different if and only if their indices are different.

Input Format

The first line contains an integer nn, the number of pattern strings.
Lines 22 to (n+1)(n + 1) each contain one string; the string on line (i+1)(i + 1) is the pattern string sis_i with index ii.
The last line contains a string, the text string tt.

Output Format

Output a single integer on one line, which is the answer.

3
a
aa
aa
aaa
3
4
a
ab
ac
abc
abcd
3
2
a
aa
aa
2

Hint

Sample 1 Explanation

s2s_2 and s3s_3 have different indices, so each contributes once to the answer.

Sample 2 Explanation

s1s_1, s2s_2, and s4s_4 all appear in the string abcd.

Constraints

  • For 10%10\% of the testdata, it is guaranteed that n=1n = 1.
  • For 100%100\% of the testdata, it is guaranteed that 1n1061 \leq n \leq 10^6, 1t1061 \leq |t| \leq 10^6, 1i=1nsi1061 \leq \sum\limits_{i = 1}^n |s_i| \leq 10^6. si,ts_i, t contain only lowercase letters.

Translated by ChatGPT 5