#K53487. Most Frequent Element Finder

    ID: 29542 Type: Default 1000ms 256MiB

Most Frequent Element Finder

Most Frequent Element Finder

You are given a list of integers. Your task is to find the element that occurs most frequently in the list. In the case where multiple elements have the same maximum frequency, you should return the smallest one.

Formally, if the frequency of an element a is denoted by \( f(a) \), then you need to find an integer \( x \) such that:

[ x = \min { a \mid f(a) = \max_{b} f(b) }]

Input Format: The first line contains an integer \( n \) representing the number of integers. The second line contains \( n \) space-separated integers.

Output Format: Print a single integer, the most frequent element (or the smallest one if there is a tie).

inputFormat

The input is read from standard input (stdin). The first line contains an integer \( n \) (the number of elements). The second line contains \( n \) space-separated integers.

outputFormat

The output is printed to standard output (stdout) and consists of a single integer: the most frequently occurring element. In case of a tie, the smallest element among those with the highest frequency is printed.

## sample
12
3 1 4 4 5 1 1 2 4 5 5 5
5