#include #include #define max(a, b) ((a) >= (b) ? (a) : (b)) #define min(a, b) ((a) <= (b) ? (a) : (b)) int main() { int p_x, p_y, q_x, q_y; long unsigned p_queens, p_poss; long unsigned i, j; long posun; while (scanf("%d%d%lu\n", &p_x, &p_y, &p_queens), p_x != 0 || p_y != 0 || p_queens != 0) { int **pole; pole = (int**) malloc (p_x * sizeof(int*)); for (i = 0; i < p_x; i++) { pole[i] = (int*) malloc (p_y * sizeof(int)); for (j = 0; j < p_y; j++) pole[i][j] = 1; } for (i = 0; i < p_queens; i++) { scanf("%d%d\n", &q_x, &q_y); q_x--; q_y--; for (j = 0; j < p_y; j++) pole[q_x][j] = 0; for (j = 0; j < p_x; j++) pole[j][q_y] = 0; posun = q_x - q_y; for (j = max(0, -posun); j < min(p_y, p_x - posun); j++) pole[posun+j][j] = 0; posun = q_x + q_y; for (j = max(0, posun - p_x + 1); j < min(p_y, posun + 1); j++) pole[posun-j][j] = 0; } p_poss = 0; for (i = 0; i < p_x; i++) for (j = 0; j < p_y; j++) if (pole[i][j]) p_poss++; printf("%lu\n", p_poss); } return 0; }