← Home
package main

import (
	"bufio"
	"fmt"
	"os"
)

type FastScanner struct {
	r *bufio.Reader
}

func (fs *FastScanner) NextInt64() int64 {
	var sign int64 = 1
	var val int64
	c, _ := fs.r.ReadByte()
	for (c < '0' || c > '9') && c != '-' {
		c, _ = fs.r.ReadByte()
	}
	if c == '-' {
		sign = -1
		c, _ = fs.r.ReadByte()
	}
	for c >= '0' && c <= '9' {
		val = val*10 + int64(c-'0')
		c, _ = fs.r.ReadByte()
	}
	fs.r.UnreadByte()
	return val * sign
}

func main() {
	fs := &FastScanner{r: bufio.NewReaderSize(os.Stdin, 1<<20)}
	n := int(fs.NextInt64())
	d := fs.NextInt64()

	m := make(map[int64]struct{}, n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		x := fs.NextInt64()
		a[i] = x
		m[x] = struct{}{}
	}

	var ans int64
	for _, x := range a {
		if _, ok := m[x+d]; ok {
			ans++
		}
	}

	fmt.Print(ans)
}