#include <bits/stdc++.h>
using namespace std;
long long nbr[10000007], ase[10000007];
int main() {
  long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, x, y, z, t, tc, flg,
      cnt, flg_2;
  long long inp[1000007], ans = -1000000007;
  memset(ase, 0, sizeof(ase));
  cin >> n;
  nbr[0] = 0;
  for (i = 1; i <= n; i++) scanf("%lld", &inp[i]), ase[inp[i]] = 1;
  sort(inp + 1, inp + 1 + n);
  long long mx = inp[n];
  for (i = 1; i <= mx + 1000; i++) {
    if (ase[i] == 1)
      x = i;
    else
      x = -1;
    if (nbr[i - 1] <= x)
      nbr[i] = x;
    else
      nbr[i] = nbr[i - 1];
  }
  inp[0] = -1;
  for (i = 1; i <= n; i++) {
    x = inp[i];
    if (x == inp[i - 1]) continue;
    for (j = x + x; j <= mx; j += x) ans = max(ans, nbr[j - 1] % x);
    ans = max(ans, nbr[mx] % x);
  }
  printf("%lld", ans);
  return 0;
}

### Prompt

Create a solution in CPP for 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;
long long nbr[10000007], ase[10000007];
int main() {
  long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, x, y, z, t, tc, flg,
      cnt, flg_2;
  long long inp[1000007], ans = -1000000007;
  memset(ase, 0, sizeof(ase));
  cin >> n;
  nbr[0] = 0;
  for (i = 1; i <= n; i++) scanf("%lld", &inp[i]), ase[inp[i]] = 1;
  sort(inp + 1, inp + 1 + n);
  long long mx = inp[n];
  for (i = 1; i <= mx + 1000; i++) {
    if (ase[i] == 1)
      x = i;
    else
      x = -1;
    if (nbr[i - 1] <= x)
      nbr[i] = x;
    else
      nbr[i] = nbr[i - 1];
  }
  inp[0] = -1;
  for (i = 1; i <= n; i++) {
    x = inp[i];
    if (x == inp[i - 1]) continue;
    for (j = x + x; j <= mx; j += x) ans = max(ans, nbr[j - 1] % x);
    ans = max(ans, nbr[mx] % x);
  }
  printf("%lld", ans);
  return 0;
}

```