#K57047. Most Frequent Product

    ID: 30333 Type: Default 1000ms 256MiB

Most Frequent Product

Most Frequent Product

You are given a list of product IDs. Your task is to determine the product ID that appears most frequently in the list. In the event that multiple product IDs have the same highest frequency, you must output the smallest product ID. Formally, given an integer nn and a sequence of product IDs a1,a2,,ana_1, a_2, \ldots, a_n, find an integer pp such that the frequency of pp is maximized. If there exists another product qq with the same frequency and q<pq < p, then output qq.

inputFormat

The first line of input contains an integer nn, representing the number of product IDs. The second line contains nn space-separated integers, each representing a product ID.

outputFormat

Output a single integer — the product ID that appears most frequently. If there are multiple such IDs, output the smallest one.## sample

7
4 4 1 2 2 4 1
4