#K83547. Most Frequent Item

    ID: 36221 Type: Default 1000ms 256MiB

Most Frequent Item

Most Frequent Item

You are given a list of integers. Your task is to find the integer that appears most frequently. If there are multiple integers with the same highest frequency, output the smallest one among them.

The input is received from the standard input (stdin) and the output should be printed to the standard output (stdout).

Hint: Use a method that counts the frequency of each element and then determines the element with the highest count. In case of a tie, select the smallest integer.

The problem can be mathematically stated as:

Let \( A = \{a_1, a_2, \dots, a_N\} \) be the sequence of integers. Define the frequency of an element \( x \) as \( f(x) = \#\{ i : a_i = x \} \). Your goal is to find an integer \( m \) such that \[ m = \min\{ x \mid f(x) = \max_{y \in A} f(y) \}\,. \]

inputFormat

The first line contains a single integer \( N \) --- the number of integers in the list.

The second line contains \( N \) space-separated integers representing the list.

Example:

7
1 2 2 3 3 3 4

outputFormat

Output a single integer --- the most frequently occurring number. In case of a tie, output the smallest one among those with the highest frequency.

Example:

3
## sample
7
1 2 2 3 3 3 4
3

</p>