AmazonOA #344
Sort Error Codes by Frequency
估计简单可在线判题
Keep every element of the array, sorting first by total number of occurrences in ascending order and, for equal frequencies, by value in ascending order; duplicate values cannot be removed.
输入格式
The first line contains n and the second line contains n integers. The original statement only gives the sorting rule, with no value bounds; on this site 0≤n≤200000 and elements are in −10^9..10^9.
输出格式
Output the n integers in the required order, separated by spaces; when n=0, output an empty line.
样例 1
输入:
6
4 5 6 5 4 3
输出:
3 6 4 4 5 5
样例 2
输入:
6
2 2 1 1 1 3
输出:
3 2 2 1 1 1
样例 3
输入:
0
输出:
样例说明
The outputs of the three public examples are 3 6 4 4 5 5; 3 2 2 1 1 1; and an empty line, checked by independent enumeration or direct simulation.