#include <bits/stdc++.h>
using namespace std;
long long int find(long long int a[], long long int aj, long long int l,
                   long long int n) {
  long long int ans;
  ans = *(lower_bound(a, a + n, aj + a[l]) - 1);
  return ans;
}
void solve() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  long long int mx = a[n - 1];
  long long int ans = 0, sol;
  for (long long int i = 0; i < n - 1; i++) {
    if (a[i] == a[i + 1]) continue;
    for (long long int j = a[i]; j < mx; j += a[i]) {
      sol = find(a, j, i, n);
      ans = max(ans, sol - j);
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  solve();
  return 0;
}

### Prompt

Please provide a CPP coded solution 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;
long long int find(long long int a[], long long int aj, long long int l,
                   long long int n) {
  long long int ans;
  ans = *(lower_bound(a, a + n, aj + a[l]) - 1);
  return ans;
}
void solve() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  long long int mx = a[n - 1];
  long long int ans = 0, sol;
  for (long long int i = 0; i < n - 1; i++) {
    if (a[i] == a[i + 1]) continue;
    for (long long int j = a[i]; j < mx; j += a[i]) {
      sol = find(a, j, i, n);
      ans = max(ans, sol - j);
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  solve();
  return 0;
}

```