#include <bits/stdc++.h>
using namespace std;
const int maxn = 200009;
const int maxl = 1000000;
int n, sol;
int A[maxn];
int D[maxn], d;
int B[2 * maxl + 9];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &A[i]);
  sort(A, A + n);
  for (int i = 0; i < n; i++) {
    if (A[i] == A[i + 1]) continue;
    D[d++] = A[i];
  }
  D[d] = 2 * maxl;
  for (int i = 1; i <= d; i++)
    for (int h = D[i - 1] + 1; h <= D[i]; h++) B[h] = D[i - 1];
  for (int i = 0; i < d; i++)
    for (int h = 2; D[i] * h <= 2 * maxl; h++)
      sol = max(sol, B[D[i] * h] % D[i]);
  printf("%d", sol);
}

### Prompt

Your challenge is to write 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>
using namespace std;
const int maxn = 200009;
const int maxl = 1000000;
int n, sol;
int A[maxn];
int D[maxn], d;
int B[2 * maxl + 9];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &A[i]);
  sort(A, A + n);
  for (int i = 0; i < n; i++) {
    if (A[i] == A[i + 1]) continue;
    D[d++] = A[i];
  }
  D[d] = 2 * maxl;
  for (int i = 1; i <= d; i++)
    for (int h = D[i - 1] + 1; h <= D[i]; h++) B[h] = D[i - 1];
  for (int i = 0; i < d; i++)
    for (int h = 2; D[i] * h <= 2 * maxl; h++)
      sol = max(sol, B[D[i] * h] % D[i]);
  printf("%d", sol);
}

```