package Stack;
import java.util.Stack;
public class SumOfSubarrayMins {
void getMins(int nums[]) {
//Next smaller on the left
//Next smaller on the right
int n= nums.length;
int nsl[]= new int [n];
int nsr[]= new int [n];
Stack st= new Stack<>();//Storing number, index
//Next smaller on the left
for(int i=0; i=0; i--){
while(!st.isEmpty() && nums[i] < st.peek()[0]) st.pop();
nsr[i]= st.isEmpty() ? n-i: st.peek()[1] - i;
st.push(new int [] {nums[i], i});
}
long mod= (long)1e9 + 7;
long res=0;
for(int i=0; i