#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int maxModValue(int arr[], int n) {
  int ans = 0;
  sort(arr, arr + n);
  for (int i = n - 2; i >= 0; --i) {
    if (ans >= arr[i] - 1) break;
    if (arr[i] == arr[i + 1]) continue;
    for (int j = 2 * arr[i]; j - arr[i] <= arr[n - 1]; j += arr[i]) {
      int ind = lower_bound(arr, arr + n, j) - arr;
      ans = max(ans, arr[ind - 1] % arr[i]);
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  int arr[n + 1];
  for (int i = 0; i < n; ++i) cin >> arr[i];
  cout << maxModValue(arr, n);
}

### Prompt

Please create a solution in CPP 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;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int maxModValue(int arr[], int n) {
  int ans = 0;
  sort(arr, arr + n);
  for (int i = n - 2; i >= 0; --i) {
    if (ans >= arr[i] - 1) break;
    if (arr[i] == arr[i + 1]) continue;
    for (int j = 2 * arr[i]; j - arr[i] <= arr[n - 1]; j += arr[i]) {
      int ind = lower_bound(arr, arr + n, j) - arr;
      ans = max(ans, arr[ind - 1] % arr[i]);
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  int arr[n + 1];
  for (int i = 0; i < n; ++i) cin >> arr[i];
  cout << maxModValue(arr, n);
}

```