import java.util.*;
public class Main {
public static void main
(String[] args
) { Scanner scanner
= new Scanner
(System.
in); int n = scanner.nextInt();
long k = scanner.nextLong();
long[] b = new long[n];
for (int i = 0; i < n; i++) {
b[i] = scanner.nextLong();
}
long count = 0;
for (int i = 0, j = 0; j < n; j++) {
long d = b[j] - b[i]; //[i............j]
while (d > k) {
i++;
d = b[j] - b[i];
}
count += (j - i + 1);
}
System.
out.
println(count
- n
); scanner.close();
}
}
aW1wb3J0IGphdmEudXRpbC4qOwogCnB1YmxpYyBjbGFzcyBNYWluIHsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBTY2FubmVyIHNjYW5uZXIgPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwogICAgICAgIGludCBuID0gc2Nhbm5lci5uZXh0SW50KCk7CiAgICAgICAgbG9uZyBrID0gc2Nhbm5lci5uZXh0TG9uZygpOwogICAgICAgIGxvbmdbXSBiID0gbmV3IGxvbmdbbl07CiAKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgICAgICBiW2ldID0gc2Nhbm5lci5uZXh0TG9uZygpOwogICAgICAgIH0KIAogICAgICAgIGxvbmcgY291bnQgPSAwOwogCiAgICAgICAgQXJyYXlzLnNvcnQoYik7CiAKICAgICAgICBmb3IgKGludCBpID0gMCwgaiA9IDA7IGogPCBuOyBqKyspIHsKICAgICAgICAgICAgbG9uZyBkID0gYltqXSAtIGJbaV07IC8vW2kuLi4uLi4uLi4uLi5qXQogICAgICAgICAgICB3aGlsZSAoZCA+IGspIHsKICAgICAgICAgICAgICAgIGkrKzsKICAgICAgICAgICAgICAgIGQgPSBiW2pdIC0gYltpXTsKICAgICAgICAgICAgfQogICAgICAgICAgICBjb3VudCArPSAoaiAtIGkgKyAxKTsKICAgICAgICB9CiAKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oY291bnQgLSBuKTsKICAgICAgICBzY2FubmVyLmNsb3NlKCk7CiAgICB9Cn0=