SORTOUT - Mahammad and strings


Professor Mahammad was busy with working their machine learning project in XYZ University. His team collected many data for the analysis of specific procedures. As the length of individual data objects were quite large, he used a popular hashing technique for getting a unique identifier for each data. Unfortunately, the hashing function generated similar result strings for data. As it is not suitable for the project, he started to think what to do with those strings. Suddenly, he came up with a new idea for a problem for beginners. Now he asks, for the given strings in each query, how many lexicographically smaller or equal strings exist in the input? 

Input

First line of the input contains two positive integers N and Q, respectively, the number of input strings and the number of queries.

The following N lines represent the strings generated from the procedure.

Finally, the next Q lines contain the query strings which you need to process.

The input section contains strings with only lowercase English letters.

Output

For each of the Q lines, you need to output the number of equal or lexicographically smaller strings.

Note: The sum of the lengths of the input and query strings does not exceed 200000, separately.

Example

Input:
4 3
fury
fuzzy
dizzy
future
fuzz
evil
freeze

Output:
3
1
1

hide comments
Simes: 2017-09-28 21:26:23

@soumith. try this
3 1
a
a
a
a
expected answer 3, your answer 1

soumith: 2017-09-27 12:32:35

@mahmud2690
I dont see any problem with my code. Im constantly getting WA . <snip>

Last edit: 2023-05-20 00:01:13
sas1905: 2017-09-27 12:10:05


re: you can see there are a few fast (0.04 sec) submissions, so your point is not right.

Last edit: 2017-09-28 17:24:51

Added by:mahmud2690
Date:2017-09-25
Time limit:0.100s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:Me, MYSELF & I