1388 -- Mobile Number
Time Limit :1000 MS Memory Limit :65536 KB
Accepts : 92 Submits : 334
User Accepts : 79 User Submits : 92
<Submit>   <Statistics>   <Discuss>

Description

One day, an alpc found a modified telephone booklet in our laboratory recording almost all alpcs’ mobile phone numbers.  Now he asks you to verify the numbers.
We call the number of different digitals at the same position of two phone numbers: ‘difference’.
Number   1: 1 3 6 0 0 0 0 0 0 0 0
Number   2: 1 4 6 0 0 0 0 0 0 0 1
Difference: 0+1+0+0+0+0+0+0+0+0+1 = 2
Search the booklet and find out the numbers between the difference A and B to the given correct phone numbers.

Input

The first line of the input is two integers: n and m. n is the numbers counted on the booklet, while m is the given correct phone numbers (0< n <= 1000, 0< m <= 200).
Then follow n lines. On each line is a phone number in the booklet which are all distinct. Then m lines, on each line there is a correct given phone number and difference A and B (0 <= A, B <= 11). Note: all the input phone numbers will be valid phone number: 11 digitals per number.
 

Output

For each given correct phone number, print “Number *:”(* should be replaced by the order this number shows up).
Then print all the within-difference number in the booklet. Ordered as the same as in the booklet.
Then follows a line printed “Total: *”, * should be replaced by the total number of the within-difference numbers.
Then print a blank line after each given correct phone number.
 

Sample Input

4 2
13600000000
13500000001
13700000001
15500000000
13600000000 1 1
13700000001 1 2

Sample Output

Number 1:
Total: 0
Number 2:
13600000000
13500000001
Total: 2

 

Source

Alpc NUDT campus contest 2009
<Submit>   <Statistics>   <Discuss>
 


Powered by Zhang Zhaoning PDL College of Computer
Since 2006.03.09 | 2007.11.22 | 2010.03.02 Copyright (r) 2006 - 2010 All Rights Reserved