Approach hintTry it first, then revealHide
Count the subarrays in which each element is the minimum. With previous-smaller and next-smaller-or-equal boundaries from monotonic stacks, element i contributes a[i] * left * right; break ties on one side only.