<p>You are given a <strong>0-indexed</strong> array of <strong>positive</strong> integers <code>nums</code>.</p>

<p>A subarray of <code>nums</code> is called <strong>incremovable</strong> if <code>nums</code> becomes <strong>strictly increasing</strong> on removing the subarray. For example, the subarray <code>[3, 4]</code> is an incremovable subarray of <code>[5, 3, 4, 6, 7]</code> because removing this subarray changes the array <code>[5, 3, 4, 6, 7]</code> to <code>[5, 6, 7]</code> which is strictly increasing.</p>

<p>Return <em>the total number of <strong>incremovable</strong> subarrays of</em> <code>nums</code>.</p>

<p><strong>Note</strong> that an empty array is considered strictly increasing.</p>

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

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

<pre>
<strong>Input:</strong> nums = [1,2,3,4]
<strong>Output:</strong> 10
<strong>Explanation:</strong> The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.
</pre>

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

<pre>
<strong>Input:</strong> nums = [6,5,7,8]
<strong>Output:</strong> 7
<strong>Explanation:</strong> The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8].
It can be shown that there are only 7 incremovable subarrays in nums.
</pre>

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

<pre>
<strong>Input:</strong> nums = [8,7,6,6]
<strong>Output:</strong> 3
<strong>Explanation:</strong> The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.
</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>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution:
    def incremovableSubarrayCount(self, nums: List[int]) -> int:
        left_arr = []
        left_arr.append((0, nums[0]))

        for i, elem in enumerate(nums[1:]): 
            if elem <= left_arr[-1][1]:
                break

            left_arr.append((i+1, elem))

        right_arr = deque()
        right_arr.append((len(nums) - 1, nums[-1]))

        for i in range(len(nums) - 2, -1, -1):
            num = nums[i]
            if num >= right_arr[0][1]:
                break 
            
            right_arr.appendleft((i, num))
        

        if left_arr[-1][0] >= right_arr[0][0]:
            return len(nums) * (len(nums) + 1) // 2

        l_index = left_arr[0][0]
        r_index = right_arr[0][0]



        total_removable = 0
        removable_arr = []
        bonus = False

        # print(left_arr, right_arr)
        # print(l_index, r_index)

        l_index = 0
        r_index = 0
        while l_index < len(left_arr) and r_index < len(right_arr):
            left_num = left_arr[l_index][1]
            while r_index < len(right_arr) and right_arr[r_index][1] <= left_num:
                r_index += 1

            if r_index >= len(right_arr):
                break 

            total_removable += len(right_arr) - r_index
            if right_arr[r_index][0] == l_index + 1:
                total_removable -= 1
            # for indices in range(r_index, len(right_arr)):
            #     if right_arr[indices][0] == l_index + 1:
            #         bonus = True
            #         # print('bonus')
            #         continue 

            #     # print(l_index, right_arr[indices][0])
            #     total_removable += 1
            removable_arr
            # total_removable += len(right_arr) - r_index + 1
            l_index += 1

        total_removable += len(right_arr) + len(left_arr) + 1

        return total_removable
        
761