#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
int b[2000005];
int a[200005], n;
int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  int len = unique(a + 1, a + 1 + n) - a - 1;
  int MAX = a[len];
  for (int i = len; i >= 1; i--) {
    int he = a[i];
    for (int j = he + 1; j <= MAX * 2; j++)
      if (b[j] > he)
        break;
      else
        b[j] = he;
  }
  int ans = 0;
  for (int i = 1; i < len; i++) {
    int he = a[i];
    for (int j = 2; j * he <= MAX * 2; j++) {
      int oth = b[j * he];
      ans = max(ans, oth % he);
    }
  }
  printf("%d\n", ans);
  return 0;
}

### Prompt

Your task is to create a CPP solution to 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>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
int b[2000005];
int a[200005], n;
int main(void) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  int len = unique(a + 1, a + 1 + n) - a - 1;
  int MAX = a[len];
  for (int i = len; i >= 1; i--) {
    int he = a[i];
    for (int j = he + 1; j <= MAX * 2; j++)
      if (b[j] > he)
        break;
      else
        b[j] = he;
  }
  int ans = 0;
  for (int i = 1; i < len; i++) {
    int he = a[i];
    for (int j = 2; j * he <= MAX * 2; j++) {
      int oth = b[j * he];
      ans = max(ans, oth % he);
    }
  }
  printf("%d\n", ans);
  return 0;
}

```