Sanggeun and Seonyoung are playing with toy animals. First they pick one of the three game boards below. Each board is made up of many cells; board $1$ is one-dimensional (a line), board $2$ is two-dimensional (a grid), and board $3$ is three-dimensional (a solid grid).

Each cell is identified by integer coordinates, and adjacent cells are joined by a line segment.
Sanggeun places $N$ toy animals on the cells. Several animals may share the same cell.
The distance between two cells is the least number of moves needed to travel from one to the other. Because each move goes to an adjacent cell, the distance equals the sum of the absolute differences of the coordinates.
Two toy animals can hear each other when the distance between their cells is at most $D$. Given the board type, the position of every toy animal, and $D$, write a program that counts the number of pairs of toy animals that can hear each other.
The first line contains four integers $B$, $N$, $D$, and $M$ separated by spaces.
Each of the next $N$ lines gives the coordinates of one toy animal. On board $B$ a line contains $B$ integers separated by spaces: $x$ when $B = 1$, $x\ y$ when $B = 2$, and $x\ y\ z$ when $B = 3$. Every coordinate is a natural number between $1$ and $M$ inclusive. Several animals may occupy the same cell.
Print on the first line the number of pairs of toy animals that can hear each other.