#C7772. Most Frequent Element Finder

    ID: 51680 Type: Default 1000ms 256MiB

Most Frequent Element Finder

Most Frequent Element Finder

You are given a list of integers. Your task is to identify the element that occurs most frequently in the list. In case there is a tie (i.e. multiple elements have the same maximum frequency), output the smallest of those elements.

Formally, let (f(x)) denote the number of times element (x) appears in the list. You need to find an integer (m) such that:

[ m = \min{ x \mid f(x) = \max_{y} f(y) }]

The input will be provided via standard input (stdin) and the answer should be printed to standard output (stdout).

inputFormat

The first line contains an integer (n) ((1 \leq n \leq 10^5)) representing the number of elements in the list. The second line contains (n) space-separated integers, which can be positive, negative, or zero.

outputFormat

Output a single integer: the most frequently occurring element in the list. In case of a tie, output the smallest element among those with the maximum frequency.## sample

7
1 3 2 2 4 1 1
1

</p>