#include <bits/stdc++.h>
using namespace std;
bool a[3000005];
int las[3000005];
int main() {
  int n;
  scanf("%d", &n);
  int maxc = -1;
  for (int i = 1; i <= n; i++) {
    int temp;
    scanf("%d", &temp);
    maxc = max(maxc, temp);
    a[temp] = 1;
  }
  int x = 0;
  for (int i = 1; i <= (maxc << 1); i++) {
    las[i] = x;
    if (a[i]) x = i;
  }
  int ans = 0;
  for (int i = 1; i <= (maxc); i++)
    if (a[i])
      for (int j = i; j <= (maxc << 1); j += i) {
        if (las[j] > i && (las[j] % i) > ans) ans = las[j] % i;
      }
  printf("%d\n", ans);
  return 0;
}

### Prompt

Please create a solution in Cpp 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>
using namespace std;
bool a[3000005];
int las[3000005];
int main() {
  int n;
  scanf("%d", &n);
  int maxc = -1;
  for (int i = 1; i <= n; i++) {
    int temp;
    scanf("%d", &temp);
    maxc = max(maxc, temp);
    a[temp] = 1;
  }
  int x = 0;
  for (int i = 1; i <= (maxc << 1); i++) {
    las[i] = x;
    if (a[i]) x = i;
  }
  int ans = 0;
  for (int i = 1; i <= (maxc); i++)
    if (a[i])
      for (int j = i; j <= (maxc << 1); j += i) {
        if (las[j] > i && (las[j] % i) > ans) ans = las[j] % i;
      }
  printf("%d\n", ans);
  return 0;
}

```