Ever the innovator, Farmer John is teaching cows to speak some phrases in human language. He writes each new phrase the cows learn in his phrase book, a total of M (1 <= M <= 1,000) so far.
When Farmer John is on a vacation, he can only communicate with his cows by telephone. Being an active vacationer, FJ visits beaches and fine restaurants when away from the farm. When he returns, his answering machine is full of N (1 <= N <= 10,000) messages, many potentially from the cows.
FJ vacations frugally and thus gets poor telephone service. Many of the recorded messages cut off before they are complete. Help FJ determine whether the recorded messages are from the phrasebook by determining if the message begins a phrase.
You will be given the phrasebook and a set of texts of the recorded messages. Count the number of recorded messages that are the beginning (prefix) of a phrase from the phrase book.
Complete phrases are from 1 to 60 characters in length, each of which is either a letter (upper or lower case), a period (.), comma (,), question mark (?) or space. There are no leading spaces, trailing spaces, or double spaces in a phrase. Comparisons are case-sensitive, and a phrase is in fact, considered to be prefix of itself.