In the lattice points of the coordinate line there are *n* radio stations, the *i*-th of which is described by three integers:
 -  *x*<sub class="lower-index">*i*</sub> — the coordinate of the *i*-th station on the line, -  *r*<sub class="lower-index">*i*</sub> — the broadcasting range of the *i*-th station, -  *f*<sub class="lower-index">*i*</sub> — the broadcasting frequency of the *i*-th station. 
We will say that two radio stations with numbers *i* and *j* reach each other, if the broadcasting range of each of them is more or equal to the distance between them. In other words *min*(*r*<sub class="lower-index">*i*</sub>, *r*<sub class="lower-index">*j*</sub>) ≥ |*x*<sub class="lower-index">*i*</sub> - *x*<sub class="lower-index">*j*</sub>|.

Let's call a pair of radio stations (*i*, *j*) bad if *i* &lt; *j*, stations *i* and *j* reach each other and they are close in frequency, that is, |*f*<sub class="lower-index">*i*</sub> - *f*<sub class="lower-index">*j*</sub>| ≤ *k*.

Find the number of bad pairs of radio stations.
The first line contains two integers *n* and *k* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>, 0 ≤ *k* ≤ 10) — the number of radio stations and the maximum difference in the frequencies for the pair of stations that reach each other to be considered bad.

In the next *n* lines follow the descriptions of radio stations. Each line contains three integers *x*<sub class="lower-index">*i*</sub>, *r*<sub class="lower-index">*i*</sub> and *f*<sub class="lower-index">*i*</sub> (1 ≤ *x*<sub class="lower-index">*i*</sub>, *r*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>, 1 ≤ *f*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">4</sup>) — the coordinate of the *i*-th radio station, it's broadcasting range and it's broadcasting frequency. No two radio stations will share a coordinate.
none
3 2
1 3 10
3 2 5
4 10 8
1
3 3
1 3 10
3 2 5
4 10 8
2
5 1
1 3 2
2 2 4
3 2 1
4 2 1
5 3 3
2
5 1
1 5 2
2 5 4
3 5 1
4 5 1
5 5 3
5
1 4
6 8 16
0
from sys import stdin
input=lambda :stdin.readline()[:-1]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 2)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def query(self,l,r):
      return self.sum(r)-self.sum(l-1)
    
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

from collections import defaultdict
n,k=map(int,input().split())
F=set()
xrf=[]
d=defaultdict(list)
for i in range(n):
  x,r,f=map(int,input().split())
  xrf.append((x,r,f,i))
  d[f].append(i)
  F.add(f)

F=sorted(list(F))
m=len(F)

ans=0

for i in range(m):
  X=set()
  todo=[]
  R=i+1
  while R<m and F[R]-F[i]<=k:
    for j in d[F[R]]:
      X.add(xrf[j][0])
      todo.append(xrf[j])
    R+=1
  
  L=i-1
  while L>=0 and F[i]-F[L]<=k:
    for j in d[F[L]]:
      X.add(xrf[j][0])
      todo.append(xrf[j])
    L-=1
  for j in d[F[i]]:
    X.add(xrf[j][0])
    todo.append(xrf[j])
  
  X=sorted(list(X))
  todo.sort(key=lambda x:-x[1]*2*10**9+x[3])
  
  N=len(X)
  dX={}
  for j in range(N):
    dX[X[j]]=j
  
  bit=Bit(N)
  #print(todo)
  for x,r,f,_ in todo:
    tmp=dX[x]
    if f==F[i]:
      ng,ok=-1,tmp
      while abs(ng-ok)>1:
        mid=(ng+ok)//2
        if x-X[mid]<=r:
          ok=mid
        else:
          ng=mid
      left=ok
      
      ng,ok=N,tmp
      while abs(ng-ok)>1:
        mid=(ng+ok)//2
        if X[mid]-x<=r:
          ok=mid
        else:
          ng=mid
      right=ok
      
      ans+=bit.query(left+1,right+1)
    bit.add(tmp+1,1)
    
print(ans)