comefrom: <doocs>0907.Sum of Subarray Minimums_1.py
code: def sumSubarrayMins( arr: List[int]) -> int:
      n = len(arr)
      left = [-1] * n
      right = [n] * n
      stk = []
      for i, v in enumerate(arr):
          while stk and arr[stk[-1]] >= v:
              stk.pop()
          if stk:
              left[i] = stk[-1]
          stk.append(i)
      stk = []
      for i in range(n - 1, -1, -1):
          while stk and arr[stk[-1]] > arr[i]:
              stk.pop()
          if stk:
              right[i] = stk[-1]
          stk.append(i)
      mod = int(1e9) + 7
      return sum((i - left[i]) * (right[i] - i) * v for i, v in enumerate(arr)) % mod
masked: def sample_funcname ( var_0 : List [ int ] ) -> int :
      var_4 = len ( var_0 )
      var_6 = [ - 1 ] * var_4
      var_7 = [ var_4 ] * var_4
      var_8 = [ ]
      for var_10 , var_11 in enumerate ( var_0 ) :
          while var_8 and var_0 [ var_8 [ - 1 ] ] >= var_11 :
              var_8.pop ( )
          if var_8 :
              var_6 [ var_10 ] = var_8 [ - 1 ]
          var_8.append ( var_10 )
      var_8 = [ ]
      for var_10 in range ( var_4 - 1 , - 1 , - 1 ) :
          while var_8 and var_0 [ var_8 [ - 1 ] ] > var_0 [ var_10 ] :
              var_8.pop ( )
          if var_8 :
              var_7 [ var_10 ] = var_8 [ - 1 ]
          var_8.append ( var_10 )
      var_17 = int ( 1e9 ) + 7
      return sum ( ( var_10 - var_6 [ var_10 ] ) * ( var_7 [ var_10 ] - var_10 ) * var_11 for var_10 , var_11 in enumerate ( var_0 ) ) % var_17
  