COCI 2009/2010, Contest #3
Task SORT
Mirko is a great code breaker. He knows any cipher in the world can be broken by frequency analysis. However, his idea of what frequency analysis is completely wrong.
He intercepted an enemy message. The message consists of N numbers, smaller than or equal to C Mirko belives freqency analysis consists of sorting this sequence so that more frequent numbers appear before less frequent ones.
Formally, the sequence must be sorted so that given any two numbers X and Y, X appears before Y if the number of times X appears in the original sequence is larger than the number of time Y does. If the number of appearances are equal, the number whose value appears sooner in the input should appear sooner in the sorted sequence.
Help Mirko by creating a "frequency sorter".
Input
The first line of the input contains two integers, N (1 ≤ N ≤ 1 000), the length of the message, and C (1 ≤ C ≤ 1 000 000 000), the number from the task description.
The next line contains N integers smaller than or equal to C, the message itself.
Output
The first and only line of the output should contain N numbers, the sorted sequence.
Sample Tests
Input5 2 2 1 2 1 2 Output2 2 2 1 1 |
Input9 3 1 3 3 3 2 2 2 1 1 Output1 1 1 3 3 3 2 2 2 |
Input9 77 11 33 11 77 54 11 25 25 33 Output11 11 11 33 33 25 25 77 54 |
All Submissions
Best Solutions
Point Value: 7
Time Limit: 1.00s
Memory Limit: 32M
Added: Jul 04, 2013
Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
Comments (Search)
It's quiet in here...