#include <bits/stdc++.h>
using namespace std;
long long int x, y;
long long int gcd(long long int a, long long int b) {
  if (a == 0) {
    x = 0, y = 1;
    return b;
  }
  long long int gc = gcd(b % a, a);
  long long int temp;
  temp = x;
  x = y - (b / a) * temp;
  y = temp;
  return gc;
}
int visited[1000005];
int a[1000005];
int val[2 * 1000005];
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n;
  int i;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    val[a[i] + 1] = a[i];
  }
  for (i = 1; i < (2 * 1000005); i++) {
    val[i] = max(val[i], val[i - 1]);
  }
  int ans = 0;
  for (i = 0; i < n; i++) {
    if (!visited[a[i]]) {
      visited[a[i]] = 1;
      for (int j = a[i] * 2; j <= 2 * 1000005; j += a[i]) {
        ans = max(ans, val[j] % a[i]);
      }
    }
  }
  cout << ans << endl;
}

### Prompt

Create a solution in Cpp for 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;
long long int x, y;
long long int gcd(long long int a, long long int b) {
  if (a == 0) {
    x = 0, y = 1;
    return b;
  }
  long long int gc = gcd(b % a, a);
  long long int temp;
  temp = x;
  x = y - (b / a) * temp;
  y = temp;
  return gc;
}
int visited[1000005];
int a[1000005];
int val[2 * 1000005];
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n;
  int i;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    val[a[i] + 1] = a[i];
  }
  for (i = 1; i < (2 * 1000005); i++) {
    val[i] = max(val[i], val[i - 1]);
  }
  int ans = 0;
  for (i = 0; i < n; i++) {
    if (!visited[a[i]]) {
      visited[a[i]] = 1;
      for (int j = a[i] * 2; j <= 2 * 1000005; j += a[i]) {
        ans = max(ans, val[j] % a[i]);
      }
    }
  }
  cout << ans << endl;
}

```