#C5871. Most Frequent Elements

    ID: 49568 Type: Default 1000ms 256MiB

Most Frequent Elements

Most Frequent Elements

You are given an array of integers. Your task is to identify all the elements that occur most frequently in the array and output them in ascending order. Formally, if you denote the frequency of an element \( x \) by \( f(x) \), then you need to find all \( x \) for which \( f(x) = \max_{y} f(y) \). If the array is empty, output nothing.

Examples:

  • For array [1, 2, 2, 3, 3], the output should be 2 3.
  • For array [3, 1, 4, 1, 5, 9], the output should be 1.
  • For array [5, 1, 1, 3, 5, 3], since all three numbers appear twice, the output should be 1 3 5.

Use efficient methods to ensure your solution works even for larger input sizes.

inputFormat

The first line contains an integer \( n \) (where \( n \ge 0 \)), representing the number of elements in the array. If \( n > 0 \), the second line contains \( n \) space-separated integers which are the elements of the array.

outputFormat

Output the most frequent elements in ascending order, separated by a single space. If there are no elements, output nothing.

## sample
5
1 2 2 3 3
2 3