#include <bits/stdc++.h>
using namespace std;
const int MN = 2e6 + 100;
int last[MN];
int cnt[MN];
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    cnt[t]++;
  }
  int ls = -1;
  for (int i = 0; i < MN; i++) {
    last[i] = ls;
    if (cnt[i]) {
      ls = i;
    }
  }
  int ans = 0;
  for (int i = 1; i < MN; i++) {
    if (cnt[i]) {
      for (int j = 2 * i; j < MN; j += i) {
        if (last[j] != -1) {
          ans = max(ans, last[j] % i);
        }
      }
    }
  }
  cout << ans;
}

### Prompt

Construct a CPP code solution to the problem outlined:

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 MN = 2e6 + 100;
int last[MN];
int cnt[MN];
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    cnt[t]++;
  }
  int ls = -1;
  for (int i = 0; i < MN; i++) {
    last[i] = ls;
    if (cnt[i]) {
      ls = i;
    }
  }
  int ans = 0;
  for (int i = 1; i < MN; i++) {
    if (cnt[i]) {
      for (int j = 2 * i; j < MN; j += i) {
        if (last[j] != -1) {
          ans = max(ans, last[j] % i);
        }
      }
    }
  }
  cout << ans;
}

```