#C7685. Most Frequent Stamp
Most Frequent Stamp
Most Frequent Stamp
You are given a collection of stamps represented by integers. Your task is to determine which stamp appears most frequently. In the event of a tie, the stamp that appears first in the collection should be chosen.
Note: If there is a tie, the answer is the stamp with the smallest index in the collection. The solution should read input from stdin
and print the result to stdout
.
The problem can be formulated as finding the value s such that:
\( \max_{s \in \text{stamps}} \text{frequency}(s) \) is maximized, and in case of ties, the stamp with the smallest index is returned.
inputFormat
The input is given via standard input and consists of two lines:
- The first line contains an integer \( n \) (\(1 \le n \le 10^5\)), representing the number of stamps.
- The second line contains \( n \) space-separated integers representing the stamp identifiers.
outputFormat
Output a single integer — the identifier of the most frequent stamp. If there are multiple stamps with the same highest frequency, output the one that appears first in the input list.
## sample7
5 3 1 3 2 1 3
3