import java.io.*;
import java.util.*;

public class che_av {

	FastScanner in;
	PrintWriter out;

	void solve() {
		int n = in.nextInt(), r = in.nextInt() + 1;
		int[] a = new int[n];
		long ans = 0;
		for (int i = 0; i < n; i++) {
			ans += Math.abs(Arrays.binarySearch(a, 0, i, (a[i] = in.nextInt()) - r) + 1);
		}
		out.println(ans);
	}

	void run() {
		try {
			in = new FastScanner("che.in");
			out = new PrintWriter("che.out");
			solve();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

	public static void main(String[] args) {
		new che_av().run();
	}
}
