#P7259. [COCI 2009/2010 #3] SORT

[COCI 2009/2010 #3] SORT

Description

Mirko is a great code breaker. He knows that any code in the world can be cracked by frequency analysis.

But he completely misunderstood what frequency analysis is.

He intercepted an enemy message. The message consists of NN numbers, each not greater than CC.

Mirko believes that frequency analysis means sorting the sequence so that numbers with higher frequency come before numbers with lower frequency.

For any two numbers xx and yy, if the number of occurrences of xx in the original sequence is greater than the number of occurrences of yy, then xx should appear before yy. If the numbers of occurrences are equal, then whichever value appears earlier in the input should appear earlier in the sorted sequence.

Please help Mirko build a "frequency sorter".

Input Format

The first line contains two positive integers N,CN, C, as described in the statement.

The second line contains NN positive integers aia_i, representing the message.

Output Format

Output one line with NN positive integers, representing the sorted sequence.

5 2
2 1 2 1 2

2 2 2 1 1

9 3
1 3 3 3 2 2 2 1 1

1 1 1 3 3 3 2 2 2

9 77
11 33 11 77 54 11 25 25 33

11 11 11 33 33 25 25 77 54

Hint

Constraints

For 100%100\% of the testdata, 1N1031 \le N \le 10^3, 1C1091 \le C \le 10^9, and 1aiC1 \le a_i \le C.

Notes

Translated from COCI 2009-2010 #3 T3 SORT. Full score is 70 points. Each test case is worth 7 points, for a total of 10 test cases.

Translated by ChatGPT 5