Under construction

Still being built. Things may change

Finding Prefixes

Interview

Time limit1sMemory limit1536 MB

Summary
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.
Level

Medium5 of 10

Topics
Trie, String
Solved
No attempts yet

Problem

A prefix of a string SS is a substring that starts at the very beginning of SS. For example, the prefixes of SS = "codeplus" include "code", "co", "codepl", and "codeplus", while "plus", "s", "cude", and "crud" are not prefixes.

You are given a set SS of NN strings.

Write a program that counts how many of the MM given strings are a prefix of at least one string in the set SS.

Input

The first line contains the numbers of strings NN and MM (1≤N≤10,0001 \le N \le 10{,}000, 1≤M≤10,0001 \le M \le 10{,}000).

Each of the next NN lines contains one string of the set SS.

Each of the next MM 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 SS never contains the same string twice.

Output

Print on the first line the number of the MM strings that are a prefix of at least one string in the set SS.

Examples1

  1. Example 1

    Input
    5 10
    algoonlinejudge
    starlight
    codeplus
    sundaycoding
    codingsh
    algo
    star
    starl
    code
    sunday
    coding
    cod
    online
    judge
    plus
    
    Expected output
    7