P3796 AC Automaton (Simple Version II)
Description
There are $N$ pattern strings consisting of lowercase letters and a text string $T$. Each pattern may appear multiple times in the text. You need to find out **which** pattern strings appear the most times in the text $T$.
Input Format
The input contains multiple test cases. There are at most $50$ test cases.
The first line of each test case contains a positive integer $N$, indicating the number of pattern strings, where $1 \leq N \leq 150$.
The next $N$ lines each contain a pattern string of length at most $70$. The next line contains a text string $T$ of length at most $10^6$. It is guaranteed that there are no duplicate pattern strings.
The input ends with $N = 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.
Explanation/Hint
Translated by ChatGPT 5