#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
  out << "[";
  for (auto it = a.begin(); it != a.end(); ++it) {
    if (it != a.begin()) out << ", ";
    out << *it;
  }
  return out << "]";
}
mt19937 rnd(time(NULL));
mt19937_64 rnd64(time(NULL));
const int INF = 1e9;
const long long INF64 = 1e18;
const int MOD = 1e9 + 7;
const long double PI = acosl(-1.0);
const long double EPS = 1e-9;
const int N = 200 * 1000 + 11;
int n;
int a[N];
bool read() {
  if (scanf("%d", &n) != 1) return false;
  for (int i = 0; i < int(n); ++i) scanf("%d", &a[i]);
  return true;
}
void solve() {
  sort(a, a + n);
  n = unique(a, a + n) - a;
  int ans = 0;
  for (int i = 0; i < int(n); ++i) {
    for (int j = 2 * a[i]; j <= 2 * 1000 * 1000; j += a[i]) {
      int pos = lower_bound(a, a + n, j) - a - 1;
      if (pos < n) ans = max(ans, a[pos] % a[i]);
    }
  }
  printf("%d\n", ans);
}
int main() {
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  if (read()) {
    solve();
  }
}

### Prompt

Develop a solution in cpp to the problem described below:

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;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
  out << "[";
  for (auto it = a.begin(); it != a.end(); ++it) {
    if (it != a.begin()) out << ", ";
    out << *it;
  }
  return out << "]";
}
mt19937 rnd(time(NULL));
mt19937_64 rnd64(time(NULL));
const int INF = 1e9;
const long long INF64 = 1e18;
const int MOD = 1e9 + 7;
const long double PI = acosl(-1.0);
const long double EPS = 1e-9;
const int N = 200 * 1000 + 11;
int n;
int a[N];
bool read() {
  if (scanf("%d", &n) != 1) return false;
  for (int i = 0; i < int(n); ++i) scanf("%d", &a[i]);
  return true;
}
void solve() {
  sort(a, a + n);
  n = unique(a, a + n) - a;
  int ans = 0;
  for (int i = 0; i < int(n); ++i) {
    for (int j = 2 * a[i]; j <= 2 * 1000 * 1000; j += a[i]) {
      int pos = lower_bound(a, a + n, j) - a - 1;
      if (pos < n) ans = max(ans, a[pos] % a[i]);
    }
  }
  printf("%d\n", ans);
}
int main() {
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  if (read()) {
    solve();
  }
}

```