{A, AB, BA, CA, BBC}.
The first K characters of S are the prefix of S with length K. Write a program which accepts as input a set of primitives P and a sequence of constituents T. The program must compute the length of the longest prefix, that can be composed from primitives in P.
The input data appear in two files. The file INPUT.TXT describes the set of primitives P, while the file DATA.TXT contains the sequence T to be examined. The first line of INPUT.TXT contains N, the number of primitives in P (1<=N<=100). Each primitive is given in two consecutive lines. The first line contains the length L of the primitive (1<=L<=20). In the second line there is a string of uppercase letters (from 'A' to 'Z') of length L. The N primitives are all different.
Each line of the file DATA.TXT contains one uppercase letter in the first position. This file ends with a line containing a single period ('.').
The length of the sequence is at least 1 and at most 500,000.
Write into the first line of file OUTPUT.TXT the length of the longest prefix of T that can be composed from the set P.
Figure 2 gives two input files and a corresponding output file.
INPUT.TXT DATA.TXT OUTPUT.TXT 5 A 11 1 B A A 2 B AB A 3 C BBC A 2 B CA A 2 A BA B C B .