#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int a[2 * 100010] = {0};   int check(int x, int n) {     if (x == 1) return 0;     int cur = 0, ans = 0;     while (cur < a[n - 1]) {       cur += x;       int pos = lower_bound(a, a + n, cur) - a;       if (pos > 0 && a[pos - 1] >= x) ans = max(ans, a[pos - 1] % x);     }     return ans;   }   int Solve(int n) {     int ans = 0, m = 1;     sort(a, a + n);     for (int i = 1; i < n; i++)       if (a[m - 1] != a[i]) a[m++] = a[i];     for (int i = 0; i < m; i++) ans = max(ans, check(a[i], m));     return ans;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     printf( %d n , Solve(n));     return 0;   }   