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_1 = len ( var_0 )
      var_2 = [ - 1 ] * var_1
      var_3 = [ var_1 ] * var_1
      var_4 = [ ]
      for var_5 , var_6 in enumerate ( var_0 ) :
          while var_4 and var_0 [ var_4 [ - 1 ] ] >= var_6 :
              var_4.pop ( )
          if var_4 :
              var_2 [ var_5 ] = var_4 [ - 1 ]
          var_4.append ( var_5 )
      var_4 = [ ]
      for var_5 in range ( var_1 - 1 , - 1 , - 1 ) :
          while var_4 and var_0 [ var_4 [ - 1 ] ] > var_0 [ var_5 ] :
              var_4.pop ( )
          if var_4 :
              var_3 [ var_5 ] = var_4 [ - 1 ]
          var_4.append ( var_5 )
      var_7 = int ( 1e9 ) + 7
      return sum ( ( var_5 - var_2 [ var_5 ] ) * ( var_3 [ var_5 ] - var_5 ) * var_6 for var_5 , var_6 in enumerate ( var_0 ) ) % var_7
  