public class Main{
public static int mod = 99997867;
public static void main(String[] args){
long count = 0;
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int d = sc.nextInt();
int[] pos = new int[n];
for (int i = 0; i < n; i++){
pos[i] = sc.nextInt();
}
int left = 0;
for (int right = 2; right < n; right++){
while (pos[right] - pos[left] > d){
left++;
}
long p = right - left;
count += p * (p - 1) / 2;
}
System.out.println(count % mod);
}
}