~/algor $ cat problems/ikkinchi-eng-katta
Second largest
Medium
1000 ms
64 MB
52%
A positive integer $n$ and an array of $n$ integers are given. Find the second largest value of the array: equal values count as one (for example, in the array $5, 5, 3$ the second largest value is $3$). If the array has fewer than two distinct values, print $-1$.
Input
The first line contains a positive integer $n$. The second line contains $n$ integers separated by spaces.
Output
One integer — the second largest value or $-1$.
Note
$1 \le n \le 10^{5}$
$0 \le a_{i} \le 10^{9}$
Examples
Input #1
5 4 9 2 9 7
Output #1
7
Input #2
3 5 5 3
Output #2
3