#K56387. Traffic Lights Maximum Manhattan Distance

    ID: 30187 Type: Default 1000ms 256MiB

Traffic Lights Maximum Manhattan Distance

Traffic Lights Maximum Manhattan Distance

In the city of Codeville, there is a grid of intersections arranged in n rows and m columns. Some intersections have traffic lights. Your task is to compute the maximum Manhattan distance from any intersection without a traffic light to the nearest intersection where a traffic light is present.

Recall that the Manhattan distance between two points ((x_1, y_1)) and ((x_2, y_2)) is given by:

[ |x_1 - x_2| + |y_1 - y_2| ]

If every intersection has a traffic light, then the maximum distance is 0.

inputFormat

The input is read from standard input (stdin). The first line contains three integers (n), (m) and (k), where (n) and (m) define the grid dimensions and (k) is the number of intersections with traffic lights. The next (k) lines each contain two integers representing the row and column indices (1-indexed) of an intersection with a traffic light.

outputFormat

Output a single integer to standard output (stdout) which is the maximum Manhattan distance from any intersection without a traffic light to its nearest intersection with a traffic light.## sample

4 4 3
1 2
3 4
4 1
2

</p>