#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  int ans = 0;
  n = unique(a, a + n) - a;
  for (int i = n - 2; i >= 0; i--) {
    if (ans >= a[i]) break;
    for (int j = 2;; j++) {
      int idx = lower_bound(a + i, a + n, j * a[i]) - a - 1;
      ans = max(ans, a[idx] % a[i]);
      if (idx == n - 1) break;
    }
  }
  cout << ans;
  return 0;
}

### Prompt

Your challenge is to write 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;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  int ans = 0;
  n = unique(a, a + n) - a;
  for (int i = n - 2; i >= 0; i--) {
    if (ans >= a[i]) break;
    for (int j = 2;; j++) {
      int idx = lower_bound(a + i, a + n, j * a[i]) - a - 1;
      ans = max(ans, a[idx] % a[i]);
      if (idx == n - 1) break;
    }
  }
  cout << ans;
  return 0;
}

```