#K83897. Find the Mode

    ID: 36299 Type: Default 1000ms 256MiB

Find the Mode

Find the Mode

Given an array of n integers, your task is to determine the mode of the array. The mode is defined as the element that appears the most number of times. In case multiple elements have the same maximum frequency, output the smallest one among them. Formally, let \(A = [a_1, a_2, \ldots, a_n]\) be the array. Find an element \(m\) such that:

\(m = \min\{ x \mid \text{frequency}(x) = \max_{y \in A}\{\text{frequency}(y)\} \}\)

The input is provided via standard input and the output should be written to standard output.

inputFormat

The first line contains a single integer n (\(1 \leq n \leq 10^5\)), representing the number of elements in the array.

The second line contains n space-separated integers \(a_1, a_2, \ldots, a_n\), where each integer is in the range of \(-10^9\) to \(10^9\) (or other constraints as applicable).

outputFormat

Output a single integer which is the mode of the array. If there are multiple modes, output the smallest one.

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

</p>