#P7259. Frequency Sorter
Frequency Sorter
Frequency Sorter
Mirko is a renowned cryptanalyst who mistakenly believes that frequency analysis involves sorting a sequence of numbers based on their frequency in the input. He intercepted a message containing (N) numbers, each less than or equal to (C). Your task is to help Mirko by sorting the sequence such that numbers with higher frequency appear before those with lower frequency. For any two numbers (x) and (y), if (x) occurs more frequently than (y) in the original sequence, then (x) should appear before (y) in the sorted sequence. In case of a tie (i.e. both numbers occur equally often), the number that appears first in the original input should come first in the sorted output.
inputFormat
The first line contains two integers (N) and (C), where (N) is the number of elements in the sequence and (C) is the maximum possible value. The second line contains (N) integers separated by spaces.
outputFormat
Output the sorted sequence in one line. Each number should be separated by a space.
sample
5 10
3 3 2 2 2
2 2 2 3 3