#C6003. Most Frequent Element Finder
Most Frequent Element Finder
Most Frequent Element Finder
Given a list of integers, your task is to determine the most frequent element in the list. In case there is more than one such element, output the smallest one among them.
You should implement a solution that reads from standard input (stdin) and writes the answer to standard output (stdout).
Formally, given a list of integers \(a_1, a_2, \dots, a_n\), find an integer \(x\) such that its frequency \(f(x) = |\{ i \mid a_i = x \}|\) is maximized. In the event of a tie, choose \(x = \min\{ y \mid f(y) = \max_{z} f(z) \}\).
inputFormat
The first line contains a single 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 are the elements of the list.
outputFormat
Output a single integer: the most frequent element. If multiple elements have the same maximum frequency, output the smallest one among them.
## sample7
1 3 2 3 2 1 1
1