#include <bits/stdc++.h>
using namespace std;
int p[2000001], a[2000001], n, xmax, s;
int main() {
  cin >> n;
  int x, j;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    p[x] = 1;
    xmax = max(xmax, x);
  }
  int t = 0;
  for (int i = 1; i <= 2 * xmax; i++) {
    a[i] = t;
    if (p[i] == 1) t = i;
  }
  for (int i = 2; i <= xmax; i++)
    if (p[i] == 1) {
      j = 2 * i;
      while (j <= 2 * xmax) {
        if (a[j] > j - i) s = max(s, a[j] - (j - i));
        j = j + i;
      }
    }
  cout << s;
  return 0;
}

### Prompt

Please formulate a cpp solution to the following problem:

You are given a sequence a consisting of n integers. Find the maximum possible value of <image> (integer remainder of ai divided by aj), where 1 ≤ i, j ≤ n and ai ≥ aj.

Input

The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·105). 

The second line contains n space-separated integers ai (1 ≤ ai ≤ 106).

Output

Print the answer to the problem.

Examples

Input

3
3 4 5


Output

2

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int p[2000001], a[2000001], n, xmax, s;
int main() {
  cin >> n;
  int x, j;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    p[x] = 1;
    xmax = max(xmax, x);
  }
  int t = 0;
  for (int i = 1; i <= 2 * xmax; i++) {
    a[i] = t;
    if (p[i] == 1) t = i;
  }
  for (int i = 2; i <= xmax; i++)
    if (p[i] == 1) {
      j = 2 * i;
      while (j <= 2 * xmax) {
        if (a[j] > j - i) s = max(s, a[j] - (j - i));
        j = j + i;
      }
    }
  cout << s;
  return 0;
}

```