[Login|Register]
Problems

Status

Rank

Statistics

Problem B
Unhappy dots
Time Limit: 1000ms
Memory Limit: 65536kb
Description

There are k dots living on an n × m grid. A dot is happy if and only if he has at least two neighbors. Otherwise, he’s lonely and thus unhappy.

Two dots are neighbors means that the manhattan distance between them is not greater than 1.

Given the locations of all dots, your task to count the number unhappy dots.

Input

The input consists of multiple test cases. The first line of each test case contains three integers k, n and m, which are described above. Next k lines each contains two integers xi and yi, indicating the location of a dot. (1 ≤ k ≤ 105, 1 ≤ xim ≤ 109, 1 ≤ yin ≤ 109)

A test case begins with “0 0 0” indicates the end of input.

Output

For each test case, output “Case x: ” first, where x is the case number. Then output the number unhappy dots.

Sample Input
2 2 2
1 1
1 2
4 2 2
1 1
1 2
2 1
2 2
5 2 2
1 1
1 1
1 2
2 1
2 2
0 0 0
Sample Output
Case 1: 2
Case 2: 0
Case 3: 0
University of Science and Technology of China
Online Judge for ACM/ICPC
Processed in 1.2ms with 2 query(s).