~/algor $ cat problems/saralash-chastota-boyicha
Sort by frequency
Medium
1000 ms
128 MB
58%
$n$ integers are given. Arrange them so that more frequent values come first; among values occurring the same number of times, the smaller one comes first. Each value is printed consecutively as many times as it occurs.
Input
The first line contains a positive integer $n$. The second line contains $n$ integers $a_{i}$ separated by spaces.
Output
One line with $n$ integers separated by spaces.
Note
$1 \le n \le 2 * 10^{5}$
$-10^{9} \le a_{i} \le 10^{9}$
Examples
Input #1
9 4 6 2 6 4 4 2 9 6
Output #1
4 4 4 6 6 6 2 2 9
Input #2
3 5 -1 5
Output #2
5 5 -1