Problem:
Score : 100 points

Problem Statement

There is a grid with H horizontal rows and W vertical columns.
Let (i, j) denote the square at the i-th row from the top and the j-th column from the left.

For each i and j (1 \leq i \leq H, 1 \leq j \leq W), Square (i, j) is described by a character a_{i, j}.
If a_{i, j} is ., Square (i, j) is an empty square; if a_{i, j} is #, Square (i, j) is a wall square.
It is guaranteed that Squares (1, 1) and (H, W) are empty squares.

Taro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square.

Find the number of Taro's paths from Square (1, 1) to (H, W).
As the answer can be extremely large, find the count modulo 10^9 + 7.

Constraints

H and W are integers.

2 \leq H, W \leq 1000

a_{i, j} is . or #.

Squares (1, 1) and (H, W) are empty squares.

Input

Input is given from Standard Input in the following format:

H W
a_{1, 1}\ldotsa_{1, W}
:
a_{H, 1}\ldotsa_{H, W}

Output

Print the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.

Sample Input 1

3 4
...#
.#..
....

Sample Output 1

3

There are three paths as follows:

Sample Input 2

5 2
..
#.
..
.#
..

Sample Output 2

0

There may be no paths.

Sample Input 3

5 5
..#..
.....
#...#
.....
..#..

Sample Output 3

24

Sample Input 4

20 20
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................

Sample Output 4

345263555

Be sure to print the count modulo 10^9 + 7.

Solution in Rust (1.15.1) (judge verdict: Accepted)

#![allow(non_snake_case)]

use std::cmp;

#[allow(dead_code)]
pub struct Scanner<'a> {
    _buf: &'a str,
    iter: ::std::str::SplitWhitespace<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    pub fn new(buf: &'a str) -> Self {
        Scanner {
            _buf: buf,
            iter: buf.split_whitespace(),
        }
    }

    pub fn array<T>(&mut self, n: usize) -> Vec<T>
        where T: ::std::str::FromStr,
              T::Err: ::std::fmt::Debug,
    {
        let mut res = Vec::with_capacity(n);
        for _ in 0..n {
            res.push(self.value());
        }
        res
    }

    pub fn value<T>(&mut self) -> T
        where T: ::std::str::FromStr,
              T::Err: ::std::fmt::Debug,
    {
        self.next().parse().unwrap()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.next().chars().collect()
    }

    fn next(&mut self) -> &str {
        self.iter.next().unwrap()
    }
}

#[allow(dead_code)]
const INF: i64 = 1_010_000_000_000_000_000;

#[allow(dead_code)]
const MOD: i64 = 1_000_000_007;

struct Solver {
    M: Vec<Vec<char>>,
    memo: Vec<Vec<Option<i64>>>,
}

impl Solver {
    fn new(H: i64, W: i64, M: Vec<Vec<char>>) -> Self {
        Solver {
            M: M,
            memo: vec![vec![None; H as usize]; W as usize],
        }
    }

    fn f(&mut self, x: i64, y: i64) -> i64 {
        if x == 0 && y == 0 { return 1; }

        if self.memo[x as usize][y as usize].is_none() {
            let mut res = 0;
            if x > 0 && self.M[y as usize][(x-1) as usize] != '#' {
                res += self.f(x-1,y);
                res %= MOD;
            }
            if y > 0 && self.M[(y-1) as usize][x as usize] != '#' {
                res += self.f(x,y-1);
                res %= MOD;
            }
            self.memo[x as usize][y as usize] = Some(res);
        }
        self.memo[x as usize][y as usize].unwrap()
    }
}

fn main() {
    let mut _input = String::new();
    {
        use ::std::io::Read;
        ::std::io::stdin().read_to_string(&mut _input).unwrap();
    }
    let mut sc = Scanner::new(&_input);

    let H = sc.value::<i64>();
    let W = sc.value::<i64>();
    let mut M = Vec::with_capacity(H as usize);
    for _ in 0..H {
        M.push(sc.chars());
    }

    let mut sol = Solver::new(H, W, M);
    let ans = sol.f(W-1,H-1);

    println!("{}", ans);
}