#K59782. Most Visited Book
Most Visited Book
Most Visited Book
You are given a browsing history represented as a sequence of book IDs. Your task is to determine the book ID that has been visited the most times. In case of a tie (i.e., multiple books have the same maximum number of visits), return the smallest book ID.
The answer should be computed based on the following idea:
If we denote by \(f(x)\) the frequency of book \(x\), and let \(M = \max_{x} f(x)\), then among all book IDs \(x\) with \(f(x) = M\), output \(\min\{x : f(x)=M\}\).
Note: The input is given via standard input (stdin) and the output should be written to standard output (stdout).
inputFormat
The first line contains a single integer \(n\), the number of book visits.
The second line contains \(n\) space-separated integers representing the book IDs in the order they were visited.
Input is provided via standard input (stdin).
outputFormat
Output the book ID that has the maximum number of visits. In the case of a tie, output the smallest book ID among them. The result should be printed to standard output (stdout).
## sample1
1
1
</p>