#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O2")
#pragma GCC optimization("unroll-loops")
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int n;
  cin >> n;
  int arr[n];
  int ans = 0;
  int maxi = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    maxi = max(maxi, arr[i]);
  }
  sort(arr, arr + n);
  for (int i = 0; i < n; i++) {
    if (i && (arr[i] == arr[i - 1])) {
      continue;
    }
    int temp = 2 * arr[i];
    while (temp <= maxi + arr[i]) {
      int idx = lower_bound(arr, arr + n, temp) - arr;
      if (idx > 0) {
        ans = max(ans, arr[idx - 1] % arr[i]);
      }
      temp += arr[i];
    }
  }
  cout << ans << '\n';
}

### 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;
#pragma GCC target("avx2")
#pragma GCC optimization("O2")
#pragma GCC optimization("unroll-loops")
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int n;
  cin >> n;
  int arr[n];
  int ans = 0;
  int maxi = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    maxi = max(maxi, arr[i]);
  }
  sort(arr, arr + n);
  for (int i = 0; i < n; i++) {
    if (i && (arr[i] == arr[i - 1])) {
      continue;
    }
    int temp = 2 * arr[i];
    while (temp <= maxi + arr[i]) {
      int idx = lower_bound(arr, arr + n, temp) - arr;
      if (idx > 0) {
        ans = max(ans, arr[idx - 1] % arr[i]);
      }
      temp += arr[i];
    }
  }
  cout << ans << '\n';
}

```