#include <bits/stdc++.h>
using namespace std;
int lg(long long n) {
  assert(n > 0);
  int ans = -1;
  while (n) {
    ans++;
    n >>= 1;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  a.resize(unique(a.begin(), a.end()) - a.begin());
  int ans = 0;
  for (int i = 0; i < (int)a.size(); i++) {
    for (int j = a[i]; j <= a.back(); j += a[i]) {
      int v = *(lower_bound(a.begin(), a.end(), j + a[i]) - 1);
      ans = max(ans, v - j);
    }
  }
  cout << ans << '\n';
  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;
int lg(long long n) {
  assert(n > 0);
  int ans = -1;
  while (n) {
    ans++;
    n >>= 1;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  a.resize(unique(a.begin(), a.end()) - a.begin());
  int ans = 0;
  for (int i = 0; i < (int)a.size(); i++) {
    for (int j = a[i]; j <= a.back(); j += a[i]) {
      int v = *(lower_bound(a.begin(), a.end(), j + a[i]) - 1);
      ans = max(ans, v - j);
    }
  }
  cout << ans << '\n';
  return 0;
}

```