#K3226. Most Frequent Price

    ID: 24912 Type: Default 1000ms 256MiB

Most Frequent Price

Most Frequent Price

You are given a list of price values. Your task is to determine the price that occurs most frequently. In the case of a tie (i.e., when multiple prices occur with the same maximum frequency), you should output the smallest price among them.

The problem can be formulated mathematically as follows:

Given a sequence \(a_1, a_2, \dots, a_n\), let \(f(x)\) denote the frequency of price \(x\). Then, find the value \(p\) such that

[ p = \min \left{ x \mid f(x) = \max_{y} f(y) \right}. ]

You must read the input from standard input (stdin) and write your answer to standard output (stdout).

inputFormat

The first line contains a single integer \(n\) (\(1 \leq n \leq 10^5\)) representing the number of price values.

The second line contains \(n\) integers separated by spaces, where each integer represents a price.

outputFormat

Output a single integer: the most frequently occurring price. If there is a tie, output the smallest price among those with the highest frequency.

## sample
1
10
10