<p>You are given a binary array <code>nums</code>.</p>

<p>A subarray of an array is <strong>good</strong> if it contains <strong>exactly</strong> <strong>one</strong> element with the value <code>1</code>.</p>

<p>Return <em>an integer denoting the number of ways to split the array </em><code>nums</code><em> into <strong>good</strong> subarrays</em>. As the number may be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>

<p>A subarray is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p>

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

<pre>
<strong>Input:</strong> nums = [0,1,0,0,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> There are 3 ways to split nums into good subarrays:
- [0,1] [0,0,1]
- [0,1,0] [0,1]
- [0,1,0,0] [1]
</pre>

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

<pre>
<strong>Input:</strong> nums = [0,1,0]
<strong>Output:</strong> 1
<strong>Explanation:</strong> There is 1 way to split nums into good subarrays:
- [0,1,0]
</pre>

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

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>0 &lt;= nums[i] &lt;= 1</code></li>
</ul>

class Solution:
    def numberOfGoodSubarraySplits(self, a: List[int]) -> int:
        MOD = 10**9 + 7

        #if 1 not in a:
        #    return 0
        #print(a[a.index(1):len(a)-a[::-1].index(1)])
        #print([v or (len([*p])+1) for v,p in groupby(a[a.index(1):len(a)-a[::-1].index(1)])])
        return 1 in a and prod(v or len([*p])+1 for v,p in groupby(a[a.index(1):len(a)-a[::-1].index(1)]))%MOD or 0


        for firstOne in range(len(nums)):
            if nums[firstOne] == 1:
                break
        
        if firstOne == len(nums)-1 and nums[firstOne] != 1:
            return 0

        result = 1
        zeroCnt = 0
        for i in range(firstOne+1, len(nums)):
            if nums[i] == 0:
                zeroCnt += 1
            elif nums[i] == 1:
                result = result*(zeroCnt + 1)%MOD
                zeroCnt = 0
        
        return result
1856