A fire has broken out on the farm, and the cows are rushing to help put it out! The farm is described by a 10 \times 10 grid of characters, as shown below:
..........
..........
..........
..B.......
..........
.....R....
..........
..........
.....L....
..........The character represents the barn, which has just caught fire. The character represents the lake, and represents the location of a large rock.
The cows want to form a "bucket brigade" by positioning themselves along a path between the lake and the barn, allowing them to pass buckets of water along the path to help extinguish the fire. A bucket can be passed between two cows if they are immediately adjacent to each other in one of the four cardinal directions: north, south, east, or west.
Similarly, a cow can take a bucket of water from the lake only if she is immediately adjacent to the lake. A cow can throw a bucket of water onto the barn only if she is immediately adjacent to the barn.
Determine the minimum number of "." squares that must be occupied by cows to form a successful bucket brigade.
A cow cannot be placed on the square containing the large rock. The barn and the lake are guaranteed not to be immediately adjacent to each other.
Consists of rows, each containing characters, describing the layout of the farm.
Print one integer representing the minimum number of cows needed to form a viable bucket brigade.
Here is one possible solution, using the optimal number of cows ():
..........
..........
..........
..B.......
..C.......
..CC.R....
...CCC....
.....C....
.....L....
..........Example 1