#P1470. [IOI 1996 / USACO2.3] 最长前缀 Longest Prefix

[IOI 1996 / USACO2.3] 最长前缀 Longest Prefix

Description

In biology, the structures of some organisms are represented by sequences of uppercase letters that contain their components. Biologists are interested in breaking long sequences into shorter sequences (i.e., elements).

If the elements in a set PP can be concatenated (elements may be reused) to form a sequence SS, then we say that SS can be decomposed into elements from PP. Not all elements need to appear (for example, BBC does not appear below). For instance, the sequence ABABACABAAB can be decomposed into elements from the set {A, AB, BA, CA, BBC}.

The first kk characters of sequence SS are called the length-kk prefix of SS. Design a program that, given a set of elements and an uppercase-letter sequence, lets SS' be the longest prefix of SS that can be decomposed into elements from the given set PP, and computes the length kk of SS'.

Input Format

The input begins with a set PP consisting of several elements, given as a sequence of space-separated strings. All letters are uppercase, and the data may span multiple lines. The set ends with a line that contains only a single .. There are no duplicate elements in the set.

Then follows the uppercase-letter sequence SS, given as a string, with a newline after every 7676 characters.

Output Format

Output a single line containing one integer: the maximum length of a prefix of SS that satisfies the condition.

A AB BA CA BBC
.
ABABACABAABC

11

Hint

Constraints

For 100%100\% of the testdata, 1card(P)2001 \le \text{card}(P) \le 200, 1S2×1051 \le |S| \le 2 \times 10^5, and the length of each element in PP does not exceed 1010.

Translation from NOCOW.

Translated by ChatGPT 5