Buggy python submission (verdict: Runtime Error):
def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)


Fixed submission:
import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)

Buggy python submission (verdict: Runtime Error):
def valid(i,j):
    if i>=0 and i<h and j>=0 and j<w:
        return 1
    return 0
def paths(i,j):
 
    if valid(i,j)==0 or a[i][0][j]=='#':
        return 0
    if i==h-1 and j==w-1:
        return 1

    if dp[i][j]==-1:
           a1=0
           a1+=paths(i+1,j)%m
           a1+=paths(i,j+1)%m
           dp[i][j]=a1%m
           return dp[i][j]
    else:
            return dp[i][j]



h,w=map(int,input().split())
a=[[]for _ in range(h)]
m=1000000007
for i in range(h):
   a[i].extend(input().split())
dp=[[-1 for _ in range(1000)]for _ in range(1000)]
print(paths(0,0))

Fixed submission:
import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)

Buggy python submission (verdict: Runtime Error):
def valid(i,j):
    if i>=0 and i<h and j>=0 and j<w:
        return 1
    return 0
def paths(i,j):

    if valid(i,j)==0 or  a[i][0][j]=='#':
        return 0
    if i==h-1 and j==w-1:
        return 1

    if dp[i][j]==-1:
           a=0
           a+=paths(i+1,j)%m
           a+=paths(i,j+1)%m
           dp[i][j]=a%m
           return dp[i][j]
    else:
            return dp[i][j]



h,w=map(int,input().split())
a=[[]for _ in range(h)]
m=1000000007
for i in range(h):
   a[i].extend(input().split())
dp=[[-1 for _ in range(1000)]for _ in range(1000)]
print(paths(0,0))


Fixed submission:
import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)

Buggy python submission (verdict: Runtime Error):
def valid(i,j):
    if i>=0 and i<h and j>=0 and j<w:
        return 1
    return 0
def paths(i,j):

    if valid(i,j)==0 or  a[i][0][j]=='#':
        return 0
    if i==h-1 and j==w-1:
        return 1

    if dp[i][j]==-1:
           dp[i][j]=(paths(i+1,j)%m+paths(i,j+1)%m)%m
           return dp[i][j]
    else:
            return dp[i][j]



h,w=map(int,input().split())
a=[[]for _ in range(h)]
m=1000000007
for i in range(h):
   a[i].extend(input().split())
dp=[[-1 for _ in range(1000)]for _ in range(1000)]
print(paths(0,0))

Fixed submission:
import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)

Buggy python submission (verdict: Runtime Error):
def valid(i,j):
    if i>=0 and i<h and j>=0 and j<w:
        return 1
    return 0
def paths(i,j):

    if valid(i,j)==0 or  a[i][0][j]=='#':
        return 0
    if i==h-1 and j==w-1:
        return 1

    if dp[i][j]==-1:
           dp[i][j]=(paths(i+1,j)%m+paths(i,j+1)%m)%m
           return dp[i][j]
    else:
            return dp[i][j]



h,w=map(int,input().split())
a=[[]for _ in range(h)]
m=1000000007
for i in range(h):
   a[i].extend(input().split())
dp=[[-1 for _ in range(w+1)]for _ in range(h+1)]
print(paths(0,0))


Fixed submission:
import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)

Buggy python submission (verdict: Runtime Error):
def valid(i,j):
    if i>=0 and i<h and j>=0 and j<w:
        return 1
    return 0
def paths(i,j):

    if valid(i,j)==0 or  a[i][0][j]=='#':
        return 0
    if i==h-1 and j==w-1:
        return 1

    if dp[i][j]==-1:
           dp[i][j]=(paths(i+1,j)%m+paths(i,j+1)%m)%m
           return dp[i][j]
    else:
            return dp[i][j]



h,w=map(int,input().split())
a=[[]for _ in range(h)]
m=1000000007
for i in range(h):
   a[i].extend(input().split())
dp=[[-1 for _ in range(w)]for _ in range(h)]
print(paths(0,0))


Fixed submission:
import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)

Buggy python submission (verdict: Runtime Error):
def valid(i,j):
    if i>=0 and i<h and j>=0 and j<w:
        return 1
    return 0
def paths(i,j):
 
    if valid(i,j)==0 or  a[i][0][j]=='#':
        return 0
    if i==h-1 and j==w-1:
        return 1

    if dp[i][j]==-1:
           dp[i][j]=paths(i+1,j)+paths(i,j+1)
           return dp[i][j]
    else:
            return dp[i][j]



h,w=map(int,input().split())
a=[[]for _ in range(h)]
m=1000000007
for i in range(h):
   a[i].extend(input().split())
dp=[[-1 for _ in range(w)]for _ in range(h)]
print(paths(0,0)%m)


Fixed submission:
import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)

Buggy python submission (verdict: Runtime Error):
def valid(i,j):
    if i>=0 and i<h and j>=0 and j<w:
        return 1
    return 0
def paths(i,j):

    if a[i][0][j]=='#' or valid(i,j)==0:
        return 0
    if i==h-1 and j==w-1:
        return 1
    
    if dp[i][j]==-1:
           dp[i][j]=paths(i+1,j)+paths(i,j+1)
           return dp[i][j]
        else:
            return dp[i][j]
   


h,w=map(int,input().split())
a=[[]for _ in range(h)]
m=1000000007
for i in range(h):
   a[i].extend(input().split())
dp=[[-1 for _ in range(w+1)]for _ in range(h+1)]
print(paths(0,0)%m)


Fixed submission:
import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)

Buggy python submission (verdict: Runtime Error):
def valid(i,j):
    if i>=0 and i<h and j>=0 and j<w:
        return 1
    return 0
def paths(i,j):

    if a[i][0][j]=='#' or valid(i,j)==0:
        return 0
    if i==h-1 and j==w-1:
        return 1
    if i<h-1 and j<w-1:
        if dp[i][j]==-1:
          dp[i][j]=paths(i+1,j)+paths(i,j+1)
          return dp[i][j]
        else:
            return dp[i][j]
    if i==h-1 and j<w-1:
        if dp[i][j]==-1:
            dp[i][j]=paths(i,j+1)
            return dp[i][j]
        else:
            return dp[i][j]
    if i<h-1 and j==w-1:
        if dp[i][j]==-1:
            dp[i][j]=paths(i+1,j)
            return dp[i][j]
        else:
            return dp[i][j]


h,w=map(int,input().split())
a=[[]for _ in range(h)]
m=1000000007
for i in range(h):
   a[i].extend(input().split())
dp=[[-1 for _ in range(w+1)]for _ in range(h+1)]
print(paths(0,0)%m)


Fixed submission:
import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)

Buggy python submission (verdict: Runtime Error):
def valid(i,j):
    if i>=0 and i<h and j>=0 and j<w:
        return 1
    return 0
def paths(i,j):

    if a[i][0][j]=='#' or valid(i,j)==0:
        return 0
    if i==h-1 and j==w-1:
        return 1
    if i<h-1 and j<w-1:
        if dp[i][j]==-1:
          dp[i][j]=paths(i+1,j)+paths(i,j+1)
          return dp[i][j]
        else:
            return dp[i][j]
    if i==h-1 and j<w-1:
        if dp[i][j]==-1:
           dp[i][j]=paths(i,j+1)
           return dp[i][j]
        else:
            return dp[i][j]
    if i<h-1 and j==w-1:
        if dp[i][j]==-1:
           dp[i][j]=paths(i+1,j)
           return dp[i][j]
        else:
            return dp[i][j]


h,w=map(int,input().split())
a=[[]for _ in range(h)]
m=1000000007
for i in range(h):
   a[i].extend(input().split())
dp=[[-1 for _ in range(w)]for _ in range(h)]
print(paths(0,0)%m)


Fixed submission:
import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)

Buggy python submission (verdict: Runtime Error):
def valid(i,j):
    if i>=0 and i<h and j>=0 and j<w:
        return 1
    return 0
def paths(i,j):

    if a[i][0][j]=='#' or valid(i,j)==0:
        return 0
    if i==h-1 or j==w-1:
        return 1
    else:
        if dp[i][j]==-1:
          dp[i][j]=paths(i+1,j)+paths(i,j+1)
          return dp[i][j]
        else:
            return dp[i][j]
    '''elif i==h-1 and j<w-1:
        if dp[i][j]==-1:
           dp[i][j]=paths(i,j+1)
           return dp[i][j]
        else:
            return dp[i][j]
    elif i<h-1 and j==w-1:
        if dp[i][j]==-1:
           dp[i][j]=paths(i+1,j)
           return dp[i][j]
        else:
            return dp[i][j]'''


h,w=map(int,input().split())
a=[[]for _ in range(h)]
m=1000000007
for i in range(h):
   a[i].extend(input().split())
dp=[[-1 for _ in range(w)]for _ in range(h)]
print(paths(0,0)%m)

Fixed submission:
import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)

Buggy python submission (verdict: Runtime Error):
def valid(i,j):
    if i>=0 and i<h and j>=0 and j<w:
        return 1
    return 0
def paths(i,j):

    if a[i][0][j]=='#' or valid(i,j)==0:
        return 0
    if i==h-1 and j==w-1:
        return 1
    else:
        if dp[i][j]==-1:
          dp[i][j]=(paths(i+1,j)+paths(i,j+1))%m
          return dp[i][j]
        else:
            return dp[i][j]
    '''elif i==h-1 and j<w-1:
        if dp[i][j]==-1:
           dp[i][j]=paths(i,j+1)
           return dp[i][j]
        else:
            return dp[i][j]
    elif i<h-1 and j==w-1:
        if dp[i][j]==-1:
           dp[i][j]=paths(i+1,j)
           return dp[i][j]
        else:
            return dp[i][j]'''


h,w=map(int,input().split())
a=[[]for _ in range(h)]
m=1000000007
for i in range(h):
   a[i].extend(input().split())
dp=[[-1 for _ in range(w)]for _ in range(h)]
print(paths(0,0)%m)

Fixed submission:
import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)

Buggy python submission (verdict: Runtime Error):
def paths(i,j):

    if a[i][0][j]=='#':
        return 0
    if i==h-1 and j==w-1:
        return 1
    if i<h-1 and j<w-1:
        if dp[i][j]==-1:
          dp[i][j]=paths(i+1,j)+paths(i,j+1)
          return dp[i][j]
        else:
            return dp[i][j]
    elif i==h-1 and j<w-1:
        if dp[i][j]==-1:
           dp[i][j]=paths(i,j+1)
           return dp[i][j]
        else:
            return dp[i][j]
    elif i<h-1 and j==w-1:
        if dp[i][j]==-1:
           dp[i][j]=paths(i+1,j)
           return dp[i][j]
        else:
            return dp[i][j]


h,w=map(int,input().split())
a=[[]for _ in range(h)]
m=1000000007
for i in range(h):
   a[i].extend(input().split())
dp=[[-1 for _ in range(w)]for _ in range(h)]
print(paths(0,0)%m)


Fixed submission:
import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)

Buggy python submission (verdict: Runtime Error):
def paths(i,j):

    if a[i][0][j]=='#':

        return 0
    if i==h-1 and j==w-1:
        return 1
    if i<h-1 and j<w-1:
        if dp[i][j]==-1:
          dp[i][j]=paths(i+1,j)+paths(i,j+1)
          return dp[i][j]
        else:
            return paths(i+1,j)+paths(i,j+1)
    elif i==h-1 and j<w-1:
        if dp[i][j]==-1:
           dp[i][j]=paths(i,j+1)
           return dp[i][j]
        else:
            return dp[i][j]
    elif i<h-1 and j==w-1:
        if dp[i][j]==-1:
           dp[i][j]=paths(i+1,j)
           return dp[i][j]
        else:
            return dp[i][j]


h,w=map(int,input().split())
a=[[]for _ in range(h)]
m=1000000007
for i in range(h):
   a[i].extend(input().split())
dp=[[-1 for _ in range(w)]for _ in range(h)]
print(paths(0,0)%m)

Fixed submission:
import sys
sys.setrecursionlimit(20000)

def paths(i, j):

    if i == h - 1 and j == w - 1:
        return 1
    if a[i][0][j] == '#':
        return 0
    if i < h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j) + paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i == h - 1 and j < w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i, j + 1)
            return dp[i][j]
        else:
            return dp[i][j]
    elif i < h - 1 and j == w - 1:
        if dp[i][j] == -1:
            dp[i][j] = paths(i + 1, j)
            return dp[i][j]
        else:
            return dp[i][j]


h, w = map(int, input().split())
a = [[] for _ in range(h)]
m = 1000000007
for i in range(h):
    a[i].append(input())
dp = [[-1 for _ in range(1000)] for _ in range(1000)]
print(paths(0, 0) % m)