#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int M = 1e6 + 10;
int n, a[N], f[M], xx, tot, ans;
int max_(int x, int y) { return x > y ? x : y; }
int ask(int x) {
  int sum = 0, t = x;
  while (t < M) {
    t += x;
    int k = lower_bound(a + 1, a + tot + 1, t) - a;
    if (!k) continue;
    if (a[--k] <= x) continue;
    sum = max_(sum, a[k] % x);
  }
  return sum;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &xx), f[xx] = 1;
  for (int i = 1; i < M; i++)
    if (f[i]) a[++tot] = i;
  for (int i = tot; i >= 1; i--) {
    if (ans >= a[i] - 1) break;
    ans = max_(ans, ask(a[i]));
  }
  printf("%d", ans);
  return 0;
}

### Prompt

Please provide a cpp coded solution to the problem described below:

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 N = 2e5 + 10;
const int M = 1e6 + 10;
int n, a[N], f[M], xx, tot, ans;
int max_(int x, int y) { return x > y ? x : y; }
int ask(int x) {
  int sum = 0, t = x;
  while (t < M) {
    t += x;
    int k = lower_bound(a + 1, a + tot + 1, t) - a;
    if (!k) continue;
    if (a[--k] <= x) continue;
    sum = max_(sum, a[k] % x);
  }
  return sum;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &xx), f[xx] = 1;
  for (int i = 1; i < M; i++)
    if (f[i]) a[++tot] = i;
  for (int i = tot; i >= 1; i--) {
    if (ans >= a[i] - 1) break;
    ans = max_(ans, ask(a[i]));
  }
  printf("%d", ans);
  return 0;
}

```