Forest Fire
InterviewTime limit3sMemory limit1024 MB
On an infinite grid where fire spreads to four neighbors and cut trees block it, count the trees still burning after T minutes.
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 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 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 minutes, a heavy rainstorm will put out the whole fire. So you want to know how many trees are burning after minutes.
Input
The first line contains three integers: the number of burning trees (), the number of cut-down trees (), and the number of minutes until the heavy rain (). The next lines each contain two integers (), the coordinates of a burning tree. The next lines each contain two integers (), 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 minutes.
Hint
In the first example, the fire spreads to , , and . 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 is very large. In the third example, the fire does not spread because , so the answer is 4.