1var sumSubarrayMins = function (arr) {2M = 10 ** 9 + 7;3stack = [-1];4res = 0;5arr.push(0);67for (let i2 = 0; i2 < arr.length; i2++) {8while (arr[i2] < arr[stack[stack.length - 1]]) {9i = stack.pop();10i1 = stack[stack.length - 1];11Left = i - i1;12Right = i2 - i;13res += Left * Right * arr[i];14}15stack.push(i2);16}1718return res % M;19};