#K71742. Most Frequent Widget Type

    ID: 33599 Type: Default 1000ms 256MiB

Most Frequent Widget Type

Most Frequent Widget Type

You are given a log of widget production entries, each represented by an integer type identifier. Your task is to determine the most frequently produced widget type. In the event of a tie (i.e. multiple widget types occur the same maximum number of times), you must output the smallest widget type identifier.

Implement a program that reads from standard input and writes the correct widget type to standard output. The solution should be optimized for speed, as the number of log entries can be large.

inputFormat

Input is given via standard input (stdin). The input consists of two lines. The first line contains a single integer n (1 ≤ n ≤ 105), representing the number of log entries. The second line contains n integers separated by spaces, where each integer indicates a widget type identifier.

outputFormat

Output a single integer to standard output (stdout), which is the most frequent widget type identifier. In case of a tie, output the smallest identifier among those with the maximum frequency.## sample

10
1 2 2 3 3 3 4 4 4 4
4