#include <bits/stdc++.h>
using namespace std;
int a[4000002], b[2000002];
int main() {
  int n, i, j, ans;
  scanf("%d", &n);
  int maxi = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    a[b[i]] = b[i];
    maxi = max(maxi, b[i]);
  }
  int y, z;
  y = j = 0;
  for (i = 1; i <= 2 * maxi; i++) {
    if (a[i]) b[j++] = i;
    z = a[i];
    a[i] = y;
    y = max(y, z);
  }
  int siz = j;
  ans = 0;
  for (i = 0; i < siz; i++) {
    for (j = 2 * b[i]; j <= 2 * maxi; j += b[i]) {
      if (a[j]) ans = max(ans, a[j] % b[i]);
    }
  }
  printf("%d\n", 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;
int a[4000002], b[2000002];
int main() {
  int n, i, j, ans;
  scanf("%d", &n);
  int maxi = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    a[b[i]] = b[i];
    maxi = max(maxi, b[i]);
  }
  int y, z;
  y = j = 0;
  for (i = 1; i <= 2 * maxi; i++) {
    if (a[i]) b[j++] = i;
    z = a[i];
    a[i] = y;
    y = max(y, z);
  }
  int siz = j;
  ans = 0;
  for (i = 0; i < siz; i++) {
    for (j = 2 * b[i]; j <= 2 * maxi; j += b[i]) {
      if (a[j]) ans = max(ans, a[j] % b[i]);
    }
  }
  printf("%d\n", ans);
  return 0;
}

```