A warehouse floor is a grid of rows by cols cells. Each cell is one of: . (open floor), # (a shelf, blocked), R (the robot's single starting cell), or C (a charging station; there may be several). Exactly one cell is R and at least one cell is C.
The robot moves one cell per step, up, down, left, or right, and may only move onto a cell that is . or C (never onto #). Find the minimum number of steps for the robot to reach ANY charging station. If no charging station is reachable, output -1.
Input format
Line 1: two integers rows and cols.
Next rows lines: a string of exactly cols characters, each one of ., #, R, C.
Output format
A single integer: the minimum number of steps from R to the nearest reachable C, or -1 if none is reachable.
Constraints
- 1 ≤ rows, cols ≤ 12
- exactly one cell is
R; at least one cell isC