#K56562. Find the Optimal Zeroing Value

    ID: 30226 Type: Default 1000ms 256MiB

Find the Optimal Zeroing Value

Find the Optimal Zeroing Value

You are given a sequence of n integers. Your task is to determine an integer \(y\) such that when you subtract \(y\) from every element in the sequence, the resulting sequence contains as many zeros as possible. In other words, find a \(y\) so that the count of indices \(i\) with \(b_i - y = 0\) is maximized.

This problem is equivalent to finding the mode of the sequence. If there are multiple candidates (i.e. several values that appear the maximum number of times), output the one that appears first in the sequence.

Input Format: The input is read from standard input. The first line contains a single integer \(n\) (the number of elements). The second line contains \(n\) space-separated integers representing the sequence.

Output Format: Output a single integer \(y\) on a line by itself, which is the optimal value.

Mathematical Formulation: Given a sequence \(a_1, a_2, \dots, a_n\), find \(y\) such that the number of indices \(i\) with \(a_i - y = 0\) is maximized. If there are ties, choose the value \(y\) corresponding to the first occurrence among those that attain the maximum frequency.

inputFormat

The input is given on two lines. The first line contains a single integer \(n\) (\(1 \le n \le 10^5\), for example), which represents the size of the sequence. The second line contains \(n\) space-separated integers \(a_1, a_2, \dots, a_n\), where each \(a_i\) is an integer.

outputFormat

Print a single integer \(y\) to the standard output which is the optimal value such that the sequence \(a_1 - y, a_2 - y, \dots, a_n - y\) contains as many zeros as possible.

## sample
1
5
5

</p>