RKS - RK Sorting


RK is a great code breaker. He knows any cipher in the world can be broken by frequency analysis. He intercepted an enemy message. The message consists of N numbers, smaller than or equal to C. RK 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 is equal, the number whoes value appears sooner in the input should appear sooner in the sorted sequence.
Help RK by creating a "frequency sorter".

Input

First line of input contains two integers, N (1 <= N <= 1000), length of message, and C (1 <= C <= 10^9), the number from task description. Next line contains N integers smaller than or equal to C, message itself.

Output

First and only line of output should contain N numbers, the sorted sequence.

Sample

Input
9 3
1 3 3 3 2 2 2 1 1

Output
1 1 1 3 3 3 2 2 2
Input
5 2
2 1 2 1 2

Output
2 2 2 1 1

hide comments
Manraj Singh: 2014-10-22 21:52:44

Taught me many features of STL. Great problem. :D

pandu ranga rao: 2014-07-12 10:48:33

Really STL rocks...... :)

krishna kumar: 2014-06-23 15:56:46

wrong ans at 8th case .... any cornor case ??
... help !!

SAGAR JAIN: 2014-05-26 19:53:19

What is the use of C?
I didn't use it and got AC.

P_Quantum: 2014-05-14 20:26:30

nice prblm..!!

AlcatraZ: 2014-04-11 22:56:44

Nice problem.. STL is awesome !!

|RAMSDEN|: 2014-03-20 18:05:41

easy but nice prob.
AC in one go :-)

Avinash: 2014-03-13 18:35:33

Cleverly crafted problem ! thanks !

Last edit: 2014-03-13 18:47:07
Aravindan Chandrasekaran: 2014-03-13 17:02:16

Nice problem , learnt a lot (Y)

Atul Aditya: 2014-03-06 14:51:34

@[blank]...my submission id is 11196002..
could u plz see to it why im getting WA after 9 runs :(
...thnku


Added by:BLANKRK
Date:2014-01-28
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64