#include <bits/stdc++.h>
using namespace std;
const int M = 2e6;
int n, x, ans, a[M + 5];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a[x] = x;
  }
  for (int i = 2; i <= M; i++) {
    if (!a[i]) {
      a[i] = a[i - 1];
    }
  }
  for (int i = 2; i <= M / 2; i++) {
    if (a[i] == i) {
      for (int j = 2 * i - 1; j <= M; j += i) {
        ans = max(ans, a[j] % a[i]);
      }
    }
  }
  cout << ans;
}

### 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;
const int M = 2e6;
int n, x, ans, a[M + 5];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a[x] = x;
  }
  for (int i = 2; i <= M; i++) {
    if (!a[i]) {
      a[i] = a[i - 1];
    }
  }
  for (int i = 2; i <= M / 2; i++) {
    if (a[i] == i) {
      for (int j = 2 * i - 1; j <= M; j += i) {
        ans = max(ans, a[j] % a[i]);
      }
    }
  }
  cout << ans;
}

```