For this Question: You are given an array P of size N. You have to find the maximum value of <b>P<sub>i</sub> % P<sub>j</sub></b> for all possible i, j pairs.First line contains a single integer N.
The second line of the input contains N space seperated integers.

Constraints:
2 <= N <= 10<sup>5</sup>
1 <= P<sub>i</sub> <= 10<sup>9</sup>Print the maximum value of P<sub>i</sub> % P<sub>j</sub> for all possible i, j pairs in the array.Sample Input:
5
8 6 7 9 4

Sample Output:
8

Explanation:
i = 1, j = 4 (1-based indexing) will give the maximum possible result over all (i, j) pairs., I have written this Solution Code: #include<bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using T = pair<int, int>;
typedef long long ll;
const int mod = 1e9 + 7;
const int INF = 1e9;


void solve() {
	int n;
    cin >> n;
    vector<int> p(n);
    set<int> s;
    for(auto &i : p) cin >> i, s.insert(i);
    if(s.size() == 1){
        cout << 0;
    }
    else{
        auto it = s.rbegin();
        it++;
        cout << (*it);
    }
}

signed main(){
    fast
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
        if(i != t) cout << endl;
    }
}, In this Programming Language: C++, Now tell me if this Code is compilable or not?