diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -5,14 +5,16 @@
 import bisect
 import itertools
 import functools
+
+
 class Solution:
     def sumSubarrayMins(self, arr: List[int]) -> int:
         stack = []
         res = 0
-        
+        arr = [float("-inf")] + arr + [float("-inf")]
         for i, num in enumerate(arr):
             while stack and arr[stack[-1]] > num:
                 cur = stack.pop()
-                res += arr[cur] * (cur - i) * (cur - stack[-1]
+                res += arr[cur] * (i - cur) * (cur - stack[-1])
             stack.append(i)
         return res % (10**9 + 7)
