#abc268h. Ex - Taboo

Ex - Taboo

Score : 600600 points

问题描述

给定一个字符串 SS。Takahashi 可以执行以下操作 00 次或多次:

  • 选择一个整数 ii,满足 1iS1 \leq i \leq |S|,并将 SS 的第 ii 个字符更改为 *

Takahashi 的目标是使 SS 不包含任何 NN 个字符串 T1,T2,,TNT_1,T_2,\ldots,T_N 作为子串。 求实现目标所需的最小操作次数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a string SS. Takahashi may perform the following operation 00 or more times:

  • Choose an integer ii such that 1iS1 \leq i \leq |S| and change the ii-th character of SS to *.

Takahashi's objective is to make SS not contain any of NN strings T1,T2,,TNT_1,T_2,\ldots,T_N as a substring.
Find the minimum number of operations required to achieve the objective.

Constraints

  • 1S5×1051 \leq |S| \leq 5 \times 10^5
  • 1N1 \leq N
  • NN is an integer.
  • 1Ti1 \leq |T_i|
  • Ti5×105\sum{|T_i|} \leq 5 \times 10^5
  • TiTjT_i \neq T_j if iji \neq j.
  • SS and TiT_i are strings consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

SS

NN

T1T_1

T2T_2

\vdots

TNT_N

Output

Print the answer.

Sample Input 1

abcdefghijklmn
3
abcd
ijk
ghi

Sample Output 1

2

If he performs the operation twice by choosing 11 and 99 for ii, SS becomes *bcdefgh*jklmn; now it does not contain abcd, ijk, or ghi as a substring.

Sample Input 2

atcoderbeginnercontest
1
abc

Sample Output 2

0

No operation is needed.

Sample Input 3

aaaaaaaaa
2
aa
xyz

Sample Output 3

4

update @ 2024/3/10 11:20:12