#include <bits/stdc++.h>
using namespace std;
int a[200010], n, res;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (i && a[i] == a[i - 1]) continue;
    int now = 2 * a[i];
    int r = a[i] * (1 + a[n - 1] / a[i]);
    int prv = i;
    while (prv < n) {
      int pos = (lower_bound(a + prv, a + n, now) - a);
      if (pos <= n) res = max(res, a[pos - 1] % a[i]);
      prv = pos;
      now = a[i] * (1 + a[pos] / a[i]);
    }
  }
  cout << res << endl;
  return 0;
}

### Prompt

Create a solution in cpp for 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;
int a[200010], n, res;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (i && a[i] == a[i - 1]) continue;
    int now = 2 * a[i];
    int r = a[i] * (1 + a[n - 1] / a[i]);
    int prv = i;
    while (prv < n) {
      int pos = (lower_bound(a + prv, a + n, now) - a);
      if (pos <= n) res = max(res, a[pos - 1] % a[i]);
      prv = pos;
      now = a[i] * (1 + a[pos] / a[i]);
    }
  }
  cout << res << endl;
  return 0;
}

```