Under construction

Still being built. Things may change

Forest Fire

Interview

Time limit3sMemory limit1024 MB

Summary
On an infinite grid where fire spreads to four neighbors and cut trees block it, count the trees still burning after T minutes.
Level

Medium4 of 10

Topics
Graph, BFS, Hash map
Solved
No attempts yet

Problem

A forest fire has broken out in the integer forest! The integer forest is an infinitely large two-dimensional plane with a tree at every point with integer coordinates. Right now NN of these trees are burning. Every minute, fire spreads from each burning tree to its four neighbors: the trees directly north, east, west, and south. To stop the fire, the fire brigade has cut down MM trees. A cut-down tree cannot catch fire, so these points act as a wall. You want to know how much damage the fire will cause. In TT minutes, a heavy rainstorm will put out the whole fire. So you want to know how many trees are burning after TT minutes.

Input

The first line contains three integers: the number of burning trees NN (1≤N≤1001 \leq N \leq 100), the number of cut-down trees MM (0≤M≤1000 \leq M \leq 100), and the number of minutes TT until the heavy rain (0≤T≤1090 \leq T \leq 10^9). The next NN lines each contain two integers xi,yix_i, y_i (0≤xi,yi<1050 \leq x_i, y_i < 10^5), the coordinates of a burning tree. The next MM lines each contain two integers xi,yix_i, y_i (0≤xi,yi<1050 \leq x_i, y_i < 10^5), the coordinates of a cut-down tree. No two trees, whether burning or cut down, share the same coordinates.

Output

Print one integer, the number of trees that are burning after TT minutes.

Hint

In the first example, the fire spreads to (0,2)(0,2), (1,3)(1,3), and (2,2)(2,2). That makes 4 burning trees in total. In the second example, the only burning tree is surrounded by cut-down trees. So only one tree burns, even though TT is very large. In the third example, the fire does not spread because T=0T = 0, so the answer is 4.

Examples4

  1. Example 1

    Input
    1 1 1
    1 2
    1 1
    
    Expected output
    4
    
  2. Example 2

    Input
    1 4 12345678
    2 2
    1 2
    2 1
    2 3
    3 2
    
    Expected output
    1
    
  3. Example 3

    Input
    4 1 0
    1 1
    1 2
    2 3
    3 4
    7 7
    
    Expected output
    4
    
  4. Example 4

    Input
    1 2 100000
    0 0
    2 1
    1 2
    
    Expected output
    20000199999