Program cog610;
Const
Pr=100019;
Type
Pt=^Nd;
Nd=Record
E:Pt;
D,T:Longint;
End;
Var
H:Array[0..Pr]Of Pt;
S,N,C,I:Longint;
Function Hash(N,M:Longint):Longint;
Var
I:Pt;
T:Longint;
Begin
T:=N Mod Pr;
I:=H[T];
While I<>Nil Do
Begin
If I^.D=N Then
Begin
Inc(I^.T,M);
Exit(I^.T);
End;
I:=I^.E;
End;
If M=0 Then Exit(0);
New(I);
I^.D:=N;
I^.T:=1;
I^.E:=H[T];
H[T]:=I;
End;
Begin
Assign(Input,'dec.in');
Assign(Output,'dec.out');
Reset(Input);
Rewrite(Output);
Readln(N,C);
S:=0;
Fillchar(H,Sizeof(H),0);
Repeat
Read(I);
Inc(S,Hash(I+C,0));
If I>=C Then Inc(S,Hash(I-C,0));
Hash(I,1);
Dec(N);
Until N=0;
Writeln(S);
Close(Input);
Close(Output);
End.