#include <bits/stdc++.h>   using namespace std;   int oriArr[2000001] = {0};   int arr[2000001];   int main() {     int oriCnt;     cin >> oriCnt;     int maxOri = 0;     for (int i = 0; i < oriCnt; i++) {       int tmp;       cin >> tmp;       oriArr[tmp] = 1;       if (maxOri < tmp) maxOri = tmp;     }     arr[0] = 0;     int cnt = 0;     for (int i = 1; i <= maxOri; i++) {       if (oriArr[i] == 0) {         arr[i] = arr[i - 1];       } else {         arr[i] = i;         cnt++;       }     }     if (cnt == 1) {       cout <<  0  << endl;       return 0;     }     int max = 0;     for (int i = maxOri - 1; i >= 0; i--) {       if (arr[i] < max) break;       if (oriArr[i] == 0) continue;       for (int j = 2; arr[i] * (j - 1) <= maxOri; j++) {         int tmp = j * arr[i] - 1;         if (tmp > maxOri) tmp = maxOri;         if (arr[tmp] % arr[i] > max) max = arr[tmp] % arr[i];       }     }     cout << max << endl;     return 0;   }   