IOI '07 - Zagreb, Croatia
Mirko and Slavko are playing with toy animals. First, they choose one of three boards given in the figure below. Each board consists of cells (shown as circles in the figure) arranged into a one, two or three dimensional grid.

Board 1

Board 2

Board 3
Mirko then places
The distance between two cells is the smallest number of moves that an animal would need in order to reach one cell from the other. In one move, the animal may step into one of the adjacent cells (connected by line segments in the figure).
Two animals can hear each other if the distance between their cells is at most
Write a program that, given the board type, the locations of all animals, and the number
Input Specification
The first line of input contains four integers in this order:
- The board type
; - The number of animals
; - The largest distance
at which two animals can hear each other ; - The size of the board
(the largest coordinate allowed to appear in the input):- When
, will be at most . - When
, will be at most . - When
, will be at most .
- When
Each of the following
More than one animal may occupy the same cell.
Output Specification
Output should consist of a single integer, the number of pairs of animals that can hear each other.
Note: use a 64-bit integer type to calculate and output the result (long long
in C/C++, int64
in Pascal).
Grading
In test cases worth a total of
Furthermore, for each of the three board types, a solution that correctly solves all test cases of that type will be
awarded at least
Sample Input 1
1 6 5 100
25
50
50
10
20
23
Sample Output 1
4
Explanation for Sample Output 1
Suppose the animals are numbered
(distance ) (distance ) (distance ) (distance )
Sample Input 2
2 5 4 10
5 2
7 2
8 4
6 5
4 4
Sample Output 2
8
Explanation for Sample Output 2
The eight pairs are:
(distance ) (distance ) (distance ) (distance ) (distance ) (distance ) (distance ) (distance )
Comments