#K1181. Most Frequent Element

    ID: 23551 Type: Default 1000ms 256MiB

Most Frequent Element

Most Frequent Element

You are given a list of integers. Your task is to determine the integer that appears most frequently in the list. In case there is a tie (i.e. multiple integers appear the same maximum number of times), output the smallest integer among them.

Let \(n\) be the number of integers, and let \(a_1, a_2, \ldots, a_n\) be the list. You need to compute the frequency of each integer and then find the integer \(x\) such that its frequency \(f(x)\) is maximum. If \(f(x) = f(y)\) for some \(x \neq y\), choose \(x\) if \(x < y\).

inputFormat

The first line contains a single integer \(n\) (\(1 \leq n \leq 10^5\)), denoting the number of integers in the list. The second line contains \(n\) space-separated integers. Each integer will be in the range of a typical 32-bit signed integer.

outputFormat

Output a single integer: the most frequent element in the list. If there is a tie, output the smallest integer among those with the highest frequency.

## sample
1
1
1