#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 1;
int a[maxn];
int main() {
  int i, j, k;
  int n;
  int ans = 0;
  memset(a, 0, sizeof(a));
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &k);
    a[k] = k;
  }
  for (i = 2; i < maxn; ++i)
    if (a[i] == 0) a[i] = a[i - 1];
  for (i = 2; i <= 1000000; ++i) {
    if (a[i] == i) {
      for (j = i + i - 1; j < maxn; j += i) ans = max(ans, a[j] % 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;
const int maxn = 2e6 + 1;
int a[maxn];
int main() {
  int i, j, k;
  int n;
  int ans = 0;
  memset(a, 0, sizeof(a));
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &k);
    a[k] = k;
  }
  for (i = 2; i < maxn; ++i)
    if (a[i] == 0) a[i] = a[i - 1];
  for (i = 2; i <= 1000000; ++i) {
    if (a[i] == i) {
      for (j = i + i - 1; j < maxn; j += i) ans = max(ans, a[j] % i);
    }
  }
  printf("%d\n", ans);
  return 0;
}

```