Hide

Problem B
Símanúmer

Languages en is

Kristín has been rising through the ranks at the Forensic department of the Reykjavík Police the last few years, mostly because of her computer science skills, and is one of the top dogs at the department. At her job she’s noticed that witnesses are really bad at remembering phone numbers. Most witnesses only remember the first few digits.

The phone numbers witnesses give the police are often the key to solving a case, but the system the police uses to go through the phone numbers isn’t particularly efficient. A group of policemen will go over all registered numbers and collects the ones that start with the digits that the witnesses told them.

Kristín, being a computer scientist, knows that the search can be made significantly more efficient, but is very busy and asks you to implement the search for her. The program should be able to take the prefix of a phone number from a witness and then answer how many numbers start with that prefix.

Input

The first line of the input contains an integer $N$ giving the number of phone numbers in the police records. The next $N$ lines contain the phone numbers in the records, one phone number per line. No two numbers will be the same and they each contain $7$ digits. The next line contains an integer $Q$ giving the number of queries. The next $Q$ lines contain the queries, one query per line. Each query consists of $1$ to $7$ digits.

Output

Print a single line for each query with the number of phone numbers in the records that start with that query.

Scoring

The solution will be tested on differently hard input data and the data is divided into groups as shown in the table below. The solution will then be scored according to how many groups are solved.

Group

Points

Constraints

1

5

$N=1$, $Q=1$, each query contains exactly $3$ digits

2

5

$N = 1$, $Q=1$

3

15

$N \leq 100$, $Q \leq 100$, each query contains exactly $3$ digits

4

20

$N \leq 100$, $Q \leq 100$

5

25

$N \leq 10^5$, $Q \leq 10^5$, each query contains exactly $3$ digits

6

30

$N \leq 10^5$, $Q \leq 10^5$

Sample Input 1 Sample Output 1
4
8245477
9917762
9871234
8247713
5
824
9
99177
8245477
565
2
2
1
1
0

Please log in to submit a solution to this problem

Log in