<p>You are given 3 positive integers <code>zero</code>, <code>one</code>, and <code>limit</code>.</p>

<p>A <span data-keyword="binary-array">binary array</span> <code>arr</code> is called <strong>stable</strong> if:</p>

<ul>
	<li>The number of occurrences of 0 in <code>arr</code> is <strong>exactly </strong><code>zero</code>.</li>
	<li>The number of occurrences of 1 in <code>arr</code> is <strong>exactly</strong> <code>one</code>.</li>
	<li>Each <span data-keyword="subarray-nonempty">subarray</span> of <code>arr</code> with a size greater than <code>limit</code> must contain <strong>both </strong>0 and 1.</li>
</ul>

<p>Return the <em>total</em> number of <strong>stable</strong> binary arrays.</p>

<p>Since the answer may 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>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">zero = 1, one = 1, limit = 2</span></p>

<p><strong>Output:</strong> <span class="example-io">2</span></p>

<p><strong>Explanation:</strong></p>

<p>The two possible stable binary arrays are <code>[1,0]</code> and <code>[0,1]</code>, as both arrays have a single 0 and a single 1, and no subarray has a length greater than 2.</p>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">zero = 1, one = 2, limit = 1</span></p>

<p><strong>Output:</strong> <span class="example-io">1</span></p>

<p><strong>Explanation:</strong></p>

<p>The only possible stable binary array is <code>[1,0,1]</code>.</p>

<p>Note that the binary arrays <code>[1,1,0]</code> and <code>[0,1,1]</code> have subarrays of length 2 with identical elements, hence, they are not stable.</p>
</div>

<p><strong class="example">Example 3:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">zero = 3, one = 3, limit = 2</span></p>

<p><strong>Output:</strong> <span class="example-io">14</span></p>

<p><strong>Explanation:</strong></p>

<p>All the possible stable binary arrays are <code>[0,0,1,0,1,1]</code>, <code>[0,0,1,1,0,1]</code>, <code>[0,1,0,0,1,1]</code>, <code>[0,1,0,1,0,1]</code>, <code>[0,1,0,1,1,0]</code>, <code>[0,1,1,0,0,1]</code>, <code>[0,1,1,0,1,0]</code>, <code>[1,0,0,1,0,1]</code>, <code>[1,0,0,1,1,0]</code>, <code>[1,0,1,0,0,1]</code>, <code>[1,0,1,0,1,0]</code>, <code>[1,0,1,1,0,0]</code>, <code>[1,1,0,0,1,0]</code>, and <code>[1,1,0,1,0,0]</code>.</p>
</div>

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

<ul>
	<li><code>1 &lt;= zero, one, limit &lt;= 200</code></li>
</ul>

class Solution:
    def numberOfStableArrays(self, zero: int, one: int, limit: int) -> int:
        MOD = 10**9 + 7
        m = zero
        n = one

        H = [[0] * (n + 1) for _ in range(m + 1)]
        T = [[0] * (n + 1) for _ in range(m + 1)]

        H_prefix = [[0] * (n + 1) for _ in range(m + 1)]
        T_prefix = [[0] * (n + 1) for _ in range(m + 1)]

        for i in range(1, m + 1):
            if i <= limit:
                H[i][0] = 1
        for j in range(1, n + 1):
            if j <= limit:
                T[0][j] = 1

        for i in range(m + 1):
            for j in range(n + 1):
                H_prefix[i][j] = (H[i][j] if j == 0 else H_prefix[i][j - 1] + H[i][j]) % MOD
                T_prefix[i][j] = (T[i][j] if i == 0 else T_prefix[i - 1][j] + T[i][j]) % MOD

        for i in range(1, m + 1):
            for j in range(1, n + 1):
                start_x = max(0, i - limit)
                H[i][j] = (T_prefix[i - 1][j] - (T_prefix[start_x - 1][j] if start_x > 0 else 0)) % MOD

                start_y = max(0, j - limit)
                T[i][j] = (H_prefix[i][j - 1] - (H_prefix[i][start_y - 1] if start_y > 0 else 0)) % MOD

                # Update prefix sums
                H_prefix[i][j] = (H_prefix[i][j - 1] + H[i][j]) % MOD if j > 0 else H[i][j] % MOD
                T_prefix[i][j] = (T_prefix[i - 1][j] + T[i][j]) % MOD if i > 0 else T[i][j] % MOD

        return (H[m][n] + T[m][n]) % MOD
22800