#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 7;
int ar[N];
int dd[N];
int n, mx, rs;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", &ar[i]);
  sort(ar, ar + n);
  mx = *max_element(ar, ar + n) * 2;
  for (int i = 0; i < n; i++) {
    if (dd[ar[i]]) continue;
    int ml = 2;
    for (; ml * ar[i] <= mx; ml++) {
      int tp = ml * ar[i];
      int *p = lower_bound(ar, ar + n, tp);
      p--;
      rs = max(rs, (*p) % ar[i]);
    }
    dd[ar[i]] = 1;
  }
  cout << rs << endl;
  return 0;
}

### Prompt

In Cpp, your task is to solve 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 N = 2e6 + 7;
int ar[N];
int dd[N];
int n, mx, rs;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%d", &ar[i]);
  sort(ar, ar + n);
  mx = *max_element(ar, ar + n) * 2;
  for (int i = 0; i < n; i++) {
    if (dd[ar[i]]) continue;
    int ml = 2;
    for (; ml * ar[i] <= mx; ml++) {
      int tp = ml * ar[i];
      int *p = lower_bound(ar, ar + n, tp);
      p--;
      rs = max(rs, (*p) % ar[i]);
    }
    dd[ar[i]] = 1;
  }
  cout << rs << endl;
  return 0;
}

```