#C10639. Frequency Sort
Frequency Sort
Frequency Sort
You are given an integer \( n \) and an array of \( n \) integers. Your task is to sort the array based on the frequency of each element in ascending order. That is, the element with the lowest frequency should come first. If two elements have the same frequency, the smaller number should come before the larger one.
Formally, let \( f(x) \) denote the frequency of the integer \( x \) in the array. Then, for any two elements \( a \) and \( b \), \( a \) should appear before \( b \) if \[ f(a) < f(b) \quad \text{or} \quad (f(a) = f(b) \text{ and } a < b). \]
You need to read the input from standard input (stdin) and output the sorted array to standard output (stdout) as a sequence of integers separated by a single space.
inputFormat
The first line contains an integer \( n \), representing the number of elements in the array. The second line contains \( n \) integers separated by spaces.
outputFormat
Output the sorted array in one line. The numbers should be separated by a single space.
## sample5
4 5 6 5 4
6 4 4 5 5