#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, lb, ans, a[maxn];
inline int input() {
  int ans = 0;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) {
    ans = (ans << 3) + (ans << 1) + (ch - '0');
  }
  return ans;
}
int main() {
  n = input();
  ans = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = input();
  }
  sort(a + 1, a + n + 1);
  for (int j = n; j >= 1; j--) {
    if (ans > a[j]) {
      break;
    }
    if (a[j] == a[j + 1]) {
      continue;
    }
    lb = 1;
    for (int k = a[j]; k <= a[n] + a[j]; k += a[j]) {
      lb = lower_bound(a + lb, a + n + 1, k + a[j]) - a;
      ans = max(ans, a[lb - 1] % a[j]);
    }
  }
  printf("%d\n", ans);
  return 0;
}

### 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;
const int maxn = 2e5 + 5;
int n, lb, ans, a[maxn];
inline int input() {
  int ans = 0;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) {
    ans = (ans << 3) + (ans << 1) + (ch - '0');
  }
  return ans;
}
int main() {
  n = input();
  ans = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = input();
  }
  sort(a + 1, a + n + 1);
  for (int j = n; j >= 1; j--) {
    if (ans > a[j]) {
      break;
    }
    if (a[j] == a[j + 1]) {
      continue;
    }
    lb = 1;
    for (int k = a[j]; k <= a[n] + a[j]; k += a[j]) {
      lb = lower_bound(a + lb, a + n + 1, k + a[j]) - a;
      ans = max(ans, a[lb - 1] % a[j]);
    }
  }
  printf("%d\n", ans);
  return 0;
}

```