Finding Prefixes
InterviewTime limit1sMemory limit1536 MB
Given a set of N strings, count how many of M query strings appear as a prefix of at least one string in the set.
Problem
A prefix of a string is a substring that starts at the very beginning of . For example, the prefixes of = "codeplus" include "code", "co", "codepl", and "codeplus", while "plus", "s", "cude", and "crud" are not prefixes.
You are given a set of strings.
Write a program that counts how many of the given strings are a prefix of at least one string in the set .
Input
The first line contains the numbers of strings and (, ).
Each of the next lines contains one string of the set .
Each of the next lines contains one string to check.
Every string in the input consists only of lowercase English letters, and its length does not exceed 500. The set never contains the same string twice.
Output
Print on the first line the number of the strings that are a prefix of at least one string in the set .