#P3796. AC 自动机(简单版 II)

    ID: 2736 远端评测题 3000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>字符串概率论,统计字典树,Trie 树AC 自动机构造

AC 自动机(简单版 II)

Description

There are NN pattern strings consisting of lowercase letters and a text string TT. Each pattern may appear multiple times in the text. You need to find out which pattern strings appear the most times in the text TT.

Input Format

The input contains multiple test cases. There are at most 5050 test cases. The first line of each test case contains a positive integer NN, indicating the number of pattern strings, where 1N1501 \leq N \leq 150. The next NN lines each contain a pattern string of length at most 7070. The next line contains a text string TT of length at most 10610^6. It is guaranteed that there are no duplicate pattern strings. The input ends with N=0N = 0.

Output Format

For each test case, output on the first line the maximum number of occurrences among all pattern strings. Then output several lines, each containing one pattern string that achieves this maximum, in the same order as in the input.

2
aba
bab
ababababac
6
beta
alpha
haha
delta
dede
tata
dedeltalphahahahototatalpha
0
4
aba
2
alpha
haha

Hint

Translated by ChatGPT 5