#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::map;
using std::max;
using std::min;
using std::numeric_limits;
using std::set;
using std::stack;
using std::string;
using std::stringstream;
using std::vector;
using namespace std;
vector<int> DFS(vector<vector<int> >& graph, int start) {
  stack<int> st;
  vector<int> visited(graph.size(), false);
  st.push(start);
  while (st.size() > 0) {
    int cur = st.top();
    st.pop();
    if (!visited[cur]) {
      visited[cur] = true;
      for (int i = 0; i < graph[cur].size(); ++i) {
        st.push(graph[cur][i]);
      }
    }
  }
  return visited;
}
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int num_bit(long long v) {
  int ret = 0;
  while (v != 0) {
    ret += 1;
    v = v >> 1;
  }
  return ret;
}
int main() {
  std::cout.precision(10);
  int n;
  cin >> n;
  set<int> a_set;
  for (int i = 0; i < n; ++i) {
    int v;
    cin >> v;
    a_set.insert(v);
  }
  int res = 0;
  vector<int> a(a_set.begin(), a_set.end());
  for (int i = 0; i < a.size() - 1; ++i) {
    for (int k = 2;; ++k) {
      int val = a[i] * k;
      int idx = lower_bound(a.begin(), a.end(), val) - a.begin() - 1;
      res = max(res, a[idx] % a[i]);
      if (val >= a.back()) {
        break;
      }
    }
  }
  cout << res << endl;
  return 0;
}

### Prompt

Please formulate 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 std::cin;
using std::cout;
using std::endl;
using std::map;
using std::max;
using std::min;
using std::numeric_limits;
using std::set;
using std::stack;
using std::string;
using std::stringstream;
using std::vector;
using namespace std;
vector<int> DFS(vector<vector<int> >& graph, int start) {
  stack<int> st;
  vector<int> visited(graph.size(), false);
  st.push(start);
  while (st.size() > 0) {
    int cur = st.top();
    st.pop();
    if (!visited[cur]) {
      visited[cur] = true;
      for (int i = 0; i < graph[cur].size(); ++i) {
        st.push(graph[cur][i]);
      }
    }
  }
  return visited;
}
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int num_bit(long long v) {
  int ret = 0;
  while (v != 0) {
    ret += 1;
    v = v >> 1;
  }
  return ret;
}
int main() {
  std::cout.precision(10);
  int n;
  cin >> n;
  set<int> a_set;
  for (int i = 0; i < n; ++i) {
    int v;
    cin >> v;
    a_set.insert(v);
  }
  int res = 0;
  vector<int> a(a_set.begin(), a_set.end());
  for (int i = 0; i < a.size() - 1; ++i) {
    for (int k = 2;; ++k) {
      int val = a[i] * k;
      int idx = lower_bound(a.begin(), a.end(), val) - a.begin() - 1;
      res = max(res, a[idx] % a[i]);
      if (val >= a.back()) {
        break;
      }
    }
  }
  cout << res << endl;
  return 0;
}

```