diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -23,7 +23,7 @@
     for i in range(m + 1):
         if q[i] < n + 1:
             nq[i] = min(nq[i], q[i])
-            if 0 <= i + dd * pp <= m and dd > 0:
+            if 0 <= i + dd * pp <= m and dd != 0:
                 nq[i + dd * pp] = min(nq[i + dd * pp], q[i] + pp)
     q = nq
 for qq in q:
