#include <bits/stdc++.h>
using namespace std;
int a[200005];
int n, an = 1;
int index(int p) {
  int x1 = 0, x2 = n, x;
  while (x1 + 1 != x2) {
    x = (x1 + x2) / 2;
    if (a[x] > p)
      x2 = x;
    else
      x1 = x;
  }
  return x2;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  sort(a, a + n);
  int i;
  for (i = 1; i < n; i++)
    if (a[i] != a[an - 1]) a[an] = a[i], an++;
  if (an == 1) {
    cout << 0 << endl;
    return 0;
  }
  n = an;
  int m = 0;
  for (int i = n - 2; i >= 0 && a[i] > m + 1; i--) {
    m = max(m, a[index(2 * a[i] - 1) - 1] % a[i]);
    for (int j = index(2 * a[i] + m); j < n; j++) {
      m = max(m, a[j] % a[i]);
    }
  }
  cout << m << endl;
  return 0;
}

### Prompt

In cpp, your task is to solve 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[200005];
int n, an = 1;
int index(int p) {
  int x1 = 0, x2 = n, x;
  while (x1 + 1 != x2) {
    x = (x1 + x2) / 2;
    if (a[x] > p)
      x2 = x;
    else
      x1 = x;
  }
  return x2;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  sort(a, a + n);
  int i;
  for (i = 1; i < n; i++)
    if (a[i] != a[an - 1]) a[an] = a[i], an++;
  if (an == 1) {
    cout << 0 << endl;
    return 0;
  }
  n = an;
  int m = 0;
  for (int i = n - 2; i >= 0 && a[i] > m + 1; i--) {
    m = max(m, a[index(2 * a[i] - 1) - 1] % a[i]);
    for (int j = index(2 * a[i] + m); j < n; j++) {
      m = max(m, a[j] % a[i]);
    }
  }
  cout << m << endl;
  return 0;
}

```