Candycopter

View as PDF

Submit solution


Points: 5
Time limit: 1.0s
Memory limit: 256M

Problem types

Mustif's grandma gives them one candy per day, but Mustif wants to eat all the candy in one day. So Mustif takes their toy helicopter and uses it to steal all of the candies from their grandma's room.

There are \(\mathbf{N}\) candies in the room and Mustif wants them all. But there is a problem, the helicopter can only fly for \(\mathbf{M}\) units before landing to wait and recharge.

Mustif stands on the \((X,Y,Z) = (0,0,0)\) point and also their helicopter takes off from this point. After taking the candy, the helicopter needs to fly back to the \((X,Y,Z) = (0,0,0)\) point and land there. If it lands in the room, Mustif's grandma may see the helicopter and suspect that something fishy is going on.

Can you find the number of candies Mustif can steal from the room?

Input

Two space-separated integers \(\mathbf{N}\) and \(\mathbf{M}\) on the first line, the number of candies in the room and maximum units that the helicopter can fly before landing to recharge respectively.

Next \(\mathbf{N}\) lines have three space-separated integers \(\mathbf{X_i}\), \(\mathbf{Y_i}\) and \(\mathbf{Z_i}\), being the coordinates of the \(\mathbf{i}\)th candy.

Batch #1:
  • \(1 \leq \mathbf{N} \leq 100\)
  • \(1 \leq \mathbf{M} \leq 300\)
  • \(1 \leq \mathbf{X_i}, \mathbf{Y_i}, \mathbf{Z_i} \leq 100\)
Batch #2:
  • \(1 \leq \mathbf{N} \leq 10^5\)
  • \(1 \leq \mathbf{M} \leq 3 \cdot 10^5\)
  • \(1 \leq \mathbf{X_i}, \mathbf{Y_i}, \mathbf{Z_i} \leq 10^5\)

Output

Print the number of candies Mustif can steal from the room.

Examples

Input:

1 2
1 0 0

Output:

1

Input:

3 50
3 4 0
12 15 16
12 15 17

Output:

2