#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#include<vector>
int main() {
// your code goes here
int arr[]={1,2,3};
int n=3;
int k=2;
int count=0,diff=0,i=0,j=0;
sort(arr,arr+n);
while(i<n && j<n)
{
diff=arr[j]-arr[i];
while(diff>k)
{
i++;
diff=arr[j]-arr[i];
}
//if(sum<=k)
count+=(j-i+1);
j++;
}
cout<<count-n;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KI2luY2x1ZGU8dmVjdG9yPgoKaW50IG1haW4oKSB7CgkvLyB5b3VyIGNvZGUgZ29lcyBoZXJlCglpbnQgYXJyW109ezEsMiwzfTsKCWludCBuPTM7CglpbnQgaz0yOwoJaW50IGNvdW50PTAsZGlmZj0wLGk9MCxqPTA7Cglzb3J0KGFycixhcnIrbik7Cgl3aGlsZShpPG4gJiYgajxuKQoJIHsKCSAgIAlkaWZmPWFycltqXS1hcnJbaV07CgkgICAJd2hpbGUoZGlmZj5rKQoJICAgCSB7CgkgICAJIAlpKys7CgkgICAJIAlkaWZmPWFycltqXS1hcnJbaV07CgkgICAJIAkKCSAgIAkgfQoJICAgCSAvL2lmKHN1bTw9aykKCSAgIAkgICAgY291bnQrPShqLWkrMSk7CgkgICAJIGorKzsgICAKCSB9CgkgCgkgY291dDw8Y291bnQtbjsKCSAKCXJldHVybiAwOwp9