题目描述
You are given a array A of size N. Lets see if you can find the maximum value of Ai % Aj such that Aj ≤ Ai and 1 ≤ i,j ≤ N.
Input
The first line contains integer N — the length of the sequence.
The second line contains N space-separated integers Ai
Output
Print the answer to the problem in one line
Constrains
1 ≤ N ≤ 5*10^5
1 ≤ ai ≤ 10^6
SAMPLE INPUT
3
3 4 5
SAMPLE OUTPUT
2
输入格式
见题面
输出格式
见题面
样例输入
1
1
样例输出
0