Paths Through a Blocked Grid
You are given a grid of n rows and m columns. Every cell is either free (.) or blocked (#).
A path starts in the top-left cell, ends in the bottom-right cell, and at every step moves exactly one cell right or down. A path is allowed only if every cell it visits, including the first and the last, is free.
Count the allowed paths. The number can be huge, so print it modulo 10^9+7.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 2000).
Each of the next n lines contains a string of exactly m characters, each . or #, describing one row of the grid from top to bottom.
Output
Print one integer: the number of allowed paths modulo 10^9+7. If there are none, which includes the case where the top-left or the bottom-right cell is blocked, print 0.
Notes
In the first example the grid has 10 right/down paths in total; 6 of them pass through the blocked cell, leaving 4.
In the second example the three paths are RRRDDD, RDDRRD and RDDRDR, where R is a step right and D a step down.
In the third example the bottom-right cell is blocked, so no path is allowed.
When n = m = 1 there is exactly one path (the empty one) if the only cell is free.