#include <bits/stdc++.h>
using namespace std;
set<int> array_map;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    array_map.insert(a);
  }
  set<int>::reverse_iterator it_s = array_map.rbegin();
  int max_num = *it_s;
  int _max = 0;
  for (it_s++; it_s != array_map.rend() && _max <= (*it_s); ++it_s) {
    for (int cur_num = (*it_s) * 2; cur_num <= max_num; cur_num += *it_s) {
      set<int>::iterator it = array_map.lower_bound(cur_num);
      --it;
      if (*it <= *it_s) continue;
      if (cur_num == *it) --it;
      _max = max((*it) % (*it_s), _max);
    }
    _max = max(max_num % (*it_s), _max);
  }
  printf("%d\n", _max);
  return 0;
}

### Prompt

Please create a solution in CPP 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;
set<int> array_map;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    array_map.insert(a);
  }
  set<int>::reverse_iterator it_s = array_map.rbegin();
  int max_num = *it_s;
  int _max = 0;
  for (it_s++; it_s != array_map.rend() && _max <= (*it_s); ++it_s) {
    for (int cur_num = (*it_s) * 2; cur_num <= max_num; cur_num += *it_s) {
      set<int>::iterator it = array_map.lower_bound(cur_num);
      --it;
      if (*it <= *it_s) continue;
      if (cur_num == *it) --it;
      _max = max((*it) % (*it_s), _max);
    }
    _max = max(max_num % (*it_s), _max);
  }
  printf("%d\n", _max);
  return 0;
}

```