Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/matritsa-yollar-soni

Number of paths

Medium 1000 ms 64 MB 63%
Share

A grid of size $n \times m$ is given: . is a free cell, # is an obstacle. A robot wants to go from the top-left cell to the bottom-right cell; it moves only right or down and only through free cells. How many different paths are there? The answer may be large, so print it modulo $10^{9} + 7$. If the start or the finish cell is an obstacle, the answer is $0$.

A grid with obstacles; one of the right-and-down paths from the top-left to the bottom-right corner is highlighted

Input

The first line contains two positive integers $n$ and $m$.
Each of the next $n$ lines contains a string of $m$ characters (. or #).

Output

One integer — the number of paths modulo $10^{9} + 7$.

Note

$1 \le n, m \le 100$

Examples

Input #1
3 4
....
.#..
....
Output #1
4
Input #2
2 2
.#
#.
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.