<p>There is an <code>m x n</code> grid with a ball. The ball is initially at the position <code>[startRow, startColumn]</code>. You are allowed to move the ball to one of the four adjacent cells in the grid (possibly out of the grid crossing the grid boundary). You can apply <strong>at most</strong> <code>maxMove</code> moves to the ball.</p>

<p>Given the five integers <code>m</code>, <code>n</code>, <code>maxMove</code>, <code>startRow</code>, <code>startColumn</code>, return the number of paths to move the ball out of the grid boundary. Since the answer can be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/04/28/out_of_boundary_paths_1.png" style="width: 500px; height: 296px;" />
<pre>
<strong>Input:</strong> m = 2, n = 2, maxMove = 2, startRow = 0, startColumn = 0
<strong>Output:</strong> 6
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/04/28/out_of_boundary_paths_2.png" style="width: 500px; height: 293px;" />
<pre>
<strong>Input:</strong> m = 1, n = 3, maxMove = 3, startRow = 0, startColumn = 1
<strong>Output:</strong> 12
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= m, n &lt;= 50</code></li>
	<li><code>0 &lt;= maxMove &lt;= 50</code></li>
	<li><code>0 &lt;= startRow &lt; m</code></li>
	<li><code>0 &lt;= startColumn &lt; n</code></li>
</ul>

class Solution:
    def findPaths(self, m: int, n: int, maxMove: int, startRow: int, startColumn: int) -> int:

        if maxMove == 0:
            return 0

        modvalue = (10**9 + 7)
        dp1 = [ [0] * n for _ in range(m) ]
        dp2 = [ [0] * n for _ in range(m) ]

        def getCell(matrix,i,j):
            if i<0 or i>=len(matrix):
                return 0
            if j<0 or j>=len(matrix[i]):
                return 0
            return matrix[i][j]

        for i in range(m):
            dp1[i][0] += 1
            dp1[i][n-1] += 1

        for j in range(n):
            dp1[0][j] += 1
            dp1[m-1][j] += 1

        def step(fromMatrix, toMatrix):
            for i in range(m):
                for j in range(n):
                    toMatrix[i][j] = (getCell(fromMatrix,i-1,j) + getCell(fromMatrix,i+1,j) + getCell(fromMatrix,i,j-1) + getCell(fromMatrix,i,j+1)) % modvalue

        fromMatrix = dp1
        toMatrix = dp2
        result = fromMatrix[startRow][startColumn]

        for _ in range(maxMove-1):
            step(fromMatrix,toMatrix)
            result = (result + toMatrix[startRow][startColumn]) % modvalue
            t = fromMatrix
            fromMatrix = toMatrix
            toMatrix = t

        return result
16900