#include <bits/stdc++.h>
using namespace std;
int N, A[300200 + 1], ans = 0, maxim = 0;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
    maxim = max(A[i], maxim);
  }
  sort(A + 1, A + N + 1);
  for (int i = 1; i < N; i++) {
    for (int j = A[i]; j <= maxim; j += A[i]) {
      int lo = i, hi = N, val = j + A[i], soli = i;
      while (lo <= hi) {
        int mid = (lo + hi) / 2;
        if (A[mid] < val) {
          soli = mid;
          lo = mid + 1;
        } else {
          hi = mid - 1;
        }
      }
      if (A[soli] > j) ans = max(ans, A[soli] % j);
    }
    while (i <= N && A[i] == A[i + 1]) i++;
  }
  printf("%d\n", ans);
  return 0;
}

### Prompt

Please provide a Cpp coded solution to the problem described below:

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;
int N, A[300200 + 1], ans = 0, maxim = 0;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
    maxim = max(A[i], maxim);
  }
  sort(A + 1, A + N + 1);
  for (int i = 1; i < N; i++) {
    for (int j = A[i]; j <= maxim; j += A[i]) {
      int lo = i, hi = N, val = j + A[i], soli = i;
      while (lo <= hi) {
        int mid = (lo + hi) / 2;
        if (A[mid] < val) {
          soli = mid;
          lo = mid + 1;
        } else {
          hi = mid - 1;
        }
      }
      if (A[soli] > j) ans = max(ans, A[soli] % j);
    }
    while (i <= N && A[i] == A[i + 1]) i++;
  }
  printf("%d\n", ans);
  return 0;
}

```