<p>You wrote down many <strong>positive</strong> integers in a string called <code>num</code>. However, you realized that you forgot to add commas to seperate the different numbers. You remember that the list of integers was <strong>non-decreasing</strong> and that <strong>no</strong> integer had leading zeros.</p>

<p>Return <em>the <strong>number of possible lists of integers</strong> that you could have written down to get the string </em><code>num</code>. Since the answer may be 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>

<pre>
<strong>Input:</strong> num = &quot;327&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> You could have written down the numbers:
3, 27
327
</pre>

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

<pre>
<strong>Input:</strong> num = &quot;094&quot;
<strong>Output:</strong> 0
<strong>Explanation:</strong> No numbers can have leading zeros and all numbers must be positive.
</pre>

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

<pre>
<strong>Input:</strong> num = &quot;0&quot;
<strong>Output:</strong> 0
<strong>Explanation:</strong> No numbers can have leading zeros and all numbers must be positive.
</pre>

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

<ul>
	<li><code>1 &lt;= num.length &lt;= 3500</code></li>
	<li><code>num</code> consists of digits <code>&#39;0&#39;</code> through <code>&#39;9&#39;</code>.</li>
</ul>

from collections import defaultdict

class Solution:
    def numberOfCombinations(self, num: str) -> int:
        MOD: int = int(1e9 + 7)
        combinations_end_len = [[0] * (len(num) + 2) for _ in range(len(num) + 2)]
        combinations_start_end = [[0] * (len(num) + 2) for _ in range(len(num) + 2)]
        for end_idx in range(len(num)):
            for start_idx in range(end_idx, -1, -1):
                curr_len: int = end_idx - start_idx + 1
                curr_combinations: int = 0
                if num[start_idx] != '0':
                    curr_combinations += combinations_end_len[start_idx - 1][curr_len - 1] if start_idx > 0 else 0
                    curr_combinations += start_idx == 0
                if start_idx - curr_len >= 0 and num[start_idx] != '0' and num[start_idx - curr_len] != '0' and num[start_idx - curr_len: start_idx] <= num[start_idx: end_idx + 1]:
                    curr_combinations += combinations_start_end[start_idx - curr_len][start_idx - 1]                
                combinations_start_end[start_idx][end_idx] = curr_combinations % MOD
                combinations_end_len[end_idx][curr_len] = (combinations_end_len[end_idx][curr_len - 1] + combinations_start_end[end_idx - curr_len + 1][end_idx]) % MOD
            
            for curr_len in range(end_idx + 2, len(num) + 1):
                combinations_end_len[end_idx][curr_len] = combinations_end_len[end_idx][curr_len - 1]
        
        return combinations_end_len[len(num) - 1][len(num)]

591400