#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//variable
int arr[1001][1001];
int a,b;
void scan_P(int i,int j){
arr[i][j] = 1;
}
void scan_K(int i,int j){
for(int i1=i-1;i1 <=i+1;i1++){
if(i1 <0 || i1 >=a ||i1 ==i){
}else{
if((j+2) < b ){
arr[i1][j+2] = 1;
}
if((j-2) >=0){
arr[i1][j-2] = 1;
}
}
}
for(int j1=j-1;j1 <=j+1;j1++){
if(j1 <0 || j1 >=b ||j1 == j){
}else{
if((i+2) < a){
arr[i+2][j1] = 1;
}
if((i-2) >= 0){
arr[i-2][j1] = 1;
}
}
}
}
void scan_Q(int i,int j){
arr[i][j] = 1;
for(int i1=i+1;i1<a;i1++){
if(arr[i1][j] == 1){
break;
}else{
arr[i1][j] = 1;
}
}
for(int i1=i-1;i1>=0;i1--){
if(arr[i1][j] == 1){
break;
}else{
arr[i1][j] = 1;
}
}
for(int j1=j+1;j1<b;j1++){
if(arr[i][j1] == 1){
break;
}else{
arr[i][j1] = 1;
}
}
for(int j1=j-1;j1>=0;j1--){
if(arr[i][j1] == 1){
break;
}else{
arr[i][j1] = 1;
}
}
for(int i1 = i-1;i1 >= 0;i1--){
int j1 = j- (i-i1);
if(j1 <0){
break;
}
if(arr[i1][j1] == 1){
break;
}else{
arr[i1][j1] = 1;
}
}
for(int i1 = i-1;i1 >= 0;i1--){
int j1 = j+ (i-i1);
if(j1 >=b){
break;
}
if(arr[i1][j1] == 1){
break;
}else{
arr[i1][j1] = 1;
}
}
for(int i1 = i+1; i1 <a;i1++){
int j1 = j-(i1-i);
if(j1 <0){
break;
}
if(arr[i1][j1] == 1 ){
break;
}else{
arr[i1][j1] = 1;
}
}
for(int i1 = i+1; i1 < a;i1++){
int j1 = j+(i1-i);
if(j1 >= b){
break;
}
if(arr[i1][j1] == 1 || j1 >=b){
break;
}else{
arr[i1][j1] = 1;
}
}
}
int ret_val(){
int res = 0;
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
if(arr[i][j] == 0){
res++;
}
}
}
return res;
}
int main(){
//freopen("input.txt","r",stdin);
int test = 1;
while(a >0 && b > 0){
int num_q,num_k,num_p;
int arr1[202],arr2[202],arr3[202];
for(int i=0;i<2*num_q;i++){
}
for(int i=0;i<2*num_k;i++){
}
for(int i=0;i<2*num_p;i++){
}
//Scan P
for(int i=0;i<num_p;i++){
scan_P(arr3[2*i]-1,arr3[2*i+1]-1);
}
for(int i=0;i<num_k;i++){
arr[arr2[2*i]-1][arr2[2*i+1]-1] = 1;
}
//Scan_Q
for(int i=0;i<num_q;i++){
scan_Q(arr1[2*i]-1,arr1[2*i+1]-1);
}
//ScaN K
for(int i=0;i<num_k;i++){
scan_K(arr2[2*i]-1,arr2[2*i+1]-1); // 1 4 0 3
}
// for(int i=0;i<a;i++){
// for(int j=0;j<b;j++){
// printf("%d ",arr[i][j]);
// }
// printf("\n");
// }
printf("Board %d has %d safe squares.\n",test
,ret_val
()); test++;
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgovL3ZhcmlhYmxlCmludCBhcnJbMTAwMV1bMTAwMV07IAppbnQgYSxiOwp2b2lkIHNjYW5fUChpbnQgaSxpbnQgail7CiAgICBhcnJbaV1bal0gPSAxOwp9Cgp2b2lkIHNjYW5fSyhpbnQgaSxpbnQgail7CiAgICBmb3IoaW50IGkxPWktMTtpMSA8PWkrMTtpMSsrKXsKICAgICAgICBpZihpMSA8MCB8fCBpMSA+PWEgfHxpMSA9PWkpewoKICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgaWYoKGorMikgPCBiICl7CiAgICAgICAgICAgICAgICBhcnJbaTFdW2orMl0gPSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKChqLTIpID49MCl7CiAgICAgICAgICAgICAgICBhcnJbaTFdW2otMl0gPSAxOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfSAKICAgIGZvcihpbnQgajE9ai0xO2oxIDw9aisxO2oxKyspewogICAgICAgIGlmKGoxIDwwIHx8IGoxID49YiB8fGoxID09IGopewoKICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgaWYoKGkrMikgPCBhKXsKICAgICAgICAgICAgICAgIGFycltpKzJdW2oxXSA9IDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYoKGktMikgPj0gMCl7CiAgICAgICAgICAgICAgICBhcnJbaS0yXVtqMV0gPSAxOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9Cgp2b2lkIHNjYW5fUShpbnQgaSxpbnQgail7CiAgICBhcnJbaV1bal0gPSAxOwogICAgZm9yKGludCBpMT1pKzE7aTE8YTtpMSsrKXsKICAgICAgICBpZihhcnJbaTFdW2pdID09IDEpewogICAgICAgICAgICBicmVhazsKICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgYXJyW2kxXVtqXSA9IDE7CiAgICAgICAgfQogICAgfQogICAgZm9yKGludCBpMT1pLTE7aTE+PTA7aTEtLSl7CiAgICAgICAgaWYoYXJyW2kxXVtqXSA9PSAxKXsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfWVsc2V7CiAgICAgICAgICAgIGFycltpMV1bal0gPSAxOwogICAgICAgIH0KICAgIH0KICAgIGZvcihpbnQgajE9aisxO2oxPGI7ajErKyl7CiAgICAgICAgaWYoYXJyW2ldW2oxXSA9PSAxKXsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfWVsc2V7CiAgICAgICAgICAgIGFycltpXVtqMV0gPSAxOwogICAgICAgIH0KICAgIH0KICAgIGZvcihpbnQgajE9ai0xO2oxPj0wO2oxLS0pewogICAgICAgIGlmKGFycltpXVtqMV0gPT0gMSl7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH1lbHNlewogICAgICAgICAgICBhcnJbaV1bajFdID0gMTsKICAgICAgICB9CiAgICB9CiAgICBmb3IoaW50IGkxID0gaS0xO2kxID49IDA7aTEtLSl7CiAgICAgICAgaW50IGoxID0gai0gKGktaTEpOwogICAgICAgIGlmKGoxIDwwKXsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIGlmKGFycltpMV1bajFdID09IDEpewogICAgICAgICAgICBicmVhazsKICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgYXJyW2kxXVtqMV0gPSAxOwogICAgICAgICAgICAKICAgICAgICB9CiAgICB9CiAgICBmb3IoaW50IGkxID0gaS0xO2kxID49IDA7aTEtLSl7CiAgICAgICAgaW50IGoxID0gaisgKGktaTEpOwogICAgICAgIGlmKGoxID49Yil7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBpZihhcnJbaTFdW2oxXSA9PSAxKXsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfWVsc2V7CiAgICAgICAgICAgIGFycltpMV1bajFdID0gMTsKICAgICAgICB9CiAgICB9CiAgICBmb3IoaW50IGkxID0gaSsxOyBpMSA8YTtpMSsrKXsKICAgICAgICBpbnQgajEgPSBqLShpMS1pKTsKICAgICAgICBpZihqMSA8MCl7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBpZihhcnJbaTFdW2oxXSA9PSAxICl7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH1lbHNlewogICAgICAgICAgICBhcnJbaTFdW2oxXSA9IDE7CiAgICAgICAgfQogICAgfQogICAgZm9yKGludCBpMSA9IGkrMTsgaTEgPCBhO2kxKyspewogICAgICAgIGludCBqMSA9IGorKGkxLWkpOwogICAgICAgIGlmKGoxID49IGIpewogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgaWYoYXJyW2kxXVtqMV0gPT0gMSB8fCBqMSA+PWIpewogICAgICAgICAgICBicmVhazsKICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgYXJyW2kxXVtqMV0gPSAxOwogICAgICAgIH0KICAgIH0KfQppbnQgcmV0X3ZhbCgpewogICAgaW50IHJlcyA9IDA7CiAgICBmb3IoaW50IGk9MDtpPGE7aSsrKXsKICAgICAgICBmb3IoaW50IGo9MDtqPGI7aisrKXsKICAgICAgICAgICAgaWYoYXJyW2ldW2pdID09IDApewogICAgICAgICAgICAgICAgcmVzKys7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gcmVzOwp9CmludCBtYWluKCl7CiAgICAvL2ZyZW9wZW4oImlucHV0LnR4dCIsInIiLHN0ZGluKTsKICAgIGludCB0ZXN0ID0gMTsKICAgIHNjYW5mKCIlZCAlZCIsJmEsJmIpOwogICAgd2hpbGUoYSA+MCAmJiBiID4gMCl7CiAgICAgICAgbWVtc2V0KGFyciwwLHNpemVvZihhcnIpKTsKICAgICAgICBpbnQgbnVtX3EsbnVtX2ssbnVtX3A7CiAgICAgICAgaW50IGFycjFbMjAyXSxhcnIyWzIwMl0sYXJyM1syMDJdOwogICAgICAgIHNjYW5mKCIlZCIsJm51bV9xKTsKICAgICAgICBmb3IoaW50IGk9MDtpPDIqbnVtX3E7aSsrKXsKICAgICAgICAgICAgc2NhbmYoIiVkIiwmYXJyMVtpXSk7CiAgICAgICAgfQogICAgICAgIHNjYW5mKCIlZCIsJm51bV9rKTsKICAgICAgICBmb3IoaW50IGk9MDtpPDIqbnVtX2s7aSsrKXsKICAgICAgICAgICAgc2NhbmYoIiVkIiwmYXJyMltpXSk7CiAgICAgICAgfQogICAgICAgIHNjYW5mKCIlZCIsJm51bV9wKTsKICAgICAgICBmb3IoaW50IGk9MDtpPDIqbnVtX3A7aSsrKXsKICAgICAgICAgICAgc2NhbmYoIiVkIiwmYXJyM1tpXSk7CiAgICAgICAgfQogICAgICAgIC8vU2NhbiBQCiAgICAgICAgZm9yKGludCBpPTA7aTxudW1fcDtpKyspewogICAgICAgICAgICBzY2FuX1AoYXJyM1syKmldLTEsYXJyM1syKmkrMV0tMSk7CiAgICAgICAgfQoKICAgICAgICBmb3IoaW50IGk9MDtpPG51bV9rO2krKyl7CiAgICAgICAgICAgIGFyclthcnIyWzIqaV0tMV1bYXJyMlsyKmkrMV0tMV0gPSAxOyAgCiAgICAgICAgfQogICAgICAgIC8vU2Nhbl9RCiAgICAgICAgZm9yKGludCBpPTA7aTxudW1fcTtpKyspewogICAgICAgICAgICBzY2FuX1EoYXJyMVsyKmldLTEsYXJyMVsyKmkrMV0tMSk7CiAgICAgICAgfQogICAgICAgIC8vU2NhTiBLCiAgICAgICAgZm9yKGludCBpPTA7aTxudW1faztpKyspewogICAgICAgICAgICBzY2FuX0soYXJyMlsyKmldLTEsYXJyMlsyKmkrMV0tMSk7ICAvLyAxIDQgMCAzCiAgICAgICAgfQogICAgICAgIC8vIGZvcihpbnQgaT0wO2k8YTtpKyspewogICAgICAgIC8vICAgICBmb3IoaW50IGo9MDtqPGI7aisrKXsKICAgICAgICAvLyAgICAgICAgIHByaW50ZigiJWQgIixhcnJbaV1bal0pOwogICAgICAgIC8vICAgICB9CiAgICAgICAgLy8gICAgIHByaW50ZigiXG4iKTsKICAgICAgICAvLyB9CiAgICAgICAgcHJpbnRmKCJCb2FyZCAlZCBoYXMgJWQgc2FmZSBzcXVhcmVzLlxuIix0ZXN0LHJldF92YWwoKSk7CiAgICAgICAgdGVzdCsrOwogICAgICAgIHNjYW5mKCIlZCAlZCIsJmEsJmIpOwoKICAgIH0KICAgIHJldHVybiAwOwp9