#C11034. School Location Optimization

    ID: 40306 Type: Default 1000ms 256MiB

School Location Optimization

School Location Optimization

You are given an n × n grid representing a city map. Each cell of the grid is either a building, denoted by B, or an empty plot, denoted by .. Your task is to choose an empty plot to build a school such that the maximum Manhattan distance from the school to any building is minimized.

The Manhattan distance between two points with coordinates \( (x_1, y_1) \) and \( (x_2, y_2) \) is defined as:

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

If there are no buildings on the map, the answer is 0. If there is no empty plot available (i.e. every cell is a building), output inf (representing an infinite distance).

inputFormat

The first line contains an integer n (the size of the grid).
The following n lines each contain a string of length n representing a row of the city map. Each character is either B (a building) or . (an empty plot).

outputFormat

Output a single line containing the minimum possible maximum Manhattan distance from any building to the school. If no empty plot exists, output inf (without quotes).

## sample
3
B..
...
..B
2

</p>