diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -5,7 +5,7 @@
 ans = 0
 q = []
 for v in p:
-    if q and p[0] < v:
+    if q and q[0] < v:
         ans += v - heappop(q)
         heappush(q, v)
     heappush(q, v)
