#include <bits/stdc++.h>
using namespace std;
void FastIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(15);
}
int main() {
  FastIO();
  int n, i, j, y, maxval = -1, ans = 0, var;
  vector<int> v;
  vector<int>::iterator it;
  set<int> s;
  set<int>::iterator it1;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> var;
    s.insert(var);
    maxval = max(maxval, var);
  }
  v.resize(s.size());
  it1 = s.begin();
  i = 0;
  while (it1 != s.end()) {
    v[i] = *it1;
    it1++;
    i++;
  }
  n = v.size();
  for (i = 0; i < n; i++) {
    for (j = 2;; j++) {
      it = lower_bound(v.begin(), v.end(), j * v[i]);
      if (it == v.begin()) {
        if (j * v[i] > maxval) break;
        continue;
      }
      it--;
      y = *it;
      if (y >= v[i]) ans = max(ans, y % v[i]);
      if (j * v[i] > maxval) break;
    }
  }
  cout << ans << "\n";
  return 0;
}

### Prompt

Please formulate 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;
void FastIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(15);
}
int main() {
  FastIO();
  int n, i, j, y, maxval = -1, ans = 0, var;
  vector<int> v;
  vector<int>::iterator it;
  set<int> s;
  set<int>::iterator it1;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> var;
    s.insert(var);
    maxval = max(maxval, var);
  }
  v.resize(s.size());
  it1 = s.begin();
  i = 0;
  while (it1 != s.end()) {
    v[i] = *it1;
    it1++;
    i++;
  }
  n = v.size();
  for (i = 0; i < n; i++) {
    for (j = 2;; j++) {
      it = lower_bound(v.begin(), v.end(), j * v[i]);
      if (it == v.begin()) {
        if (j * v[i] > maxval) break;
        continue;
      }
      it--;
      y = *it;
      if (y >= v[i]) ans = max(ans, y % v[i]);
      if (j * v[i] > maxval) break;
    }
  }
  cout << ans << "\n";
  return 0;
}

```