maximize-modulo

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

Source: hackerearth | Difficulty: EASY


Solutions: