#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
int n;
int arr[2 * 100000 + 10], pos[1000000 * 2 + 10];
bool vis[2 * 1000000 + 10];
int main() {
  ios::sync_with_stdio(false);
  int tmp, ind = 0, ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    if (!vis[tmp]) {
      arr[ind++] = tmp;
      vis[tmp] = 1;
    }
  }
  sort(arr, arr + ind);
  for (int i = 0; i < ind; i++) pos[arr[i]] = i;
  for (int i = 0; i < ind; i++) {
    if (arr[i] == 1 || !arr[i]) continue;
    int a = arr[i], nxt = a;
    int l, r;
    l = pos[arr[i]];
    while (1) {
      nxt = nxt + a;
      tmp = lower_bound(arr, arr + ind, nxt) - arr;
      if (tmp == ind) tmp = ind - 1;
      if (arr[tmp] >= nxt) tmp--;
      tmp = arr[tmp];
      if (!tmp) continue;
      ans = max(ans, tmp % arr[i]);
      if (nxt > arr[ind - 1]) break;
    }
  }
  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;
#pragma comment(linker, "/STACK:1024000000,1024000000")
int n;
int arr[2 * 100000 + 10], pos[1000000 * 2 + 10];
bool vis[2 * 1000000 + 10];
int main() {
  ios::sync_with_stdio(false);
  int tmp, ind = 0, ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    if (!vis[tmp]) {
      arr[ind++] = tmp;
      vis[tmp] = 1;
    }
  }
  sort(arr, arr + ind);
  for (int i = 0; i < ind; i++) pos[arr[i]] = i;
  for (int i = 0; i < ind; i++) {
    if (arr[i] == 1 || !arr[i]) continue;
    int a = arr[i], nxt = a;
    int l, r;
    l = pos[arr[i]];
    while (1) {
      nxt = nxt + a;
      tmp = lower_bound(arr, arr + ind, nxt) - arr;
      if (tmp == ind) tmp = ind - 1;
      if (arr[tmp] >= nxt) tmp--;
      tmp = arr[tmp];
      if (!tmp) continue;
      ans = max(ans, tmp % arr[i]);
      if (nxt > arr[ind - 1]) break;
    }
  }
  printf("%d\n", ans);
  return 0;
}

```