diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -13,6 +13,6 @@
         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)
+        return res % (10**9 + 7)