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: import java.io.*;
import java.util.*;



class Main {
	public static void main (String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str1 = br.readLine();
        String str2[] = str1.split(" ");
        int n = Integer.parseInt(str2[0]);
        int k = Integer.parseInt(str2[1]);
        String str3 = br.readLine();
        String str4[] = str3.split(" ");
        long[] arr = new long[n];
        for(int i = 0; i < n; ++i) {
            arr[i] = Long.parseLong(str4[i]);
        }
        Arrays.sort(arr);
        int i=0,j=2;
        long ans=0;
        while(j!=n){
        if(i==j-1){j++;continue;}
    if((arr[j]-arr[i])>k){i++;}
    else{
            int x = j-i;
        ans+=(x*(x-1))/2;
        j++;
    }

}
System.out.print(ans);

	}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?