<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers and an integer <code>k</code>.</p>

<p><strong>Partition</strong> the array into two ordered <strong>groups</strong> such that each element is in exactly <strong>one</strong> group. A partition is called great if the <strong>sum</strong> of elements of each group is greater than or equal to <code>k</code>.</p>

<p>Return <em>the number of <strong>distinct</strong> great partitions</em>. Since the answer may be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>

<p>Two partitions are considered distinct if some element <code>nums[i]</code> is in different groups in the two partitions.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2,3,4], k = 4
<strong>Output:</strong> 6
<strong>Explanation:</strong> The great partitions are: ([1,2,3], [4]), ([1,3], [2,4]), ([1,4], [2,3]), ([2,3], [1,4]), ([2,4], [1,3]) and ([4], [1,2,3]).
</pre>

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

<pre>
<strong>Input:</strong> nums = [3,3,3], k = 4
<strong>Output:</strong> 0
<strong>Explanation:</strong> There are no great partitions for this array.
</pre>

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

<pre>
<strong>Input:</strong> nums = [6,6], k = 2
<strong>Output:</strong> 2
<strong>Explanation:</strong> We can either put nums[0] in the first partition or in the second partition.
The great partitions will be ([6], [6]) and ([6], [6]).
</pre>

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

<ul>
	<li><code>1 &lt;= nums.length, k &lt;= 1000</code></li>
	<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>

import math
class Solution:
    def countPartitions(self, l: List[int], k: int) -> int:
        def fun(s,ind,d):
            if ind==n:
                if s<k:
                    return 1
                return 0
            if s>=k:
                return 0
            if (s,ind) in d:
                return d[(s,ind)]
            a=0
            a=fun(s+l[ind],ind+1,d)
            a+=fun(s,ind+1,d)
            d[(s,ind)]=a
            return a
        n=len(l)
        x=2*(fun(0,0,{}))
        if x>math.pow(2,n):
            return 0
        mod=10**9+7
        return (pow(2,n,mod) - (x)%mod + mod)%mod
        # m=10**9+7
        # def fun(ind,s,dic):
        #     if ind== len(nums):
        #         if s<k:
        #             return 1
        #         return 0

        #     if (ind,s) in dic:
        #         return dic[(ind,s)]
        #     if s>=k:
        #         return 0
        #     a=0

        #     a=fun(ind+1,s+nums[ind],dic)+fun(ind+1,s,dic)
        #     dic[(ind,s)]=a
        #     return a
        # z=2*fun(0,0,{})

        # if z>(math.pow(2,len(nums))):
        #     return 0
        # tt=((pow(2,len(nums),m))-(z)%m +m)%m

        # if tt<0:
        #     return 0
        # return tt
1377