#P1296. 奶牛的耳语

奶牛的耳语

Description

In your cattle farm, all cows are kept in a row of stalls arranged along a straight line. There are nn cows, and the position of the ii-th cow on the line is represented by an integer coordinate pi(0pi108)p_i(0\le p_i \le 10^8). On boring days, cows often share gossip from their own stalls. Each cow speaks with the same loudness, but due to sound attenuation, a cow’s voice can only be heard by cows within a distance no greater than d(0d104)d(0 \le d \le 10^4). In this case, the pair of cows is said to be able to communicate with each other. Given all cows’ positions and the maximum propagation distance dd, please write a program to compute how many pairs of cows in your farm can communicate.

Input Format

The first line contains two integers n,dn,d.

The second line contains nn integers, each being a coordinate pip_i, describing a cow’s position on the line.

Output Format

A single integer, the number of pairs of cows in the farm that can communicate.

5 10
10 12 16 37 40

4

Hint

Constraints

  • For 40%40\% of the data, 1n1031 \leq n \leq 10^3.
  • For 100%100\% of the data, 1n1061 \leq n \leq 10^6.

Translated by ChatGPT 5