#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> seq(n);
  for (int i = 0; i < n; i++) cin >> seq[i];
  sort((seq).begin(), (seq).end());
  int mx = 0;
  map<int, int> vis;
  for (int i = 0; i < n; i++) {
    if (vis[seq[i]]) continue;
    for (int j = 2 * seq[i];; j += seq[i]) {
      int pos =
          distance(seq.begin(), lower_bound((seq).begin(), (seq).end(), j)) - 1;
      mx = max(mx, seq[pos] % seq[i]);
      if (j > (seq)[(int)((seq)).size() - 1]) break;
    }
    vis[seq[i]] = true;
  }
  cout << mx << endl;
  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 main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> seq(n);
  for (int i = 0; i < n; i++) cin >> seq[i];
  sort((seq).begin(), (seq).end());
  int mx = 0;
  map<int, int> vis;
  for (int i = 0; i < n; i++) {
    if (vis[seq[i]]) continue;
    for (int j = 2 * seq[i];; j += seq[i]) {
      int pos =
          distance(seq.begin(), lower_bound((seq).begin(), (seq).end(), j)) - 1;
      mx = max(mx, seq[pos] % seq[i]);
      if (j > (seq)[(int)((seq)).size() - 1]) break;
    }
    vis[seq[i]] = true;
  }
  cout << mx << endl;
  return 0;
}

```