#K57047. Most Frequent Product
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 and a sequence of product IDs , find an integer such that the frequency of is maximized. If there exists another product with the same frequency and , then output .
inputFormat
The first line of input contains an integer , representing the number of product IDs. The second line contains 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