#C3459. Frequency Sorting Challenge
Frequency Sorting Challenge
Frequency Sorting Challenge
You are given an array of integers. Your task is to sort the array in ascending order based on the frequency of each element. If two numbers have the same frequency, then the smaller number should come first.
Formally, let \(f(a)\) denote the frequency of the number \(a\) in the array. Then for any two elements \(a\) and \(b\) in the array, \(a\) should appear before \(b\) if either \(f(a) < f(b)\) or \(f(a) = f(b)\) and \(a < b\).
inputFormat
The input consists of two lines:
- The first line contains an integer \(n\) which is the number of elements in the array.
- The second line contains \(n\) space-separated integers.
outputFormat
Output a single line containing the sorted array. The numbers must be separated by a single space.
## sample6
4 5 6 5 4 3
3 6 4 4 5 5