<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>.</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>
</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;= 1000</code></li>
</ul>

class Solution:
    def numberOfStableArrays(self, zero: int, one: int, l: int) -> int:
        if l==1:
            return 2 if zero==one else 1 if abs(zero-one)==1 else 0
        p=10**9+7                 
        s0=zero+one
        lst0=[None]*(s0+1)
        tmp=[1]*(zero+1)
        lst0[0]=[tmp, tmp]
        for s in range(1, s0+1):
            ls10=lst0[s-1][0]
            ls11=lst0[s-1][1]
            if s>l:
                lsl0=lst0[s-l-1][0]
                lsl1=lst0[s-l-1][1]
            tmp0=[0]*(zero+1)
            tmp1=[0]*(zero+1)
            mn=max(s-one-1, 0)
            sm=ls10[mn]+ls11[mn]
            for z in range(max(s-one, 0), min(s, zero)+1):
                if z==0: a=0; b=1 if s<=l else 0
                elif z==s: a=1 if z<=l else 0; b=0
                else:
                    a=(sm-(lsl1[z-l-1] if z>l else 0))%p
                    sm=ls10[z]+ls11[z]
                    b=(sm-(lsl0[z] if s-z>l else 0))%p
                tmp0[z]=a
                tmp1[z]=b
            lst0[s]=(tmp0, tmp1)
            if s>l:
                lst0[s-l-1]=None
            if s>s0-l:
                lst0[s-1]=None                
        return (lst0[s0][0][zero]+lst0[s0][1][zero])%p
63600