Олимпиадный тренинг

Задача 28332. City of Che


Задача

Темы:
In the center of the city of Che there is a pedestrian street - one of the most popular places for city residents to walk. It is very pleasant to walk along this street, because there are n funny monuments along the street.
 
Masha, a girl from the city of Che, likes two boys from her school, and she can't choose between them. To make her final decision, she decided to date both boys at the same time. Masha wants to choose two monuments on the pedestrian street, near which the boys will be waiting for her. At the same time, she wants to choose such monuments so that the boys do not see each other. Masha knows that because of the fog, the boys will only see each other if they are no more than r meters away.
 
Masha wondered how many ways there are to choose two different monuments for dating.
 
Input
The first line contains two integers n and r (2<=n<=300 000, 1<=r<=109) - the number of monuments and the maximum distance the boys can see each other.
The second line contains n positive numbers d1 ... dn, where di is the distance from the i-th monument to the beginning of the street. All monuments are located at different distances from the beginning of the street. The monuments are listed in order of increasing distance from the beginning of the street (1<=d1 <d2< ... < dn<=109).
 
Output
Print one number - the number of ways to choose two monuments for dating.
 
Examples
# Input Output Explanation
1
4 4
1 3 5 8
2 In the example above, Masha can choose monuments 1 and 4 or monuments 2 and 4.