diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -31,7 +31,7 @@
         p = min(hull[i][1], hull[i + 1][1])
         for j in range(distance + 1):
             ans += p
-            if j >= grad_min_dur:
+            if j < distance - grad_min_dur:
                 p += grad_min
             else:
                 p += grad_min + 1
