Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/ikkinchi-eng-katta

Second largest

Medium 1000 ms 64 MB 52%
Share

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$.

Finding the second largest element of an array

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

Sign in to submit a solution

Signing up is free and takes a minute.