898C.md (3029B)
1 Source: https://codeforces.com/problemset/problem/898/C 2 3 C. Phone Numbers 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. 22 23 Vasya decided to organize information about the phone numbers of friends. You will be given *n* strings — all entries from Vasya's phone books. Each entry starts with a friend's name. Then follows the number of phone numbers in the current entry, and then the phone numbers themselves. It is possible that several identical phones are recorded in the same record. 24 25 Vasya also believes that if the phone number *a* is a suffix of the phone number *b* (that is, the number *b* ends up with *a*), and both numbers are written by Vasya as the phone numbers of the same person, then *a* is recorded without the city code and it should not be taken into account. 26 27 The task is to print organized information about the phone numbers of Vasya's friends. It is possible that two different people have the same number. If one person has two numbers *x* and *y*, and *x* is a suffix of *y* (that is, *y* ends in *x*), then you shouldn't print number *x*. If the number of a friend in the Vasya's phone books is recorded several times in the same format, it is necessary to take it into account exactly once. 28 29 Read the examples to understand statement and format of the output better. 30 31 Input 32 33 First line contains the integer *n* (1 ≤ *n* ≤ 20) — number of entries in Vasya's phone books. 34 35 The following *n* lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English letters. Number of phone numbers in one entry is not less than 1 is not more than 10. The telephone numbers consist of digits only. If you represent a phone number as a string, then its length will be in range from 1 to 10. Phone numbers can contain leading zeros. 36 37 Output 38 39 Print out the ordered information about the phone numbers of Vasya's friends. First output *m* — number of friends that are found in Vasya's phone books. 40 41 The following *m* lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each record must contain all the phone numbers of current friend. 42 43 Entries can be displayed in arbitrary order, phone numbers for one record can also be printed in arbitrary order. 44 45 Examples 46 47 Input 48 49 ``` 50 2 51 ivan 1 00123 52 masha 1 00123 53 ``` 54 55 Output 56 57 ``` 58 2 59 masha 1 00123 60 ivan 1 00123 61 ``` 62 63 Input 64 65 ``` 66 3 67 karl 2 612 12 68 petr 1 12 69 katya 1 612 70 ``` 71 72 Output 73 74 ``` 75 3 76 katya 1 612 77 petr 1 12 78 karl 1 612 79 ``` 80 81 Input 82 83 ``` 84 4 85 ivan 3 123 123 456 86 ivan 2 456 456 87 ivan 8 789 3 23 6 56 9 89 2 88 dasha 2 23 789 89 ``` 90 91 Output 92 93 ``` 94 2 95 dasha 2 23 789 96 ivan 4 789 123 2 456 97 ```