<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>

class Solution:
    def numberOfCombinations(self, num: str) -> int:
        num = list(num)
        n = len(num)
        cmp = [[0] * (n + 1) for _ in range(n+1)]
        for k in range(1, n // 2 + 1):
            for j in range(n-1, k-1, -1):
                i = j - k
                if num[i] < num[j]:
                    cmp[i][j] = 1
                elif num[i] > num[j]:
                    cmp[i][j] = -1
                else:
                    r = cmp[i+1][j+1]
                    if r == 0 or abs(r) + 1 > j - i:
                        cmp[i][j] = 0
                    elif r < 0:
                        cmp[i][j] = r - 1
                    else:
                        cmp[i][j] = r + 1

        prefix_sums = [[0] * (n+2) for _ in range(n+2)]
        for j in range(n-1, -1, -1):
            for i in range(j):
                v = 0
                if num[i] != "0" and num[j] != "0":
                    if n - j > j - i or (n - j == j - i and cmp[i][j] >= 0):
                        lo, hi = 2 * j - i + (cmp[i][j] < 0), (n + j) // 2 + 1
                        v = 1 + prefix_sums[j][lo] - prefix_sums[j][hi+1]
                prefix_sums[i][j] += (prefix_sums[i][j+1] + v) % 1000000007
        return (prefix_sums[0][1] + (num[0] != "0")) % 1000000007
2484