diff --git a/buggy.py b/buggy.py
--- a/buggy.py
+++ b/buggy.py
@@ -6,6 +6,8 @@
     nq = [0] * (k + 1)
     for j in range(k):
         nq[j + 1] += q[j]
+        if j + m + 1 <= k:
+            nq[j + m + 1] -= q[j]
     for j in range(k):
         nq[j + 1] += nq[j]
         nq[j + 1] %= M
