#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
int n;
int A[maxn];
int B[maxm * 2];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", A + i);
  sort(A, A + n);
  n = unique(A, A + n) - A;
  for (int i = 0, j = A[0] + 1; i < n; i++) {
    while (j <= A[i + 1]) B[j++] = A[i];
  }
  for (int j = A[n - 1] + 1; j < maxm * 2; j++) B[j] = A[n - 1];
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 2; j * A[i] < 2 * maxm; j++) {
      int d = j * A[i];
      if (B[d] % A[i] > res) res = B[d] % A[i];
    }
  }
  printf("%d\n", res);
  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;
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
int n;
int A[maxn];
int B[maxm * 2];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", A + i);
  sort(A, A + n);
  n = unique(A, A + n) - A;
  for (int i = 0, j = A[0] + 1; i < n; i++) {
    while (j <= A[i + 1]) B[j++] = A[i];
  }
  for (int j = A[n - 1] + 1; j < maxm * 2; j++) B[j] = A[n - 1];
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 2; j * A[i] < 2 * maxm; j++) {
      int d = j * A[i];
      if (B[d] % A[i] > res) res = B[d] % A[i];
    }
  }
  printf("%d\n", res);
  return 0;
}

```