#include <bits/stdc++.h>
using namespace std;
int pr[2000001];
int v[200001];
int va[200001];
int ind;
int maa;
int check(int ii) {
  int ma = 0;
  for (int j = 2 * ii; j <= 2000000; j += ii) {
    if (pr[j] > (j - ii)) ma = ((ma) > ((pr[j] % ii)) ? (ma) : ((pr[j] % ii)));
    if (pr[j] == maa) break;
  }
  return ma;
}
int main() {
  int n;
  cin >> n;
  int ma = 0;
  for (int i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    pr[tmp] = -1;
    ma = ((ma) > (tmp) ? (ma) : (tmp));
  }
  int prev = 0;
  maa = ma;
  for (int i = 1; i <= ((2 * ma) > (2000000) ? (2 * ma) : (2000000)); ++i) {
    if (pr[i] == -1) {
      va[ind++] = i;
      pr[i] = prev;
      prev = i;
    } else
      pr[i] = prev;
  }
  ma = 0;
  for (int i = 0; i < ind; ++i)
    ma = ((ma) > (check(va[i])) ? (ma) : (check(va[i])));
  cout << ma << endl;
}

### Prompt

Your challenge is to write 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 pr[2000001];
int v[200001];
int va[200001];
int ind;
int maa;
int check(int ii) {
  int ma = 0;
  for (int j = 2 * ii; j <= 2000000; j += ii) {
    if (pr[j] > (j - ii)) ma = ((ma) > ((pr[j] % ii)) ? (ma) : ((pr[j] % ii)));
    if (pr[j] == maa) break;
  }
  return ma;
}
int main() {
  int n;
  cin >> n;
  int ma = 0;
  for (int i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    pr[tmp] = -1;
    ma = ((ma) > (tmp) ? (ma) : (tmp));
  }
  int prev = 0;
  maa = ma;
  for (int i = 1; i <= ((2 * ma) > (2000000) ? (2 * ma) : (2000000)); ++i) {
    if (pr[i] == -1) {
      va[ind++] = i;
      pr[i] = prev;
      prev = i;
    } else
      pr[i] = prev;
  }
  ma = 0;
  for (int i = 0; i < ind; ++i)
    ma = ((ma) > (check(va[i])) ? (ma) : (check(va[i])));
  cout << ma << endl;
}

```