Question
Frequency-Based Sorting

Mia is organizing a list of items represented by an array of numbers. She wants to sort the list by arranging items that appear most frequently first, in ascending order of frequency. If two items appear the same number of times, she places the larger item first. Can you help Mia organize her list according to these rules?

Input
The first line of the input contains a single integer N, denoting the size of items.
The second line of the input contains N space-separated integers, denoting an array nums.

Constraints
1 ≤ N ≤ 100
-100 ≤ nums[i] ≤ 100
Output
Print the final sorted array according to rules.
Example
Sample Input
6
1 1 2 2 2 3
Sample Output
3 1 1 2 2 2
Explanation
'3' has a frequency of 1, '1' has a frequency of 2, and '2' has a frequency of 3.

Online