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: n, p = input().split(' ')
n = int(n)
p = int(p)
arr = input().split(' ')[:n]

for i in range(n):
    arr[i] = int(arr[i])

arr.sort()
i = 0
k = 2
count = 0
while k!=n:
    if i == k-1:
        k = k + 1
        continue
    if (arr[k] - arr[i]) <= p:
        count = count + (int)(((k-i)*(k-i-1))/2)
        k = k + 1
    else:
        i = i + 1

print(count)








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