#include <bits/stdc++.h>
using namespace std;
int n;
int s[2000010];
int a[200010];
int b[200010];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", b + i);
  sort(b, b + n);
  a[0] = b[0];
  int num = 1;
  for (int i = 0; i < n - 1; i++) {
    if (b[i + 1] != b[i]) {
      a[num] = b[i + 1];
      num++;
    }
  }
  int maxi = 0;
  int cont = 0;
  int mayor = 2 * a[num - 1] + 1;
  s[0] = -1;
  for (int i = 1; i < mayor; i++) {
    if (i != a[cont] + 1)
      s[i] = s[i - 1];
    else {
      s[i] = cont;
      cont++;
    }
  }
  for (int i = 0; i < num - 1; i++) {
    for (int j = 2 * a[i]; j < mayor; j += a[i]) {
      if (s[j] < i) continue;
      int r = (a[s[j]] % a[i]);
      maxi = max(maxi, r);
    }
  }
  cout << maxi << endl;
  return 0;
}

### Prompt

Your task is to create 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 n;
int s[2000010];
int a[200010];
int b[200010];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", b + i);
  sort(b, b + n);
  a[0] = b[0];
  int num = 1;
  for (int i = 0; i < n - 1; i++) {
    if (b[i + 1] != b[i]) {
      a[num] = b[i + 1];
      num++;
    }
  }
  int maxi = 0;
  int cont = 0;
  int mayor = 2 * a[num - 1] + 1;
  s[0] = -1;
  for (int i = 1; i < mayor; i++) {
    if (i != a[cont] + 1)
      s[i] = s[i - 1];
    else {
      s[i] = cont;
      cont++;
    }
  }
  for (int i = 0; i < num - 1; i++) {
    for (int j = 2 * a[i]; j < mayor; j += a[i]) {
      if (s[j] < i) continue;
      int r = (a[s[j]] % a[i]);
      maxi = max(maxi, r);
    }
  }
  cout << maxi << endl;
  return 0;
}

```