onu
There are n journalists in a hotel in the UN controlled zone, and they are identified by numbers 1, 2, ..., n.
When checking in at the hotel each journalist receives an ID card with a code on it (a positive integer of no more than 10 digits).
The governor of the region wants to go visit the surroundings. Because the number of journalists that want to go with him is too big he decides to draft up a list with groups of journalists in the hotel and he would pick one of them (to his liking). He makes up these group of journalists depending on a non-zero digit k. The following rules are respected for forming the groups:
a) All groups contain the same number of journalists (let's write it down as h).
b) If the journalists of a group have identification numbers x1, x2, ..., xh, (x1< x2< ...<xh) then any two codes ci , ci+1 corresponding to identification numbers xi, xi+1 (1<=i<h) have the property that the sequence comprised of the last k digits of ci coincides with the sequence of the first k digits in ci+1.
c) The number of h journalists
in a group is selected so that it be the maximum while meeting property b).
Tasks
Write a program that determines all the groups of journalists that meet above conditions.
Input Data
Input file onu.in contains on the first line two positive integers n and k separated by a space, and on the second line the journalists' codes in ascending ID number order 1, 2, …, n, each separated by a space.
Output Data
Output file onu.out will contain on the first line the number G representing the number of groups that meet task properties and each of the following G lines will contain a group of journalists. Journalists in a group will be written in ascending ID number order. Groups will be written in the file in ascending order.
Constraints and Statements
onu.in | onu.out | Explanation |
8
2 823 25 110 80 231 1011 31 110 |
2 |
Solution 1 5 7 corresponds to codes 823 231 31. |
Time limit: 2 seconds/test
prof. Doru Popescu Anastasiu
"Radu Greceanu" Slatina National High School
Contact:dopopan@yahoo.com