Zombie Apocalypse

Given up to 2000 zombie cells on an N by M grid with Chebyshev distance spreading, count how many cells end up at level Q.

Hard8GeometrySortingImplementationMathNo attempts yetTime limit2sMemory limit512 MB

Problem

Your country has zombies, and that is the problem. You work at the Forensic Institute for Zoology and Zombie Emerging Studies (FIZZES), and your job is to report how bad the situation is.

The country is mapped onto an N×MN \times M grid of cells, and every cell gets one non-negative integer. You know the exact location of every zombie, and no two zombies share a cell. The numbers are written in this order.

  • Every cell holding a zombie is marked 00.
  • Every unmarked cell touching a cell marked 00 is marked 11.
  • Every unmarked cell touching a cell marked 11 is marked 22.
  • This repeats until every cell carries a number.

Two cells touch when they share a side or a corner, so one cell touches up to eight cells. The number in a cell is the level of concern the institute has about zombie spread at that spot.

For N=5N = 5, M=6M = 6 with zombies in row 2 column 4 and row 3 column 3, the numbers come out like this.

2 2 1 1 1 2
2 1 1 0 1 2
2 1 0 1 1 2
2 1 1 1 2 2
2 2 2 2 2 3

Your boss gives you an integer QQ. Determine how many cells are marked with QQ.

Input

The first line contains two space-separated integers NN and MM (1N1091 \le N \le 10^9, 1M1091 \le M \le 10^9), the number of rows and the number of columns of the grid.

The second line contains KK (1K20001 \le K \le 2000), the number of zombies.

Each of the next KK lines contains two space-separated integers rir_i and cic_i (1riN1 \le r_i \le N, 1ciM1 \le c_i \le M), the row and the column of the ii-th zombie. No two zombies share a cell, so (ri,ci)(rj,cj)(r_i, c_i) \ne (r_j, c_j) whenever iji \ne j.

The last line contains the integer QQ (0QN+M0 \le Q \le N + M).

Output

Print the number of cells in the grid that are marked with QQ.