For this Question: Given an array <b>Arr[]</b> of size <b>N</b> as input, your task is to count the number of triplets Arr[i], Arr[j] and Arr[k] such that:-
i < j < k and the difference between every 2 elements of triplets is less than or equal to P i. e |Arr[i] - Arr[j]| <= P, |Arr[i] - Arr[k]| <= P and |Arr[j] - Arr[k]| <= PThe first line of input contains two space- separated integers N and P.
next line contains N space separated integers depicting the values of the Arr[].

Constraints:-
3 <= N <= 10<sup>5</sup>
1 <= Arr[i], P <= 10<sup>9</sup>
0 <= i <= N-1Return the count of triplets that satisfies the above conditions.Sample Input:-
5 4
1 3 2 5 9

Sample Output:-
4

Explanation:-
(1, 3, 2), (1, 3, 5), (1, 2, 5), (2, 3, 5) are the required triplets

Sample Input:-
5 3
1 8 4 2 9

Sample Output:-
1, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
int n,p;
cin>>n>>p;
int a[n];
for(int i=0;i<n;i++){
    cin>>a[i];
}
sort(a,a+n);
int i=0,j=2;
int ans=0;
while(j!=n){
        if(i==j-1){j++;continue;}
    if((a[j]-a[i])>p){i++;}
    else{
            int x = j-i;
        ans+=(x*(x-1))/2;
        j++;
    }

}

cout<<ans;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not?