#P4648. Animal Toys Communication
Animal Toys Communication
Animal Toys Communication
Mirko and Slavko are playing a game with animal toys. First, they choose one of the three toy templates, which are composed of grid points in one, two, or three dimensions (as shown by the circles in the figure below).
Then Mirko places N animal toys on the grid points of the selected template. An animal toy can move one step at a time to an adjacent grid point (in the figure, adjacent points are connected by short lines). The distance between two grid points is defined as the minimum number of steps required to move from one point to the other.
If the distance between two animals is (\le D) (i.e., less than or equal to (D)), then they can hear each other. Your task is to count the number of pairs of animals that can mutually hear each other.
inputFormat
The first line contains three integers: (T), (N), and (D), where (T) represents the type of template (1 for one-dimensional, 2 for two-dimensional, 3 for three-dimensional), (N) is the number of animal toys, and (D) is the maximum distance within which animals can hear each other.
This is followed by (N) lines. Depending on the value of (T), each line contains (T) integers representing the coordinates of an animal. For example, when (T = 2), each line contains two integers ((x) and (y)).
outputFormat
Output a single integer representing the total number of pairs of animals that can hear each other.
sample
1 3 1
1
2
4
1
</p>