#P1225E. Rock Is Push
Rock Is Push
Description
You are at the top left cell of an labyrinth. Your goal is to get to the bottom right cell . You can only move right or down, one cell per step. Moving right from a cell takes you to the cell , while moving down takes you to the cell .
Some cells of the labyrinth contain rocks. When you move to a cell with rock, the rock is pushed to the next cell in the direction you're moving. If the next cell contains a rock, it gets pushed further, and so on.
The labyrinth is surrounded by impenetrable walls, thus any move that would put you or any rock outside of the labyrinth is illegal.
Count the number of different legal paths you can take from the start to the goal modulo . Two paths are considered different if there is at least one cell that is visited in one path, but not visited in the other.
The first line contains two integers — dimensions of the labyrinth ().
Next lines describe the labyrinth. Each of these lines contains characters. The -th character of the -th of these lines is equal to "R" if the cell contains a rock, or "." if the cell is empty.
It is guaranteed that the starting cell is empty.
Print a single integer — the number of different legal paths from to modulo .
Input
The first line contains two integers — dimensions of the labyrinth ().
Next lines describe the labyrinth. Each of these lines contains characters. The -th character of the -th of these lines is equal to "R" if the cell contains a rock, or "." if the cell is empty.
It is guaranteed that the starting cell is empty.
Output
Print a single integer — the number of different legal paths from to modulo .
Note
In the first sample case we can't (and don't have to) move, hence the only path consists of a single cell .
In the second sample case the goal is blocked and is unreachable.
Illustrations for the third sample case can be found here: https://assets.codeforces.com/rounds/1225/index.html