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
lakshya1st: 2020-09-03 15:01:36

AC in 1 go!!

robosapien: 2020-06-04 22:33:30

good stl problem...

vikas12: 2020-04-21 19:22:01

really good problem for learner

nadstratosfer: 2020-04-12 21:52:11

Yes, 915 users got AC by blind luck and your solution's mere 3.5GB memory usage could hardly be a reason to suspect there's anything wrong with it.

Last edit: 2020-04-12 21:52:29
az_09_18je0028: 2020-04-12 21:39:26

there is error in this question after 10 test_cases for c++ users....it gives wrong answer or TLE

piyushdaily: 2020-03-23 16:36:18

Good problem , learnt the use of comparator in sort function.... :-)

beginner: 2019-02-12 19:08:51

Nice problem statement ( adding c in problem :p )

mynk322: 2018-10-03 23:17:11

USE ARRAY, VECTOR, AND BRUTE FORCE!!!

sagar_zhcet: 2017-06-19 21:21:57

STL at its peak :)

vengatesh15: 2017-02-05 05:58:55

easy one AC in 1 go:-)


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