Number Of Valid Subarrays

hard
Given an array nums of integers, return the number of non-empty continuous subarrays that satisfy the following condition:
The leftmost element of the subarray is not larger than other elements in the subarray.

Input Format

Input is managed for you

Output Format

Output is managed for you

Constraints

1. 1 <= nums.length <= 50000
2. 0 <= nums[i] <= 100000

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
5
1
4
2
5
3
Output
11
Previous
Basic Calculator
Next
Basic Calculator Ii

Related Questions