#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 256;
const int N = 1256;
const int INF = int(1e9);
int n, a[MAXN * 2 + 0x100];
int u[MAXN * 2 + 0x100];
int main() {
  ios_base ::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    u[a[i]] = a[i];
  }
  int mx = 0;
  for (int i = 1; i <= MAXN + MAXN; ++i) {
    if (u[i] == 0 && u[i - 1] != 0) u[i] = u[i - 1];
  }
  for (int i = 1; i <= MAXN; ++i) {
    if (u[i] == i) {
      for (int j = i * 2 - 1; j <= MAXN + MAXN; j += i) {
        mx = max(mx, u[j] % u[i]);
      }
    }
  }
  cout << mx;
  return 0;
}

### Prompt

Your task is to create a Cpp solution 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 = 1e6 + 256;
const int N = 1256;
const int INF = int(1e9);
int n, a[MAXN * 2 + 0x100];
int u[MAXN * 2 + 0x100];
int main() {
  ios_base ::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    u[a[i]] = a[i];
  }
  int mx = 0;
  for (int i = 1; i <= MAXN + MAXN; ++i) {
    if (u[i] == 0 && u[i - 1] != 0) u[i] = u[i - 1];
  }
  for (int i = 1; i <= MAXN; ++i) {
    if (u[i] == i) {
      for (int j = i * 2 - 1; j <= MAXN + MAXN; j += i) {
        mx = max(mx, u[j] % u[i]);
      }
    }
  }
  cout << mx;
  return 0;
}

```