题目描述
Problem Description
Alice has $n$ positive integers, numbered from $1$ to $n$, denoted as $a_1, a_2, \dots, a_n$.
Bob has just learned about the modulo operation and decides to practice with these $n$ numbers. He writes down all the values of
$$a_i \bmod a_j (1 \le i, j \le n \wedge i \neq j)$$
where $\bmod$ denotes the modulo operation.
Alice wants to know what the strictly second largest value is among all the results. After removing duplicates from the modulo results (i.e., keeping only one instance of each result value), the second largest value among the remaining numbers is called the strictly second largest value.
Input Format
The first line contains a positive integer $n$, representing the number of digits.
The second line contains $n$ positive integers representing $a_i$.
Output Format
A single line containing an integer representing the answer.
If there are fewer than two distinct numbers after removing duplicates, output $-1$.
Sample Input and Output
Sample Input #1
4
4 5 5 6
Sample Output #1
4
Sample Input #2
4
1 1 1 1
Sample Output #2
-1
Sample Input #3
7
12 3 8 5 7 20 15
Sample Output #3
12
Notes
Data Range
For $40\%$ of the data, $1 \le n, a_i \le 100$;
For $70\%$ of the data, $1 \le n \le 3000$, $1 \le a_i \le 10^5$;
For $100\%$ of the data, $3 \le n \le 2 \times 10^5$, $1 \le a_i \le 10^9$.
Sample #1 Explanation
All modulo results are $\{4, 4, 4, 1, 0, 5, 1, 0, 5, 2, 1, 1\}$.
After removing duplicates, we have: $\{0, 1, 2, 4, 5\}$, and the result is $4$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分