#D7369. Operation of Frequency of Appearance
Operation of Frequency of Appearance
Operation of Frequency of Appearance
There is a frequency operation in the conversion operation of a finite number sequence. The conversion result of the sequence is a sequence of the same length. If the result is , then represents the number of in the sequence .
For example, if , then . Furthermore, if you perform a frequency operation on this sequence , you will get . This sequence does not change with the frequency operation. Such a sequence is called a fixed point of the sequence . It is known that the fixed point can be obtained by repeating the appearance frequency operation for any sequence.
The example below shows the procedure for frequency manipulation. Let the first row be the sequence , the second row be the sequence , and the last row be the sequence . Since there are 3 same numbers as the first element () of the sequence , the first element of the sequence is 3 and the same number as the next element (). Since there are two, , and so on, count the number and find .
Enter the sequence length and the sequence , and write a program that outputs the fixed point sequence and the minimum number of occurrence frequency operations performed to obtain . ..
Input
Given multiple datasets. Each dataset is given in the following format:
...
The first row is given the integer (), which represents the length of the sequence. In the second row, the integer () representing the elements of the sequence is given, separated by blanks.
Input ends with 0 single line. The number of datasets does not exceed 200.
Output
For each dataset, the minimum number of occurrence frequency operations (integer) in the first row, the sequence of fixed points corresponding to the second row element , , ..., separated by blanks.
Example
Input
10 4 5 1 1 4 5 12 3 5 4 0
Output
3 6 6 4 4 6 6 4 4 6 6
inputFormat
outputFormat
outputs the fixed point sequence and the minimum number of occurrence frequency operations performed to obtain . ..
Input
Given multiple datasets. Each dataset is given in the following format:
...
The first row is given the integer (), which represents the length of the sequence. In the second row, the integer () representing the elements of the sequence is given, separated by blanks.
Input ends with 0 single line. The number of datasets does not exceed 200.
Output
For each dataset, the minimum number of occurrence frequency operations (integer) in the first row, the sequence of fixed points corresponding to the second row element , , ..., separated by blanks.
Example
Input
10 4 5 1 1 4 5 12 3 5 4 0
Output
3 6 6 4 4 6 6 4 4 6 6
样例
10
4 5 1 1 4 5 12 3 5 4
0
3
6 6 4 4 6 6 4 4 6 6
</p>