import java.util.Scanner;
import java.util.*;


public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int[] nums = new int[N];

        for(int i=0;i<N;i++){
            nums[i] = sc.nextInt();
        }
        //初始化完毕
        if(N<=2) System.out.println(0);

        long res = 0;
        int i=0,j=2;

        while(i<N-2){
            while(j<N && nums[j]-nums[i]<=D) j++;
            long num = j-i-1;
            res = res + (num * (num-1))/2; // 在剩下的位置中挑两个C num 2
            res = res % 99997867;
            i++;
        }
        System.out.println(res);
    }
}